A small internal API for submitting, approving and splitting expenses. FastAPI with plain sqlite3.
uv sync
uv run uvicorn app.main:app --reload
The database lives at ./expenses.db (override with EXPENSES_DB) and is created and seeded on first start. Interactive docs are at /docs.
uv run pytest
uv run ruff check .
uv run ruff format --check .
Send Authorization: Bearer <token>. A missing or unknown token gets a 401.
| Id | Name | Role | Manager | Token |
|---|---|---|---|---|
| 1 | Priya Nair | finance | token-priya |
|
| 2 | Marcus Webb | manager | token-marcus |
|
| 3 | Elena Rossi | manager | token-elena |
|
| 4 | Sam Okafor | employee | Marcus | token-sam |
| 5 | Jo Tremblay | employee | Marcus | token-jo |
| 6 | Dana Lindqvist | employee | Elena | token-dana |
| Method and path | Who |
|---|---|
GET /health |
anyone |
GET /users/me |
any user |
GET /users/{id} |
that user, their manager, or finance |
POST /expenses |
any user; creates a draft |
GET /expenses |
employee: own; manager: own and direct reports'; finance: all; query limit (default 50, 1–200) and offset (default 0, ≥ 0), 422 if out of range; ordered by spent_on descending then id; amount_cents is an integer in cents, in the submitted currency, never converted |
GET /expenses/{id} |
owner, owner's manager, or finance |
POST /expenses/{id}/submit |
owner; draft to submitted |
POST /expenses/{id}/approve |
owner's manager or finance, never the owner |
POST /expenses/{id}/reject |
same as approve; body {"reason": "..."} required, 1–500 characters (422 otherwise); returned as reject_reason |
POST /expenses/{id}/split |
owner; body {"user_ids": [...]}, splits the amount evenly |
GET /expenses/{id}/splits |
same as GET /expenses/{id} |
GET /exports/expenses.csv?month=YYYY-MM |
finance; approved expenses spent in that month, as CSV |
Paging example: fetch the second page of 20 expenses with
GET /expenses?limit=20&offset=20. Keep adding limit to offset until a page returns fewer than limit rows.
app/main.py app factory and /health
app/db.py schema, seed data, connection dependency
app/auth.py bearer token auth and require_role
app/users.py user routes
app/expenses.py expense routes and status changes
app/splits.py expense splitting
app/exports.py CSV exports
tests/ one test file per module
docs/data.md data notes