From bdfa244729c7fa1b6c8d60a35aca98d9aa276174 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 18 Aug 2026 11:29:54 -0400 Subject: [PATCH] Add CLAUDE.md with architecture and project trajectory Documents the platform-shell/tool-blueprint convention, the EIB tool's mechanics, and the two-step path (landing page preview, then blueprint restructuring) so future sessions can pick up without re-deriving it. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..6a4d9d8 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,119 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## What this is + +An internal tools platform for Planeterra International Foundation, built by +Undo Designs. It currently hosts one tool, the **EIB Processor** +(Equals Money → Workday EIB transformer and statement auditor), but the app +is structured so additional tools can be added as self-contained modules +behind a shared landing page. + +## Commands + +```bash +docker compose up --build # start everything (app + Docling), foreground +docker compose up --build -d app # rebuild + restart just the Flask app after code changes +docker compose down # stop and remove both containers +docker logs eib_app --tail 50 # tail the Flask app's logs +``` + +- App: http://localhost:8081 (landing page) / http://localhost:8081/eib/ (EIB tool) +- Only `./uploads` and `./outputs` are bind-mounted (see `docker-compose.yml`) — everything + else is baked into the image at build time, so **code/template edits require a rebuild** + (`docker compose up --build -d app`) to show up; there is no hot reload. +- There is no test suite or linter configured. `python3 -m py_compile ` is the + fastest available sanity check after editing a `.py` file. +- Running `python app/main.py` outside Docker will fail on the default + `UPLOAD_FOLDER`/`OUTPUT_FOLDER` paths (`/app/uploads`, `/app/outputs`) unless those env + vars are overridden — they're container-absolute paths, not repo-relative. + +## Architecture + +**Platform shell — `app/main.py`:** a small Flask app factory. It registers each tool's +Blueprint, defines the `/` route (renders `templates/home.html`), and holds a `TOOLS` list +— one dict per tool (name, tagline, description, url) — that `home.html` loops over to +render tool cards. Adding a tool to the landing page is just appending to `TOOLS`. + +**Tool convention — `app/tools//`:** each tool is a self-contained package: +- `routes.py` — a Flask `Blueprint` with `url_prefix="/"`. All of the tool's page + and API routes live under that prefix (e.g. `/eib/`, `/eib/api/process`), so tool APIs + are namespaced and can't collide with a future tool's routes. Request handling, + `current_app.config` access, and any tool-local mutable state live here. +- `logic.py` — the tool's actual business logic, deliberately Flask-free (no `app`/ + `current_app`/`request` imports; config like folder paths or external service URLs are + passed in as plain arguments). This is what makes a tool "simple but modular": the + transformation rules are portable and readable without the web plumbing. +- Its own `templates//` folder for the tool's page. + +There's intentionally no shared `app/common.py` yet — the plan (per prior discussion) is +to lift out shared helpers only once a second tool actually duplicates something from +`eib`, not preemptively. + +**The EIB tool (`app/tools/eib/`):** +- `logic.py` does the real work: + - `process_raw()` classifies each row of a raw Equals Money export (Card, Exchange, + Cash withdrawal, Fee, Credit, Refund, ...), collapses ATM cash-withdrawal/fee/exchange + transaction groups into single clean rows, and maps merchant descriptions to clean + names via the `MERCHANT_LOOKUP` dict — anything not in that dict comes back as + `unmapped` and processing halts until it's added there. + - `run_audit()` (CSV statement) and `run_audit_pdf()` (PDF statement, four-layer check: + raw-vs-PDF totals, EIB value fidelity, structural zero-impact check on excluded rows, + statement arithmetic identity) reconcile the generated EIB output against a real + statement, per cardholder. + - `parse_pdf_with_docling()` / `extract_balances_from_markdown()` call the self-hosted + Docling container over HTTP to OCR a PDF statement into markdown and pull the + opening/credits/debits/closing balance table out of it. + - `build_excel()` writes the final `EIB_Processed[_Audited]_.xlsx`, appending the + audit table 4 columns right of the EIB columns, color-coded MATCHED (green) / + REVIEW REQUIRED (red). +- `routes.py` wires uploads and these functions together behind `/eib/...`, including a + module-level `PROCESS_STATUS` dict polled by the frontend for live progress — explicitly + a single-job/single-user shortcut, not safe for concurrent runs. +- `templates/eib/index.html` is a single vanilla-JS page (no build step, no framework) + that polls `/eib/api/process/status` during processing. +- To add a merchant mapping: edit `MERCHANT_LOOKUP` in `app/tools/eib/logic.py`, then + rebuild/restart the `app` service. + +**Docker:** `docker-compose.yml` runs two services — `docling` +(`quay.io/docling-project/docling-serve`, port 5001, healthchecked, ~60s to become healthy +on first start) and `app` (this Flask app, host `8081` → container `8080`), with `app` +waiting on Docling's healthcheck via `depends_on`. No database; all state is files under +`uploads/` (temp uploads) and `outputs/` (generated Excel files, plus +`outputs/_debug_markdown/` where Docling's raw responses and extracted markdown get +dumped for debugging PDF parsing failures). + +## Project trajectory + +This started as a single-purpose Flask app: one `app/main.py` (~1000 lines, routes and +business logic together) serving one template at `templates/index.html`, with no other +tools in mind. + +The decision was made to grow it into a small platform hosting several internal tools +behind one landing page. That happened in two deliberate steps rather than one big +rewrite: + +1. **Landing page first, in isolation.** `templates/home.html` was built and previewed + behind a throwaway `/home-preview` route so the design (navy/cyan theme matching the + EIB tool, a card grid, a "more tools soon" placeholder) could be reviewed live without + touching the working EIB tool at all. +2. **Restructure once the design was approved.** The EIB tool was split into + `app/tools/eib/` (`routes.py` + `logic.py`, per the "simple but modular" convention + above), given its own `/eib` URL prefix and namespaced API routes, and the temporary + `/home-preview` route was replaced by the real `/` route driven by the `TOOLS` registry + in `app/main.py`. + +The explicit reasoning behind the module boundary (routes vs. logic, one Blueprint per +tool, no shared `core` package yet) is: keep each tool's business logic simple and +testable in isolation, while keeping the platform shell (`main.py`) thin enough that +adding tool #2 doesn't require touching tool #1. + +**For the next tool:** create `app/tools//` following the `eib` pattern (Blueprint +with `url_prefix="/"`, Flask-free `logic.py`), add `templates//`, register the +blueprint in `app/main.py`, and append an entry to `TOOLS`. Don't build shared +infrastructure speculatively — wait until a second tool needs something `eib` already has, +then lift just that piece into a common module. + +See `eib-processor_how-it-works.md` for a deeper standalone write-up of the EIB tool's +mechanics (predates the platform restructuring but still accurate for `app/tools/eib/`).