Page:
Developer Setup
No results
1
Developer Setup
Niels Franke edited this page 2026-06-10 23:50:28 +02:00
Developer Setup
Prerequisites
- Python 3.11+
- Node.js 18+
- Git
Initial setup
# Python environment
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
# Frontend dependencies
npm --prefix apps/web install
# Playwright (required for HTML→PDF rendering in extraction)
.venv/bin/playwright install chromium
Two-terminal hot-reload
# Terminal 1 — backend (auto-reloads on Python changes)
BILLDOZER_WEB_APP_URL=http://localhost:5173 \
.venv/bin/uvicorn main:app --app-dir apps/api --reload --port 9191
# Terminal 2 — frontend (Vite dev server, proxies /api → :9191)
npm --prefix apps/web run dev
Open http://localhost:5173.
Running tests
# Full suite (run before every push)
.venv/bin/python -m pytest apps/api/tests -q && npm --prefix apps/web test -- --run
# Single Python test file
.venv/bin/python -m pytest apps/api/tests/test_pipeline_ingestion.py -q
# Single frontend test file
npm --prefix apps/web test -- --run --reporter=verbose apps/web/src/__tests__/api.test.ts
Linting
.venv/bin/ruff check apps/api # check only
.venv/bin/ruff check --fix apps/api # auto-fix
Repo layout
apps/
api/
main.py # FastAPI app, mounts routers + serves SPA
billdozer/
models.py # SQLModel: EmailRecord + EmailCandidateMetadata
db.py # init_db(), schema migrations
pipeline.py # scan orchestration, candidate persistence
classification.py # rule-based classifier, portal link extractor
extraction.py # PDF download + Playwright HTML→PDF
exporter.py # ZIP + CSV manifest generation
gmail_client.py # Gmail API wrapper, query builder
token_store.py # Fernet-encrypted token r/w
oauth_config_store.py # Encrypted OAuth client credential storage
session_token.py # In-memory UI session token
config.py # pydantic-settings, BILLDOZER_* env vars
routes/
auth.py # /api/auth/*
scans.py # /api/scans/*
review.py # /api/review/*
tests/
web/
src/
App.tsx # Step state machine (Setup → Review → Export)
api.ts # All fetch calls
components/
SetupPage.tsx
ReviewPage.tsx # View switcher (Tinder / Grid / List)
ExportPage.tsx
TinderView.tsx
GridView.tsx
ListView.tsx
styles.css
Database migrations
init_db() runs at startup. Schema changes use raw ALTER TABLE statements guarded by PRAGMA table_info checks — no migration framework. Pattern:
existing_cols = {row[1] for row in session.exec(text("PRAGMA table_info(emailcandidatemetadata)")).all()}
for col, definition in [("new_column", "TEXT NOT NULL DEFAULT ''")]:
if col not in existing_cols:
session.exec(text(f"ALTER TABLE emailcandidatemetadata ADD COLUMN {col} {definition}"))
session.commit()
Key invariants
- Idempotent ingestion: re-scanning the same
gmail_idis a no-op. Never delete and re-insert to "refresh" a record. - No live Gmail in tests: use fake client classes that implement
iter_invoice_candidates(). No mocking of the Gmail API itself. - No AI model wired:
classify_documentaccepts anAIAdapterprotocol parameter but is always called withai_adapter=None. Classification is purely rule-based. - Tokens encrypted at rest: never read/write
.billdozer/tokens.jsondirectly — go throughtoken_store.py.
Commit style
Conventional commits: feat:, fix:, docs:, chore:, refactor:, test:.
Update both AGENTS.md and CLAUDE.md in any commit where workflows, key modules, or milestones change.
Environment variables
| Variable | Default | Purpose |
|---|---|---|
BILLDOZER_GMAIL_CLIENT_ID |
— | OAuth client ID (overridden by encrypted config) |
BILLDOZER_GMAIL_CLIENT_SECRET |
— | OAuth client secret |
BILLDOZER_UI_SESSION_TOKEN |
local-dev-token |
Guards write endpoints |
BILLDOZER_WEB_APP_URL |
http://localhost:9191 |
CORS origin for dev server |