# Expense Tracker API A focused REST API built with Axum, SQLx, and PostgreSQL. It supports account registration/login, JWT bearer authentication, per-user expense CRUD, runtime SQL migrations, and generated OpenAPI/Swagger documentation. ## Requirements - Rust `1.98.1` and Cargo, selected by the included `mise.toml` - A PostgreSQL server you manage (no container runtime or helper executable is required) - `mise` to use the provided tasks All Rust crate versions are exact pins in `Cargo.toml`; `Cargo.lock` is committed and commands use `--locked`. ## Configuration and run Create a PostgreSQL database and a role with permission to connect and create/alter the application's tables. Configure these environment variables in your shell or secret manager; do not commit real values: ```sh export DATABASE_URL='postgresql://:@:/' export JWT_SECRET='' export BIND_ADDR='127.0.0.1:3000' # Optional; defaults to 127.0.0.1:3000. ``` The JWT secret must contain at least 32 bytes and should be generated/stored by your secret manager. On startup the application connects to PostgreSQL and applies embedded migrations. The database role needs permission to create the `pgcrypto` extension (or have it preinstalled) and create the application tables/indexes. ```sh mise install mise run install mise run run ``` `mise run install` installs the pinned toolchain and fetches locked dependencies. `mise run check` runs formatting verification, tests, and Clippy with `all` and `pedantic` enabled. Checks that need a database are intentionally not part of the unit test suite. ## API - `GET /health` — process health check - `POST /api/auth/register` — JSON `{ "email": "person@example.com", "password": "at-least-12-characters" }`; returns a bearer token - `POST /api/auth/login` — same request and response shape - `POST /api/expenses` — create an expense (requires `Authorization: Bearer `) - `GET /api/expenses` — list the authenticated user's expenses - `GET /api/expenses/{id}` — retrieve one of the authenticated user's expenses - `PUT /api/expenses/{id}` — replace an expense's writable fields - `DELETE /api/expenses/{id}` — delete an expense (204) - `GET /docs` — Swagger UI; `GET /api-doc/openapi.json` — OpenAPI document Expense JSON uses integer minor units to avoid floating-point money errors: ```json { "amount_cents": 1299, "currency": "USD", "description": "Lunch", "occurred_on": "2026-10-08" } ``` Amounts must be positive and at most 1,000,000,000.00 in the currency's minor unit; currency must be a three-letter ASCII code and is normalized to uppercase. Passwords are hashed with Argon2id's default Argon2 configuration and random salts. Expense queries are scoped by authenticated user ID, so one account cannot read or change another account's records. Tokens are HS256 signed and expire after 24 hours. ## Limitations This MVP has no refresh/revocation flow, rate limiting, email verification, pagination, or currency-specific fraction-digit rules. It returns generic authentication failures and hides internal database errors from clients. Deploy behind TLS, set secrets through a secret manager, and apply operational database backup/monitoring policies before production use.