A simple Expense Tracker application built with FastAPI for the backend and HTML, CSS, and JavaScript for the frontend.
This project demonstrates how a frontend communicates with a backend using REST APIs.
- Add an expense
- View all expenses
- Delete an expense
- FastAPI REST API
- Data saved to SQLite database (data persists after restart)
- HTML
- CSS
- JavaScript
- FastAPI
- SQLModel + SQLite
expense-tracker/
│
├── backend/
│ ├── main.py ← API routes
│ ├── models.py ← Expense table model
│ ├── database.py ← SQLite connection
│ ├── expenses.db ← SQLite database file (auto-created)
│ ├── requirements.txt
│
│
├── frontend/
│ ├── index.html
│ ├── script.js
│ ├── style.css
│ └── ...
│
└── README.md
git clone https://github.com/shresthaAlex/software_fellowship_day4_database.gitcd backendpython -m venv venvpython3 -m venv venvvenv\Scripts\activatesource venv/bin/activateAfter activation, your terminal should display something similar to:
(venv)
pip install -r requirements.txtNote:
requirements.txtincludesfastapi[standard], so you do not need to install Uvicorn separately.
Start the FastAPI development server with:
fastapi dev main.pyThe backend will start at:
http://127.0.0.1:8000
Interactive API documentation is available at:
http://127.0.0.1:8000/docs
Open the frontend folder in VS Code.
Right-click on index.html and select:
Open with Live Server
The frontend will communicate with the FastAPI backend running on port 8000.
GET /expensesReturns all stored expenses.
POST /expensesExample Request Body
{
"category": "Food",
"description": "Pizza",
"amount": 20
}DELETE /expenses/{expense_id}Deletes an expense using its unique ID.
categoryis required.descriptionis optional.amountmust be greater than 0.
- Data is stored in SQLite (
expenses.db). - Data persists even after restarting the server — try it!
- Delete
expenses.dbto reset all data. - The frontend stays the same — only the backend changed.
| Section | Day 3 (Before) | Day 4 (After) |
|---|---|---|
| Features | In-memory storage (data resets after restart) | SQLite database (data persists after restart) |
| Tech Stack | Pydantic | SQLModel + SQLite |
| Project Structure | main.py |
main.py, models.py, database.py, expenses.db |
| Storage | Python list | SQLite database |
| Data Persistence | ❌ Lost on restart | ✅ Saved permanently |
| Notes | "Data stored in memory, resets on restart." | "Data stored in SQLite, persists after restart." |
| File | Purpose |
|---|---|
database.py 🆕 |
Connects to SQLite, creates the database, and provides database sessions |
models.py 🆕 |
Defines the Expense table using SQLModel |
main.py 🔄 |
Uses the database for CRUD operations instead of an in-memory list |
expenses.db 🆕 |
SQLite database file that stores all expense records |
This project demonstrates:
- FastAPI
- REST APIs
- HTTP Methods (GET, POST, DELETE)
- Pydantic Validation
- JSON Requests & Responses
- Fetch API
- Frontend ↔ Backend Communication
- SQLModel + SQLite