A full-stack web application for tracking daily expenses and visualizing spending analytics over time.
- Add & Update Expenses: Easily log your daily expenses by categorizing them and adding custom notes.
- Expense Analytics: View a breakdown of your spending habits within a specific date range.
- Intuitive UI: A clean, interactive frontend built with Streamlit.
- Robust Backend: A fast, reliable REST API built with FastAPI.
- Relational Database: Persistent data storage using MySQL.
- Frontend: Streamlit
- Backend: FastAPI, Python
- Database: MySQL
- Data Processing: Pandas
- Testing: Pytest, Postman (for API testing)
Project-Expense_tracking_system/
│
├── .env.example # Template for environment variables (DB credentials)
├── schema.sql # Database schema definition
├── backend/ # FastAPI server and database helper functions
│ ├── server.py # Main FastAPI application with API endpoints
│ ├── db_helper.py # Database connection and query execution
│ ├── config.py # Configuration settings
│ └── logging_setup.py # Logger configuration
│
├── frontend/ # Streamlit application UI
│ ├── app.py # Main entry point for the frontend app
│ ├── add_update_ui.py # UI component for adding/updating expenses
│ ├── analytics_by_category.py # UI component for category analytics
│ └── analytics_by_months.py # UI component for monthly analytics
│
├── tests/ # Pytest unit tests for backend and database operations
│
└── requirements # Python dependencies
- Python 3.8+
- MySQL Server
Install the required Python dependencies:
pip install -r requirementsEnsure your MySQL server is running. Create a .env file in the root directory using .env.example as a template and configure your local MySQL credentials (username, password, database name). You can initialize the database using the provided schema.sql script.
Start the Backend Server:
Navigate to the backend directory and run the FastAPI server using Uvicorn:
cd backend
uvicorn server:app --reloadThe backend API will be available at http://localhost:8000 (You can view the Swagger UI docs at http://localhost:8000/docs).
Start the Frontend App:
Open a new terminal, navigate to the frontend directory, and run the Streamlit app:
cd frontend
streamlit run app.pyThe Streamlit interface will open in your browser, typically at http://localhost:8501.
The FastAPI backend provides the following RESTful endpoints:
GET /expenses/{expense_date}: Fetch all expenses for a specific date.POST /expenses/{expense_date}: Add, update, or overwrite expenses for a specific date.POST /analytics/category: Get an aggregated summary and percentage breakdown of expenses across categories for a specified date range.POST /analytics/months: Get an aggregated monthly summary of expenses.
To run the unit tests, use pytest from the root directory:
pytest