Skip to content

Repository files navigation

Smart Expense Tracker API

Overview

The Smart Expense Tracker API is a RESTful web service built with Python and FastAPI that helps users manage their personal expenses. It allows users to add, view, filter, calculate, and delete expenses. Data is stored in a local JSON file, making the application lightweight and easy to run without a database.

Features

  • Add a new expense
  • View all expenses
  • Filter expenses by category
  • Calculate total expenses
  • Calculate total expenses by category
  • Delete an expense
  • Interactive API documentation using Swagger UI

Tech Stack

  • Python 3.10+
  • FastAPI
  • Uvicorn
  • Pydantic
  • Pytest
  • JSON (Local File Storage)

Project Structure

expense-tracker-api/
│
├── README.md
├── AI_NOTES.md
├── requirements.txt
├── expenses.json
│
├── src/
│   ├── __init__.py
│   ├── main.py
│   ├── models.py
│   └── storage.py
│
└── tests/
    ├── __init__.py
    └── test_api.py

Installation

1. Clone the Repository

git clone https://github.com/<your-username>/expense-tracker-api.git

2. Navigate to the Project

cd expense-tracker-api

3. Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

Running the Server

Start the FastAPI development server:

uvicorn src.main:app --reload

The API will be available at:

http://127.0.0.1:8000

Interactive API Documentation

Swagger UI:

http://127.0.0.1:8000/docs

ReDoc Documentation:

http://127.0.0.1:8000/redoc

Running the Tests

Run all tests using:

pytest

API Endpoints

Method Endpoint Description
GET / Welcome endpoint
POST /expenses Add a new expense
GET /expenses View all expenses
GET /expenses?category=Food Filter expenses by category
GET /expenses/total Calculate total expenses
GET /expenses/total?category=Food Calculate total for a category
DELETE /expenses/{expense_id} Delete an expense

Example Request

Add Expense

POST /expenses

Request Body

{
    "title": "Lunch",
    "amount": 250,
    "category": "Food",
    "date": "2026-08-02"
}

Response

{
    "message": "Expense added successfully",
    "expense": {
        "id": 1,
        "title": "Lunch",
        "amount": 250,
        "category": "Food",
        "date": "2026-08-02"
    }
}

Data Storage

The application stores all expense records in a local file named expenses.json. No external database is required.

Error Handling

The API validates user input and returns appropriate HTTP status codes and error messages. For example:

  • Invalid input data returns a validation error.
  • Attempting to delete a non-existent expense returns 404 Not Found.

Future Improvements

  • User authentication
  • Database integration (SQLite or PostgreSQL)
  • Update expense endpoint
  • Pagination for large datasets
  • Search by title or date
  • Monthly expense summary

Author

Vishal Vishwas Desai

GitHub: https://github.com/Vishal-desai

LinkedIn: https://linkedin.com/in/vishal-desai-84b26a260

About

Smart Expense Tracker REST API built with FastAPI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages