The actual request was simple (store exports in R2 like source files, pending a retention-duration decision), but investigating where exports were written surfaced something worse: /api/process built and saved a full workbook to disk on EVERY extraction, and nothing in the frontend ever called /api/download/<filename> to retrieve it (confirmed by grep - no reference anywhere). Every extraction was silently orphaning an .xlsx file for no reason; 91 had already accumulated locally from this session's own testing alone. Removed the dead work entirely: /api/process no longer builds or saves a workbook at all. /api/download/<filename>, file_repository. save_workbook/resolve_output_path, and OUTPUT_FOLDER (env var, volume, directory) are all gone - confirmed nothing else referenced any of them before removing. outputs/ deleted, including its 91 accumulated files. /api/export (the only path actually used - Download Excel/All) now builds the workbook into an in-memory BytesIO and streams it straight from there - never touches disk, not even temporarily. The frontend persists it long-term instead: documentsService.saveExportFile uploads the same Blob the browser download already used to a new exportFile field (pb_migrations/3_add_export_file.js), stored in R2 same as sourceFile. Overwrites the previous export rather than keeping a history - no retention policy has been decided yet, and keeping every version would just relocate the same unbounded-growth problem from the VPS to R2 instead of fixing it. Best-effort from ResultCard.vue - a save failure is reported but never blocks the browser download itself. Verified for real: /api/process's response no longer has `filename` (title still does); /api/export still streams a valid, correctly-typed .xlsx; /app/outputs no longer exists in the rebuilt container; the old /api/download URL now falls through to the ordinary SPA catch-all, not a leftover route. documentsService.saveExportFile run against the REAL bytes /api/export produced, fetched back through the R2-backed URL, confirmed byte-for-byte - and confirmed a second export overwrites rather than creating a second record. measure.py unaffected; npm run build passes. |
||
|---|---|---|
| backend | ||
| docs | ||
| frontend | ||
| pocketbase | ||
| uploads | ||
| zexample | ||
| .env.example | ||
| .gitignore | ||
| CLAUDE.md | ||
| Dockerfile | ||
| ENTERPRISE_STANDARDS.md | ||
| README.md | ||
| UI_DESIGN_THEME.md | ||
| UI_DESIGN_THEME_ENTERPRISE.md | ||
| docker-compose.yml | ||
| requirements.txt | ||
README.md
Bettersight Statement Extractor
Turns a bank statement PDF (or a scanned/photographed one) into clean, structured transaction rows, proves the arithmetic against seven automated checks, and exports to Excel. Supports HSBC and RBC statement layouts today, auto-detected rather than hardcoded per bank.
This is Phase 1 of the planned Bettersight product line - extraction + checks + export
only. It deliberately does not categorize transactions (bank description →
accounting description). See CLAUDE.md for the full architecture, the phase roadmap,
and the reasoning behind most of the non-obvious decisions in this codebase.
Running it
docker compose up --build # start everything (app + Docling + PocketBase), foreground
docker compose up --build -d app # rebuild + restart just the app after a code change
docker compose down # stop and remove all containers
Then open http://localhost:8091.
For frontend development with hot reload: cd frontend && npm run dev (Vite, proxies
/api to the backend container) alongside docker compose up for the backend/Docling/
PocketBase containers.
Accounts (PocketBase) - one-time setup
User accounts, client projects, and processed documents are stored in PocketBase
(pocketbase/), including the original statement files in Cloudflare R2 - see
CLAUDE.md's Architecture section for the full reasoning. First-time setup:
docker compose up --build -d pocketbase- Create the superuser (PocketBase's own admin account, separate from app users):
docker compose exec pocketbase ./pocketbase superuser upsert "you@example.com" "a-strong-password" - Copy
.env.exampleto.envand fill in: that superuser's email/password, an R2 bucket + API token (Cloudflare dashboard → R2 → Manage API Tokens), and a Google OAuth2 Client ID/Secret (Google Cloud Console → APIs & Services → Credentials - the redirect URI to register is shown on PocketBase's own Admin UI athttp://localhost:8090/_/, under Collections → users → Options → OAuth2). set -a; source .env; set +a; ./pocketbase/configure-secrets.sh- enables R2 file storage and Google sign-in. Safe to re-run any time credentials change.
Without this, password signup/login still works (migrations alone create the schema); only R2-backed file storage and "Continue with Google" need the secrets configured.
Project layout
backend/ Flask API - routes -> services -> repositories -> schemas
frontend/ Vue 3 + Vite SPA - views -> components -> composables -> services
pocketbase/ Accounts, client projects, and document records - schema as migrations
fixtures/ Real statement PDFs + hand-verified ground truth, for measure.py
docs/ Reference material and test files not part of the measured corpus
results/ measure.py's own dated JSON reports (gitignored)
Measuring accuracy
python3 backend/measure.py
Runs every fixtures/*.pdf with a matching <name>_ground_truth.xlsx through the real
extraction pipeline and reports two numbers: the untouched pass rate (statements that
reach "Verified" with zero edits) and field accuracy (date/description/amount/balance,
compared row-by-row against hand-verified ground truth). A fixture without ground truth
is still run and reported, just without a field-accuracy score. Works with or without
the Docling container up - degrades to pdfplumber-only per page if Docling is
unreachable, the same fallback behavior the live app has.
A fixture's statement can legitimately land on "Failed" or "Needs review" even with
100% field accuracy - that's a check correctly flagging something real about the
statement itself (a cancelled transaction, disagreement between the two extraction
engines on a given page), not an extraction error. measure.py's field accuracy is
what tells you whether the data is actually right; the pipeline status is a separate
signal about how much automated confidence that statement earned.