A lightweight and scalable FastAPI backend for the Expense Tracker application. This backend provides RESTful APIs to manage expenses, powered by SQLite + SQLAlchemy, and is designed to seamlessly integrate with a Flutter frontend.
This backend is built with simplicity and performance in mind. It enables users to store, retrieve, and manage expenses efficiently while maintaining a clean and modular architecture.
- 🧾 Create and store expenses
- 📊 Retrieve all expenses via API
- ⚡ Fast and async-ready with FastAPI
- 🗄️ SQLite database (auto-created)
- 🧩 Clean modular structure (routes, models, schemas)
- 📱 Supports Android Emulator & real devices
- 🔍 Interactive API testing with Swagger UI
- FastAPI – API framework
- Uvicorn – ASGI server
- SQLAlchemy – ORM for database
- SQLite – Lightweight database
- Pydantic – Data validation
expense_backend/
├── main.py # App entry point
├── database.py # DB connection setup
├── models.py # SQLAlchemy models
├── schemas.py # Pydantic schemas
├── crud.py # DB operations
├── requirements.txt # Dependencies
└── routes/
└── expense_routes.py # API routes- Python 3.10+
- pip
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtuvicorn main:app --host 0.0.0.0 --port 8000 --reload- 🌐 Base URL: http://127.0.0.1:8000
- 📘 Swagger Docs: http://127.0.0.1:8000/docs
- 📕 ReDoc: http://127.0.0.1:8000/redoc
GET /
{
"message": "Expense Tracker API running"
}POST /expenses/
{
"title": "Lunch",
"amount": 150,
"category": "Food"
}GET /expenses/
Use the correct base URL depending on your device:
| Platform | Base URL |
|---|---|
| Android Emulator | http://10.0.2.2:8000 |
| iOS Simulator | http://127.0.0.1:8000 |
| Real Device (Wi-Fi) | http://YOUR_IP:8000 |
static const String baseUrl = "http://192.168.31.37:8000";- Uses SQLite
- Database file is auto-created
- Table:
expenses
Flutter App → POST /expenses/ → Backend → Save to DB
Flutter App → GET /expenses/ → Backend → Return data → UI update
Use Swagger UI:
- Try POST request
- Then GET to verify data
✔ Ensure same Wi-Fi
✔ Use correct IP (192.168.x.x)
✔ Run server with 0.0.0.0
✔ Backend not running ✔ Wrong port or IP
✔ Allow Python in Windows Firewall
- Database is automatically initialized on startup
- Simple structure makes it easy to scale
- Ready for future upgrades (auth, cloud deployment, etc.)
- 🔐 User Authentication (JWT)
- ☁️ Cloud Deployment (Render / Railway)
- 🔄 Real-time updates (WebSockets)
- 📊 Advanced analytics APIs
- 📁 Category-wise filtering
Built with ❤️ for learning and real-world application development.
If you like this project:
⭐ Star this repo 🍴 Fork it 📢 Share it
Feel free to connect or ask questions!