Skip to content

About

A full-stack personal finance tracker built with React, FastAPI and Docker.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

💰 Expense Pro

A full-stack personal expense management application built with React and FastAPI, featuring JWT authentication, secure password hashing, user-isolated expense management, income tracking, and dashboard visualization.

Expense Pro was built to explore how a complete web application can be structured across a modern frontend, REST API, authentication layer, database, and containerized development environment.

Rather than treating the project as a collection of frontend pages and database operations, the system is structured around a clear separation between client, API, authentication, business logic, and persistence.


📌 Project Overview

Managing personal expenses involves more than simply storing numbers.

A useful expense management system needs to ensure that:

  • Users can securely authenticate
  • Users can only access their own financial records
  • Expenses can be created, updated, and deleted
  • Income can be tracked alongside expenses
  • Data can be categorized and visualized
  • The frontend and backend remain separated
  • The application can be reproduced consistently across environments

Expense Pro addresses these requirements through a React frontend communicating with a FastAPI backend over HTTP.

The backend handles authentication, validation, business logic, and database operations while the frontend focuses on user interaction and visualization.


🏗️ Architecture

                         Expense Pro
                              │
               ┌──────────────┴──────────────┐
               │                             │
               ▼                             ▼
      ┌─────────────────┐          ┌─────────────────┐
      │ React + Vite    │          │ FastAPI Backend │
      │                 │  HTTP    │                 │
      │ Dashboard       │─────────▶│ REST API        │
      │ Authentication  │  Axios   │ JWT Auth        │
      │ Expense UI      │          │ Validation      │
      │ Charts          │          │ Business Logic  │
      └─────────────────┘          └────────┬────────┘
                                            │
                                      SQLAlchemy ORM
                                            │
                                            ▼
                                    ┌─────────────────┐
                                    │     SQLite      │
                                    │                 │
                                    │ Users           │
                                    │ Expenses        │
                                    │ Categories      │
                                    └─────────────────┘

The application is also containerized using Docker Compose:

┌────────────────────────────────────────────────────┐
│                   Docker Compose                   │
│                                                    │
│   ┌──────────────┐    ┌────────────────┐           │
│   │ Caddy edge   │───▶│ nginx + static │           │
│   │ HTTPS :443   │    │ React build    │           │
│   └──────┬───────┘    └────────────────┘           │
│          │                                          │
│          └───────────▶ FastAPI :8000               │
│                              │                     │
│                           SQLite                   │
└────────────────────────────────────────────────────┘

✨ Features

🔐 Authentication

Expense Pro provides account-based authentication using:

  • User registration
  • Email validation
  • Password hashing with bcrypt
  • JWT-based authentication
  • Protected API endpoints
  • Current-user resolution from JWT identity

Authentication flow:

User
 │
 ▼
Login
 │
 ▼
FastAPI
 │
 ├── Find user
 ├── Verify password
 └── Generate JWT
          │
          ▼
       Frontend
          │
          ▼
Protected API requests
          │
          ▼
JWT verification
          │
          ▼
Authenticated user

💸 Expense Management

Authenticated users can manage their own expenses.

Create

Record:

  • Amount
  • Description
  • Category

Read

Retrieve expenses belonging to the authenticated user.

Update

Modify an existing expense.

Delete

Remove an expense belonging to the authenticated user.

The backend verifies ownership using the authenticated user's identity before modifying or deleting records.

JWT
 ↓
Current User
 ↓
User ID
 ↓
Expense.user_id
 ↓
Authorized operation

This prevents one authenticated user from directly accessing another user's expense records through the API.


💵 Income Tracking

Users can:

  • View their stored income
  • Update their income

Income is associated with the authenticated user and stored in the database.

This provides the foundation for comparing income and spending within the dashboard.


📊 Dashboard & Visualization

The frontend includes dashboard components for presenting financial information visually.

The application uses:

  • Chart.js
  • react-chartjs-2

This allows expense data to be transformed from raw database records into visual summaries.


🗃️ Data Model

The current database contains models for users, expenses, and categories.

User

User
├── id
├── name
├── email
├── password_hash
├── income
└── created_at

Expense

Expense
├── id
├── amount
├── description
├── category
├── date
└── user_id

Category

Category
├── id
├── name
└── user_id

SQLAlchemy is used as the ORM between the FastAPI application and the SQLite database.


🛡️ Security

Security is handled primarily at the backend layer.

Password hashing

Passwords are never stored as plaintext.

They are hashed using bcrypt before being stored in the database.

JWT authentication

Authenticated requests use JSON Web Tokens.

The backend validates the token and resolves the associated user before allowing access to protected endpoints.

User-level data isolation

Expense queries are scoped to the authenticated user's ID.

For example:

GET /api/expenses
        │
        ▼
JWT verification
        │
        ▼
Current user identified
        │
        ▼
Query expenses for that user

Environment-based secrets

Sensitive configuration such as the JWT signing secret is provided through environment variables rather than being committed to source control.

The current configuration is intended for development and learning. Production deployment would require additional hardening such as restricted CORS origins, HTTPS, stronger secret management, rate limiting, and more robust token lifecycle management.


🧰 Technology Stack

Backend

  • Python
  • FastAPI
  • Uvicorn
  • SQLAlchemy
  • Pydantic
  • Python-JOSE
  • Passlib
  • bcrypt

Frontend

  • React
  • Vite
  • Axios
  • React Router
  • Chart.js
  • react-chartjs-2

Database

  • SQLite

Infrastructure

  • Docker
  • Docker Compose

Development

  • Git
  • GitHub

📁 Project Structure

ExpensePro/
│
├── backend/
│   ├── app/
│   │   ├── auth.py
│   │   ├── database.py
│   │   ├── main.py
│   │   │
│   │   ├── models/
│   │   │   ├── category.py
│   │   │   ├── expense.py
│   │   │   └── user.py
│   │   │
│   │   └── schemas/
│   │       ├── expense.py
│   │       └── user.py
│   │
│   ├── Dockerfile
│   └── requirements.txt
│
├── frontend/
│   ├── public/
│   ├── src/
│   │   ├── components/
│   │   │   ├── Navbar.jsx
│   │   │   └── PieChart.jsx
│   │   │
│   │   ├── pages/
│   │   │   ├── Dashboard.jsx
│   │   │   └── Login.jsx
│   │   │
│   │   ├── api.js
│   │   ├── App.jsx
│   │   └── main.jsx
│   │
│   ├── Dockerfile
│   ├── package.json
│   └── vite.config.js
│
├── docs/
│   └── api.md
│
├── docker-compose.yml
├── .env.example
├── .gitignore
└── README.md

🚀 Getting Started

Prerequisites

You can run Expense Pro either locally or through Docker.

Option A — Docker

Install:

  • Docker
  • Docker Compose

Option B — Local Development

Install:

  • Python 3.11+
  • Node.js 20+
  • npm

🐳 Running with Docker

Clone the repository:

git clone https://github.com/shubham-kain07/ExpensePro.git
cd ExpensePro

Create a .env file from the example:

cp .env.example .env

Set a secure value for:

SECRET_KEY=replace_with_a_long_random_secret

Start the application:

docker compose up --build -d

The edge proxy serves the production static build and the API through Caddy:

Application → https://localhost
Health      → https://localhost/health

The backend and frontend containers are internal-only; they are not published directly.

Caddy uses its internal CA for local HTTPS, so the browser will warn about the self-signed certificate. For a real deployment, point Caddy at your domain and replace tls internal with a trusted certificate configuration.

To stop the application:

docker compose down

This preserves the persistent database volume and the host backups/ directory. Do not use docker compose down -v unless you intend to delete the database.

Create an on-demand backup:

docker compose exec backend python scripts/backup_db.py

Backups are written to ./backups/ and pruned to the last 7 by default. For production, copy backups to storage outside the Docker host.


🐍 Local Backend Development

Create a virtual environment:

python -m venv venv

Activate it on Linux/macOS:

source venv/bin/activate

For Fish shell:

source venv/bin/activate.fish

Install dependencies:

pip install -r backend/requirements.txt

Create .env:

SECRET_KEY=replace_with_a_long_random_secret

Start FastAPI:

uvicorn backend.app.main:app --reload

Depending on the local working directory and Python import configuration, the application may instead be started from inside backend/:

cd backend
uvicorn app.main:app --reload

⚛️ Local Frontend Development

Open another terminal:

cd frontend
npm install
npm run dev

The frontend will be available at:

http://localhost:5173

For local Vite development against the backend on port 8000, explicitly allow the Vite origins in .env:

CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173

The Docker production path is same-origin and leaves CORS_ORIGINS empty.


🔌 API

The backend exposes REST endpoints for authentication, users, expenses, and income.

Authentication

POST /api/auth/signup
POST /api/auth/login

User

GET /api/me
GET /api/user/income
PUT /api/user/income

Expenses

GET    /api/expenses
POST   /api/expenses
PUT    /api/expenses/{expense_id}
DELETE /api/expenses/{expense_id}

Detailed API information is available in:

docs/api.md

FastAPI also provides interactive API documentation when the backend is running:

http://localhost:8000/docs

🧪 Development Notes

Expense Pro was built as a practical exploration of full-stack application architecture.

The project focuses on keeping responsibilities separated:

React
  ↓
HTTP / API
  ↓
FastAPI
  ↓
Authentication
  ↓
Business Logic
  ↓
SQLAlchemy
  ↓
SQLite

This separation makes it possible to change individual layers without requiring the entire application to be rewritten.

The Docker setup further allows the frontend and backend environments to be reproduced consistently.


🔮 Future Improvements

Potential future improvements include:

  • PostgreSQL support
  • Refresh-token authentication
  • Improved token lifecycle management
  • Server-side pagination
  • Advanced expense filtering
  • Dedicated category management
  • Recurring expenses
  • Monthly financial reports
  • Export to CSV/PDF
  • Improved dashboard analytics
  • Automated backend tests
  • Production deployment configuration
  • More restrictive production CORS configuration

These are planned improvements and are not represented as currently implemented functionality.


📚 What This Project Demonstrates

Expense Pro was built to explore practical software engineering concepts including:

  • REST API design
  • Authentication and authorization
  • JWT-based security
  • Password hashing
  • Database modelling
  • SQLAlchemy ORM
  • Pydantic validation
  • User-level data isolation
  • React application architecture
  • API integration
  • Data visualization
  • Docker containerization
  • Docker Compose
  • Technical documentation

The project is intentionally structured as a complete application rather than a collection of isolated frontend and backend exercises.


👨‍💻 Author

Shubham Kain

Computer Science & Technology

GitHub: @shubham-kain07


📄 License

This project is currently developed as a personal and academic software engineering project.

License information will be added when the project reaches its first public release.

About

A full-stack personal finance tracker built with React, FastAPI and Docker.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages