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:
π http://127.0.0.1:8000/docs
- 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!