Skip to content

khamar21/Expense-Tracker-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Expense Tracker Backend

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.


πŸ“Œ Overview

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.


✨ Features

  • 🧾 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

πŸ› οΈ Tech Stack

  • FastAPI – API framework
  • Uvicorn – ASGI server
  • SQLAlchemy – ORM for database
  • SQLite – Lightweight database
  • Pydantic – Data validation

πŸ“ Project Structure

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

βš™οΈ Requirements

  • Python 3.10+
  • pip

πŸš€ Quick Start

1️⃣ Create Virtual Environment

python -m venv venv
venv\Scripts\activate

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Run Server

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

4️⃣ Access API


πŸ“‘ API Endpoints

πŸ”Ή Health Check

GET /

{
  "message": "Expense Tracker API running"
}

πŸ”Ή Create Expense

POST /expenses/

{
  "title": "Lunch",
  "amount": 150,
  "category": "Food"
}

πŸ”Ή Get All Expenses

GET /expenses/


πŸ”— Flutter Integration

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

Example

static const String baseUrl = "http://192.168.31.37:8000";

πŸ—„οΈ Database

  • Uses SQLite
  • Database file is auto-created
  • Table: expenses

πŸ”„ Example Workflow

Flutter App β†’ POST /expenses/ β†’ Backend β†’ Save to DB
Flutter App β†’ GET /expenses/ β†’ Backend β†’ Return data β†’ UI update

πŸ§ͺ Testing API

Use Swagger UI:

πŸ‘‰ http://127.0.0.1:8000/docs

  • Try POST request
  • Then GET to verify data

⚠️ Troubleshooting

❌ Cannot connect from phone

βœ” Ensure same Wi-Fi βœ” Use correct IP (192.168.x.x) βœ” Run server with 0.0.0.0


❌ Connection refused

βœ” Backend not running βœ” Wrong port or IP


❌ Requests blocked

βœ” Allow Python in Windows Firewall


πŸ“Œ Notes

  • Database is automatically initialized on startup
  • Simple structure makes it easy to scale
  • Ready for future upgrades (auth, cloud deployment, etc.)

πŸš€ Future Improvements

  • πŸ” User Authentication (JWT)
  • ☁️ Cloud Deployment (Render / Railway)
  • πŸ”„ Real-time updates (WebSockets)
  • πŸ“Š Advanced analytics APIs
  • πŸ“ Category-wise filtering

πŸ‘¨β€πŸ’» Author

Built with ❀️ for learning and real-world application development.


⭐ Support

If you like this project:

⭐ Star this repo 🍴 Fork it πŸ“’ Share it


πŸ“¬ Contact

Feel free to connect or ask questions!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors