A simple FastAPI backend for managing personal finance data (transactions, categories, balances). Built with FastAPI, PostgreSQL, and Docker.
This repository is intended to be used as a backend API, for example consumed by a Next.js frontend (separate repo).
- FastAPI (async, fast, modern)
- PostgreSQL database
- SQLAlchemy ORM
- Alembic-ready (migrations)
- Docker & docker-compose
- Environment-based configuration
- Ready for cloud deployment (AWS / Fly.io / Railway)
- Backend: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Server: Uvicorn
- Containerization: Docker, Docker Compose
.
βββ app/
β βββ main.py # FastAPI entry point
β βββ database.py # DB connection & session
β βββ models/ # SQLAlchemy models
β βββ routers/ # API routes
β βββ schemas/ # Pydantic schemas
β
βββ docker-compose.yml
βββ Dockerfile
βββ .env.example
βββ .gitignore
βββ README.md
Create a .env file based on .env.example:
DATABASE_URL=postgresql+psycopg2://postgres:postgres@db:5432/money_manager
β οΈ .envis not committed to GitHub
docker compose up --buildhttp://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
From host:
psql -h localhost -p 5432 -U postgres -d money_managerFrom Docker:
docker exec -it money_manager_db psql -U postgres -d money_managerThis API is designed to be consumed by a separate Next.js repository.
Example environment variable in Next.js:
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
Example request:
fetch(`${process.env.NEXT_PUBLIC_API_URL}/transactions`)Make sure CORS is enabled in main.py:
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"] ,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)Restrict origins in production.
- Cheapest: AWS EC2 + Docker
- Managed: Fly.io / Railway / Render
- Frontend: Vercel (Next.js)
- Authentication (JWT)
- User accounts
- Categories & budgets
- Monthly reports
- Alembic migrations
MIT License
Dehya Qalbi
If you have questions or want to extend this project, feel free to open an issue or PR π