git clone https://github.com/varshitverma/api-exp-tracker.git
cd backendBefore proceeding with setup, you need to generate two API keys:
- Go to Supabase
- Create a new project or use existing one
- Go to Settings → API
- Copy these values:
- Project URL - This is your
SUPABASE_URL - Service Role Secret - This is your
SUPABASE_KEY
- Project URL - This is your
- Go to ExchangeRate-API
- Sign up for a free account
- Copy your API Key
- This will be part of your
EXCHANGE_RATE_API_URL
Create a .env file in the backend directory and add your API keys:
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_secret_key
EXCHANGE_RATE_API_URL=https://v6.exchangerate-api.com/v6/YOUR_EXCHANGERATE_API_KEY/latestpip install -r requirements.txtnpx supabase login
# Please login with your Supabase accountnpx supabase link
# Select the project you created on Supabase for this appnpx supabase migration new create_expenses_tablenpx supabase db push
# This will push the migration to your Supabase project and create the expenses table in your databasenpx supabase migration upnpx supabase db reset --linked
# This will reset your database and run all migrations again
# Use this if you want to start fresh with the database in case of any issues
# Then run all commands above again to set up the databasepython -m uvicorn main:app --reloadServer runs on: http://127.0.0.1:8000
Once the server is running, you can view interactive API documentation:
-
Swagger UI (Interactive): http://127.0.0.1:8000/api/docs
- Best for testing endpoints directly
- Try out requests and see responses
-
ReDoc (Beautiful Docs): http://127.0.0.1:8000/api/redoc
- Clean, organized documentation
- Great for reading API specifications
-
OpenAPI Schema (JSON): http://127.0.0.1:8000/api/openapi.json
- Raw OpenAPI specification
- For programmatic use & third-party tools
After installing new packages, update requirements file:
pip freeze > requirements.txtPOST /expenses
{
"amount": 50.0,
"category": "food",
"description": "lunch",
"date": "2026-02-04T12:00:00",
"payment_method": "card"
}GET /expenses
GET /expenses/{id}
PUT /expenses/{id}
{
"amount": 75.0,
"category": "food",
"description": "dinner",
"date": "2026-02-04T12:00:00",
"payment_method": "card"
}Response:
{
"success": true,
"message": "Expense updated",
"data": {
"id": 1,
"amount": 75.0,
"category": "food",
"description": "dinner",
"date": "2026-02-04T12:00:00",
"payment_method": "card"
}
}GET /expenses/convert/{target_currency}
Converts all user expenses from INR to a target currency using real-time exchange rates.
Example Response:
{
"success": true,
"data": [
{
"id": 1,
"amount": 100,
"original_amount": 100,
"original_currency": "INR",
"converted_amount": 1.11,
"target_currency": "USD",
"category": "food",
"description": "lunch"
}
],
"total_in_target_currency": 111.5,
"exchange_rate": 0.0111,
"target_currency": "USD",
"base_currency": "INR"
}DELETE /expenses/{id}
Deletes an expense by ID.
Response:
{
"success": true,
"message": "Expense deleted"
}Purpose: Convert user expenses to different currencies when traveling.
Provider: ExchangeRate-API
Setup: API key is configured in .env file (see Step 3 above)
Feature Description: When a user selects a country/currency from the UI:
- Backend receives the target currency code (e.g.,
USD,EUR,GBP) - Backend calls the Exchange Rate API to fetch current exchange rates from INR
- All existing expenses are converted to the selected currency
- User sees individual expenses and total expenses in the selected currency
- This is helpful when traveling to another country to track spending in local currency
Supported Currencies: 160+ currencies including USD, EUR, GBP, JPY, INR, AED, and more.
| Column | Type | Notes |
|---|---|---|
| id | BIGINT | Primary Key (auto-generated) |
| amount | FLOAT | Expense amount |
| category | VARCHAR(50) | Category name |
| description | TEXT | Optional description |
| date | TIMESTAMP | When expense occurred |
| payment_method | VARCHAR(50) | cash, card, digital wallet |
| created_at | TIMESTAMP | Auto-set on creation |
| updated_at | TIMESTAMP | Auto-set on creation |
--
backend/
├── app/
│ ├── model/
│ │ └── expense_model.py
│ └── routes/
│ ├── get_routes.py
│ └── post_routes.py
├── migrations/
│ └── 001_create_expenses_table.sql
├── main.py
├── setup_db.py
├── requirements.txt
└── .env
This guide covers deploying your Expense Tracker backend to AWS EC2 with Nginx reverse proxy.
- OS: Ubuntu 22.04
- Instance type: t3.small (recommended minimum 2GB RAM)
Open Security Group Ports:
- 22 (SSH)
- 80 (HTTP)
- 443 (HTTPS)
ssh -i your-key.pem ubuntu@YOUR_PUBLIC_IPsudo apt update && sudo apt upgrade -ycd ~
git clone https://github.com/your-repo/backend.git
cd backend# Install Python and venv
sudo apt install python3 python3-venv python3-pip -y
# Create virtual environment
python3 -m venv env
source env/bin/activate
# Install dependencies
pip install -r requirements.txt
pip install gunicorn
# Deactivate when done
deactivatenano .envAdd your API keys:
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_secret_key
EXCHANGE_RATE_API_URL=https://v6.exchangerate-api.com/v6/YOUR_API_KEY/latestSave with Ctrl+X → Y → Enter
sudo nano /etc/systemd/system/fastapi.servicePaste the following:
[Unit]
Description=FastAPI App
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/backend
ExecStart=/home/ubuntu/backend/env/bin/gunicorn \
-k uvicorn.workers.UvicornWorker \
main:app \
--bind 127.0.0.1:8000 \
--workers 2
Restart=always
[Install]
WantedBy=multi-user.targetSave with Ctrl+X → Y → Enter
sudo systemctl daemon-reload
sudo systemctl enable fastapi
sudo systemctl start fastapi
# Check status
sudo systemctl status fastapisudo apt install nginx -ysudo nano /etc/nginx/sites-available/defaultReplace with:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location /api/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
root /var/www/html;
index index.html;
try_files $uri /index.html;
}
}# Test configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
# Enable on startup
sudo systemctl enable nginx# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Generate certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Auto-renewal enabled by default- API:
http://yourdomain.com/api/v1/expenses - Docs:
http://yourdomain.com/api/docs - Check logs:
sudo journalctl -u fastapi -f