Architecture
System in one sentence
Hoopoe is a three-container stack — a React frontend, a Fastify backend, and a PostgreSQL database — orchestrated by Docker Compose and designed to run on a single host. An optional fourth container runs a Model Context Protocol server for local LLM access.
Diagram
┌─────────────────────────────────────┐
│ Browser (127.0.0.1:8000) │
│ React 18 + Vite + TanStack Query │
└────────────────┬────────────────────┘
│ HTTP
▼
┌─────────────────────────────────────┐
│ Frontend container │
│ nginx serving built Vite assets │
│ (proxies /api → backend:3000) │
└────────────────┬────────────────────┘
│ HTTP
▼
┌─────────────────────────────────────┐
│ Backend container │
│ Node 20 + Fastify 5 + TypeScript │
│ Drizzle ORM · argon2id · pg driver │
│ Loopback :8001 → container 3000 │
└────────────────┬────────────────────┘
│ SQL
▼
┌─────────────────────────────────────┐
│ PostgreSQL 16 container │
│ pg_trgm · unaccent · pgcrypto │
│ Host port 5432 bound to 127.0.0.1 │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ (Optional) MCP container │
│ End-to-end encrypted with a │
│ per-user token; talks to backend. │
└─────────────────────────────────────┘
Service split
| Container | Runtime | Host port | Container port | Responsibility |
|---|---|---|---|---|
frontend | nginx | 8000 | 8080 | Serves the built React app; proxies /api/* to the backend. |
backend | Node 20 | 8001 (loopback) | 3000 | Business logic, auth, importers, categorization, aggregates. |
postgres | PostgreSQL 16 | 5432 (loopback) | 5432 | Persistence. Uses pg_trgm, unaccent, pgcrypto. |
mcp (optional) | Node 20 | not exposed | — | LLM tool surface. Encrypts payloads with a per-user token. |
The frontend listens on every host interface so other devices on your
LAN can reach the app. The backend (127.0.0.1:8001) and Postgres
bind to loopback only — nginx reaches the backend via the compose
network, and nothing outside the host should touch them directly.
Request flow: "user imports an OFX file"
Follow one operation end-to-end so the layers become concrete.
- Browser — the user drops
bnp_2026-06.ofxon the Imports page. The frontendPOSTs the file to/api/imports. - Frontend proxy — nginx forwards the request to the backend
container at
http://backend:3000/api/imports. - Backend auth plugin — verifies the session cookie
(
backend/src/http/plugins/auth.ts), rotates the session id on login (not on every request), and attaches the user id to the request. - Backend import route — reads the file, sniffs the encoding,
detects the format (OFX in this case), and hands off to the OFX
parser in
backend/src/domain/imports/. - OFX parser — yields a stream of candidate transactions with normalised labels (accent-folded, case-folded for full-text search).
- Categorization pass — each candidate is run through the user's
rule set (
backend/src/domain/rules/). Matches get acategory_id; non-matches stayNULLand land in the Sort tab. - Deduplication + insert — the backend computes a content
signature for each candidate and asks Postgres to insert with an
ON CONFLICTclause on the signature. New rows land; duplicates increment the "read but deduped" counter. - Audit row — an
importsrow records the file hash, count of inserted / skipped / errored, and the timestamp. Re-uploading the same file is a no-op. - Response — the backend replies with the per-file summary; the frontend renders it under the drop zone.
For PDFs, step 5 is replaced by the template wizard flow (see the user-facing Importing page); everything else is the same.
Key libraries
- Fastify 5 — HTTP framework. Chosen for its schema-first route validation and low overhead.
- Drizzle ORM — typed SQL. The schema lives in
backend/src/db/schema.tsand doubles as the type source for API responses. - TanStack Query — server state on the frontend. Every API call
is a
useQueryoruseMutation; caching and background refetch are handled by the library. - Tailwind 3 — utility CSS. No component library; the design
system lives in
frontend/src/components/. - PostgreSQL extensions:
pg_trgm— trigram indexes for full-text search.unaccent— accent folding at query time.pgcrypto— random secrets and the MCP payload encryption.
argon2(argon2id mode) — password hashing. Per-user salt, OWASP 2024 parameters (19 MiB memory, 2 iterations, parallelism 1).- Hand-written SQL migrations — files under
backend/src/db/migrations/, applied in lexicographic order at server boot, tracked in aschema_migrationstable. Each file runs in its own transaction.
Observability
The backend exposes Prometheus metrics at GET /metrics on the same
port as the API, rate-limited to 20 requests per minute per client IP.
The route exists only when METRICS_TOKEN is set (bearer token required)
or METRICS_PUBLIC=true (no auth); otherwise it returns 404. See the top-level README's Metrics section
for the labels and canonical scrape config.
Where to go next
- Code map — where things live in the tree.
- Development — how to run the stack locally and where the tests are.
- Database — schema highlights and migration workflow.