Skip to content

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

Packages

Contributors

Languages