## TASK
#404 TripTalley backend: FastAPI+SQLite per PLAN.md; design phase done (#563), backend implementation in progress (#564-#572 pending).

## STATE
Backend at `backend/app/`: core/, models/, schemas/, services/, routers/, alembic/. Implemented: `main.py`, `core/{money.py,split.py,settle.py,db.py,config.py}`, `models/models.py`, `schemas/schemas.py`, `routers/{auth.py,trips.py,expenses.py,settlements.py,sync.py}` (all stubs), `services/fx_service.py`, `requirements.txt`, `alembic/env.py`, `DEPLOY.md`, `backend/tests/`. `triptalley.db` created with all tables. Alembic migration `d2efb7ea2b22_initial_migration.py` generated and applied. Dependencies installed with `--break-system-packages`. Git: `backend/` untracked; `DEPLOY.md` modified; `fx_service.py` updated to fix API endpoint.

## DECISIONS
- Money: integer minor units + ISO-4217; no floats.
- FX: 3-role (original → trip-settlement → display), business-day fallback, cached in `fx_rate` table.
- Settlement: on-demand via debt simplification; no stored settlements.
- SQLite + SQLAlchemy (async) + FastAPI.

## TRIED AND FAILED
- `path/srv/RUNBOOK.md` missing (path outside project).
- Assumed backend committed; only design/docs/prototype committed.
- Early scaffolding missing alembic setup; created at `backend/alembic/env.py`.
- Git log shows no backend commits—files exist but untracked.
- `backend/app/tests/` does not exist; tests dir is `backend/tests/` only.
- Relative imports in `settle.py` failed standalone (`from .money import ...`).
- `UniqueConstraint` not imported in `models/models.py`; caused `NameError`.
- System Python externally managed; used `pip install --break-system-packages`.
- `fx_service.py` referenced but did not exist in `core/`; actually at `services/fx_service.py`.
- Router stubs have no auth, DB, or business logic—only imports and `APIRouter()`.
- `backend/alembic/versions/` empty; no initial migration generated.
- `routers/__init__.py` missing; caused `ImportError`.
- Async `sqlite+aiosqlite://` URL failed in Alembic; requires sync `sqlite://` for migrations.
- `python` not in PATH; used `python3`.
- `alembic` CLI not in PATH; used `python3 -m alembic`.
- Alembic init failed because `alembic/` dir existed and non-empty.
- Migration generation failed until sync DB URL used in env.py.
- `fx_service.py` Frankfurter API endpoint `https://api.frankfurter.app` returned 301 redirect to `https://api.frankfurter.dev`; updated `FRANKFURTER_API` constant.

## OPEN
- #564 Scaffold: partial (deps/app skeleton done; DEPLOY.md updated, tests dir empty, db created).
- #565 Migrations: initial migration generated and applied; DB exists with all tables.
- #566 Split engine: stubs implemented but no tests.
- #567 Settlement engine: `Balance`, `Payment` dataclasses and `simplify_debt` stub implemented.
- #568 FX service: exists at `services/fx_service.py`; API endpoint fixed (frankfurter.dev); needs review/completion.
- #569 Display conversion logic pending in FX service or router.
- #570 Auth router: stub only; no endpoints implemented.
- #571 Sync endpoints: stub only; no implementation.
- #572 Tests: `backend/tests/` exists but empty.
- #573 Live API demo deployment not configured.

## LEARNED
- `money.py`: `CURRENCY_METRICS` maps ISO codes to (exponent, minor_name); `from_minor`/`to_minor` converters; `split_equal/percentage/custom` helpers with largest-remainder.
- `settle.py`: `Balance` (user_id, amount_minor, currency), `Payment` dataclasses; `simplify_debt()` stub.
- `fx_service.py` at `services/`: `FXService` class with `get_rate()` using Frankfurter API + DB caching + 7-day lookback; requires SQLAlchemy session.
- `schemas.py`: `CurrencyAmount`, `UserCreate/Update`, `TripCreate`, `ExpenseCreate`, `SplitParams` models (Pydantic v2).
- `split.py`: `SplitEngine.split_equal/percentage/custom()` calling `money.split_*`.
- Router files minimal stubs—no logic, auth, or DB integration.
- `db.py`: Async engine/session setup; `build_database_url()` helper; SQLite-ready.
- `models/models.py`: User, Trip, Group, Expense, Split models with `user_group`, `user_trip`, `fx_rate` tables; `UniqueConstraint` imported.
- Relative imports require module context; run `from core.settle import ...` inside `app/`.
- `routers/__init__.py` must exist.
- Alembic requires sync DB URL for migrations.
- Auth router stub at `routers/auth.py` only contains `router = APIRouter()` and comments listing endpoints.
- `main.py` imports all routers; `lifespan()` creates tables on startup.
- Core modules (`money.py`, `settle.py`, `split.py`) tested successfully with python3 REPL.
- `build_database_url()` returns `sqlite+aiosqlite:///./triptalley.db`; Alembic overrides to `sqlite:///./triptalley.db`.
- `settlements.py`, `sync.py` stubs only contain `router = APIRouter()` and commented endpoint plans.
- Frankfurter API migrated from `https://api.frankfurter.app` to `https://api.frankfurter.dev`; `fx_service.py` updated.