This project is a simple expense tracker application built using Flask for the backend, GraphQL for API querying, and React for the frontend. The backend uses an SQLite database to store and manage expense records, with Strawberry GraphQL providing a flexible API layer.
- Backend: Flask with Strawberry GraphQL for managing CRUD operations on expenses.
- Database: SQLite, managed with SQLAlchemy ORM.
- Frontend: React to provide a user interface for interacting with expenses.
- Backend: Manages data operations and exposes GraphQL endpoints.
- Frontend: Displays data to users and allows them to interact with expense records.
- Python 3.7+
- Node.js (for the React frontend)
- Flask and dependencies
-
Clone the repository:
git clone <repository-url>cd <repository-directory> -
Create a virtual environment:
python3 -m venv .venvsource .venv/bin/activate -
Install dependencies:
pip install flask strawberry-graphql sqlalchemy -
Initialize the SQLite database: This will create an SQLite database file (db.db) and set up the expenses table.
-
Start the Flask server:
python app.pyorflask run -
Access the GraphQL Playground: Navigate to http://127.0.0.1:5000/graphql/expenses in your browser to test GraphQL queries and mutations.
• ExpenseType: Represents an expense with fields:
• id: ID of the expense
• amount: Amount spent
• description: Description of the expense
• date: Date of the expense (as a string)
• category: Category of the expense
• get_expense(id: Int): Fetches a single expense by ID.
• list_expenses(limit: Int, offset: Int): Lists expenses with optional pagination.
• create_expense(amount: Float, description: String, date: String, category: String): Creates a new expense.
• update_expense(id: Int, amount: Float, description: String, date: String, category: String): Updates an existing expense.
• delete_expense(id: Int): Deletes an expense by ID.
mutation {
createExpense(amount: 50.0, description: "Grocery shopping", date: "2024-11-01", category: "Food") {
id
amount
description
date
category
}
}
This search query filters expenses by description and category, returning the first 5 results.
query {
searchExpenses(description: "lunch", limit: 5) {
id
amount
description
date
category
}
}
query {
searchExpenses(category: "Food", limit: 5) {
id
amount
description
date
category
}
}
query {
listExpenses(limit: 5, offset: 0) {
id
amount
description
date
category
}
}
mutation {
updateExpense(id: 1, amount: 75.0) {
id
amount
description
date
category
}
}
mutation {
deleteExpense(id: 1)
}
In progress
This project is licensed under the MIT License - see the LICENSE file for details.