6.9 KiB
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
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
./uploadsand./outputsare bind-mounted (seedocker-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 <file>is the fastest available sanity check after editing a.pyfile. - Running
python app/main.pyoutside Docker will fail on the defaultUPLOAD_FOLDER/OUTPUT_FOLDERpaths (/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/<name>/: each tool is a self-contained package:
routes.py— a FlaskBlueprintwithurl_prefix="/<name>". 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.configaccess, and any tool-local mutable state live here.logic.py— the tool's actual business logic, deliberately Flask-free (noapp/current_app/requestimports; 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/<name>/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.pydoes 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 theMERCHANT_LOOKUPdict — anything not in that dict comes back asunmappedand processing halts until it's added there.run_audit()(CSV statement) andrun_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 finalEIB_Processed[_Audited]_<date>.xlsx, appending the audit table 4 columns right of the EIB columns, color-coded MATCHED (green) / REVIEW REQUIRED (red).
routes.pywires uploads and these functions together behind/eib/..., including a module-levelPROCESS_STATUSdict polled by the frontend for live progress — explicitly a single-job/single-user shortcut, not safe for concurrent runs.templates/eib/index.htmlis a single vanilla-JS page (no build step, no framework) that polls/eib/api/process/statusduring processing.- To add a merchant mapping: edit
MERCHANT_LOOKUPinapp/tools/eib/logic.py, then rebuild/restart theappservice.
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:
- Landing page first, in isolation.
templates/home.htmlwas built and previewed behind a throwaway/home-previewroute 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. - 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/eibURL prefix and namespaced API routes, and the temporary/home-previewroute was replaced by the real/route driven by theTOOLSregistry inapp/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/<name>/ following the eib pattern (Blueprint
with url_prefix="/<name>", Flask-free logic.py), add templates/<name>/, 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/).