Go to file
JasonFraser 65fa93bb28 Add plain-language flags, source highlighting, and flag navigation (R.2)
The piece that gives R.1's highlighting infrastructure something to do,
and the first genuinely new review-screen UI (R.1 was all plumbing -
same page, same components, just a different PDF renderer underneath).

New flagCatalogService.js translates each check's own raw mismatch/
issue data into a four-part plain-language flag (what/where/why/what to
do). Only running_balance/date_sanity/structure_sanity/
narrative_direction ever carry row-level data - the other three checks
are whole-statement, confirmed by reading checks_service.py directly.
date_sanity/structure_sanity return a free-text issue string, not a
structured type - pattern-matched against the backend's own known
message shapes, with a fallback that always shows the raw text rather
than silently dropping it if that text ever changes.

TransactionRow.vue gained a flag-icon toggle opening a second <tr> with
every flag's own explanation (Vue 3 supports multi-root components, so
this is a real sibling row, not a wrapped div that would break the
table's HTML) and a "Show on source" button.

The real design question: how does a flagged row (deep inside
TransactionsTable) tell the source panel (a sibling three levels up, no
direct prop/event path) to highlight itself? Solved with
uiStore.highlightRequest as the bridge - TransactionRow sets it,
ExtractorView (which holds the actual ref to SourceDocumentPanel)
watches it and calls the panel's own showHighlight(), built in R.1 but
unused until now. SourceDocumentPanel also clears both the request and
its own highlight state whenever the active document changes, so a
stale box never lingers over a different document.

useTransactionFilters.js gained a flaggedOnly toggle; TransactionsTable
added "Flagged only"/"Next flagged" buttons (shown only when something
is actually flagged) - the latter cycles through flagged rows via
scrollIntoView on each row's own id, wrapping after the last.

Verified: flagsForIndex executed directly against real backend output
(a live /api/process call against the HSBC-Aug fixture, which has a
real documented running_balance mismatch) plus synthetic data covering
every builder's own branches, including two checks flagging the same
row and confirming whole-statement checks never contribute a row flag.
npm run build passes, the app container rebuilt, measure.py unaffected
(pure frontend presentation, no backend touched). Not machine-verified:
the actual click-through - Claude-in-Chrome did not connect this
session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-13 15:47:36 -04:00
backend Add per-row source position capture for the review screen's highlighting 2026-10-13 11:18:10 -04:00
docs Rebuild the app shell as an enterprise header/sidebar/footer layout 2026-10-13 08:05:55 -04:00
frontend Add plain-language flags, source highlighting, and flag navigation (R.2) 2026-10-13 15:47:36 -04:00
pocketbase Move Excel exports to R2; remove dead per-extraction workbook generation 2026-10-13 07:13:20 -04:00
uploads Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
zexample Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
.env.example Add PocketBase: accounts (password + Google) + schema for R2-backed docs 2026-10-13 00:26:41 -04:00
.gitignore Move Excel exports to R2; remove dead per-extraction workbook generation 2026-10-13 07:13:20 -04:00
CLAUDE.md Add plain-language flags, source highlighting, and flag navigation (R.2) 2026-10-13 15:47:36 -04:00
Dockerfile Move Excel exports to R2; remove dead per-extraction workbook generation 2026-10-13 07:13:20 -04:00
ENTERPRISE_STANDARDS.md Fix edit-icon color, description autogrow, and add image zoom controls 2026-10-11 23:44:06 -04:00
README.md Add PocketBase: accounts (password + Google) + schema for R2-backed docs 2026-10-13 00:26:41 -04:00
UI_DESIGN_THEME.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
UI_DESIGN_THEME_ENTERPRISE.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
docker-compose.yml Move Excel exports to R2; remove dead per-extraction workbook generation 2026-10-13 07:13:20 -04:00
requirements.txt Add raw-OCR-word-box fallback for Docling table-structure failures 2026-10-11 17:22:34 -04:00

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:

  1. docker compose up --build -d pocketbase
  2. 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"
  3. Copy .env.example to .env and 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 at http://localhost:8090/_/, under Collections → users → Options → OAuth2).
  4. 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.