How kpeoh/finance-tracker works
Purpose and Entry Points
Finance Tracker is a work-in-progress multi-user personal-finance API. It manages user-owned categories and transactions, secured with JWT bearer authentication. The executable ASGI entry point is backend/app/main.py; local operation runs PostgreSQL through docker-compose.yml and starts Uvicorn against that app. frontend/ is only a placeholder.
HTTP API Composition
FastAPI route modules expose authentication, current-user identity, and protected category/transaction CRUD:
• backend/app/api/routes/auth.py
• backend/app/api/routes/users.py
• backend/app/api/routes/categories.py
• backend/app/api/routes/transactions.py
backend/app/main.py assembles these routers and provides the health endpoint. Route handlers form the API boundary: they validate request/response contracts, obtain dependencies, and delegate domain persistence rules rather than directly defining the data model.
Authentication and Request Identity
OAuth2 password-flow login issues JWTs; protected routes resolve the bearer token into the current user and enforce ownership:
• backend/app/core/security.py
• backend/app/api/deps.py
• backend/app/schemas/auth.py
There is intentionally no public registration endpoint. Users are provisioned directly in PostgreSQL, with roles including admin, user, and constrained test.
Domain Model and Contracts
SQLAlchemy models define the central persisted graph: users own categories and transactions, while each transaction references a category. Pydantic v2 schemas define API-facing create, update, and nested read shapes:
• backend/app/models/user.py
• backend/app/models/category.py
• backend/app/models/transaction.py
• backend/app/schemas/category.py
• backend/app/schemas/transaction.py
Transactions return related user/category data through nested read models. The schema layer isolates HTTP payload representation from ORM entities.
Service-Layer Rules
Services implement business and persistence operations behind routes:
• backend/app/services/user.py
• backend/app/services/category.py
• backend/app/services/transaction.py
The category and transaction services apply ownership checks; transaction operations additionally validate that the referenced category belongs to the requesting user. Test-role users are capped at five categories and fifteen transactions, making role-based limits a domain rule rather than a client concern.
Database and Lifecycle
The backend uses asynchronous SQLAlchemy 2 with asyncpg against PostgreSQL. Database engine/session setup is centralized in backend/app/database.py; environment-driven settings reside in backend/app/core/config.py. Alembic owns schema evolution:
• backend/alembic/env.py
• backend/alembic/versions/31e92ce704bb_initial.py
PostgreSQL is the current Docker Compose infrastructure service; the API itself is currently run outside Compose.
Operations and Evolution Boundaries
backend/scripts/reset_test_user.py is an operational data-management path: it finds the test-role user, clears their finance data, and seeds demo categories/transactions. It is intended for scheduled deployment use. Architecture choices and intended API/database layering are recorded in docs/adr/0001-database-stack.md and docs/adr/0002-api-layer-structure.md. Planned boundaries include stats endpoints, stronger login controls, refresh/logout flows, a containerized API, and a future frontend.
Main entry points: database.py Async database sessions · transaction.py Transaction service · user.py User model · category.py Category service
Components 16
API Runtime
- FastAPI ASGI app · Assembles routers and serves health checks.
backend/app/main.py - Protected API routers · Auth, identity, category, and transaction endpoints.
- API schemas · Separates HTTP create, update, and nested read payloads from ORM entities.
backend/app/schemas/transaction.py
Identity
- JWT security · Password login issues tokens and validates bearer credentials.
backend/app/core/security.py - Current-user dependency · Resolves authenticated users for protected requests.
backend/app/api/deps.py
Domain
- User service
backend/app/services/user.py - Category service · Enforces ownership and test-user category limits.
backend/app/services/category.py - Transaction service · Enforces ownership, category ownership, and test-user transaction limits.
backend/app/services/transaction.py - User model · Users own categories and transactions and carry roles.
backend/app/models/user.py - Category model · User-owned transaction classification.
backend/app/models/category.py - Transaction model · References its owning user and category.
backend/app/models/transaction.py
Data & Evolution
- Async database sessions · Central engine and session setup using asyncpg.
backend/app/database.py - PostgreSQL
docker-compose.yml - Alembic migrations · Owns PostgreSQL schema creation and upgrades.
backend/alembic/env.py - Environment settings
backend/app/core/config.py
Operations
- Reset test user · Clears and seeds demo finance data for the constrained test role.
backend/scripts/reset_test_user.py
Connections 24
- FastAPI ASGI app → Protected API routers: mounts
- Protected API routers → API schemas: validates payloads
- Protected API routers → Current-user dependency: requires identity
- Protected API routers → JWT security: login
- Current-user dependency → JWT security: validates token
- Protected API routers → User service: delegates users
- Protected API routers → Category service: delegates categories
- Protected API routers → Transaction service: delegates transactions
- User service → User model: persists
- Category service → Category model: persists
- Transaction service → Transaction model: persists
- Category service → User model: checks owner
- Transaction service → User model: checks owner
- Transaction service → Category model: validates category owner
- User model → Category model: owns
- User model → Transaction model: owns
- Transaction model → Category model: references
- User service → Async database sessions: uses session
- Category service → Async database sessions: uses session
- Transaction service → Async database sessions: uses session
- Async database sessions → PostgreSQL: asyncpg
- Environment settings → Async database sessions: configures
- Alembic migrations → PostgreSQL: evolves schema
- Reset test user → Async database sessions: clears and seeds