Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 10:30 UTC
arena/2d4eda07-aram
Aram backend
Pilot Workbench (working V1 slice)
A runnable, end-to-end pilot application lives at /pilot/ (the root URL
redirects there). It takes a Pilot workbook v0.1 .xlsx, runs the accepted
read-only preflight, lets a reviewer resolve the mapping exception queue,
and produces draft Balance Sheet and Income Statement output with full
account-to-source-row drill-down, explicit checks, an audit trail, and a
reviewable Excel export.
cd backend
python -m pip install -e '.[test]'
uvicorn aram_backend.main:app --host 0.0.0.0 --port 8000
# open http://localhost:8000/pilot/
POST /api/v1/pilot/demostarts a clearly-labelled synthetic demo with two unmapped suspense accounts so the full workflow can be exercised.POST /api/v1/pilot/sessions(multipartfile) uploads a real workbook.PUT/DELETE /api/v1/pilot/sessions/{id}/mappings/{account}edit mappings; every change is recorded in the session audit trail. Reviewed/Approved statuses require a reviewer name, mirroring the workbook contract.GET /api/v1/pilot/sessions/{id}/export.xlsxdownloads the reviewable output (Info, Checks, BalanceSheet, IncomeStatement, Coverage, Exceptions, AuditTrail).
Generic, company-agnostic editing
The workbench is not tied to any specific company. Within a session you can:
- Accounts —
POST /accountsadd,PUT /accounts/{code}edit,POST /accounts/{code}/renamechange the code (the mapping is carried forward automatically),DELETE /accounts/{code}remove. A manually added account's closing balance is derived fromopening + debit - credit, never invented; duplicate codes and non-finite values are rejected. - Notes & sub-notes —
POST /notesadd a note or sub-note,PUT /notesedit its title,DELETE /notesremove it. Deleting a note that is the target of any mapping is blocked (HTTP 409) until those mappings move. - Company —
PUT /companychanges name/code/fiscal-year/unit/currency, so the same workspace serves any entity. - Save / resume —
GET /sessions/{id}/workspace.xlsxserializes the full working state back to a valid Pilot v0.1 workbook. Re-uploading it rebuilds the same accounts, notes, mappings and company (lossless round-trip), so work survives across sessions without a database.
Every edit is append-only audited (actor, action, before, after). The UI is mobile-first: bottom navigation, bottom-sheet forms, card layouts, and numeric keyboards, so the whole workflow is usable on a phone.
Safety boundary: sessions are strictly in memory (bounded, thread-safe) and
disappear on restart; the durable artifact is the exported Excel file. No
canonical file, database row, or source value is read or modified. Closing
balances are debit-positive; display signs come only from the explicit
SECTION_POLICY in pilot_engine.py (BS: Assets +, Liabilities −, Equity −;
IS: Revenue −, Expenses +). Unknown sections, conflicting mappings, unmapped
accounts, and CF/EQ targets fail closed into the exception queue — nothing is
guessed. Output is always a working draft, never an official statement.
Pilot workbook preflight
Gate 2A adds a strictly in-memory validator for the governed Pilot workbook. Generate the approved blank template from the repository root with:
cd backend
PYTHONPATH=src python scripts/generate_pilot_template.py
Call preflight_pilot_workbook(workbook_bytes) from
aram_backend.pilot_workbook. The result reports every detectable error with
an exact sheet, Excel row, and field. The function does not persist inputs,
parsed values, mappings, or reports and never guesses a financial value.
Phase 2A provides the persistent, audit-safe data foundation. It deliberately does not ingest spreadsheets, calculate financial values, or alter canonical source files.
Local setup
cd backend
python -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[test]'
alembic upgrade head
uvicorn aram_backend.main:app --reload
Open http://127.0.0.1:8000/docs. The health endpoint is
GET /api/v1/health; read-only schema catalogs are available at
GET /api/v1/schema/entities and GET /api/v1/schema/enums.
Tests
cd backend
pytest
Tests use an isolated temporary SQLite database with foreign-key enforcement. Runtime SQLite files are ignored by Git.
Phase 2B: Source registration and inspection
Phase 2B adds metadata-only registration plus read-only inspection of supported source documents.
- Supported file suffixes:
.xlsxand.csv. - Supported document types:
financial_statement,general_ledger,mapping, andtrial_balance. - Registration stores the fiscal year, safe filename, document type, and SHA-256 content hash. It does not persist source payload bytes.
- An exact duplicate—same fiscal year, content hash, safe filename, and document
type—is idempotent and returns the existing
SourceDocument. - Reusing the same fiscal year and content hash with a different safe filename,
document type, or both raises
SourceRegistrationError. The existing record remains unchanged and no second record is created. - XLSX structural inspection is read-only. General-ledger rows are parsed as typed in-memory records without changing the workbook.
- Phase 2B does not persist financial values, execute mappings, calculate balances, or modify canonical source files.