How hellopooh/archivum-magnum works
1. System shape
- This is a single FastAPI application backed by PostgreSQL, with both server-rendered pages and JSON/REST endpoints.
- The core domain is a sacrament registry: Baptism, Confirmation, First Communion, Matrimony, and Holy Orders all share one immutable registry pattern.
2. HTTP entry layer
- app/main.py is the app bootstrap and likely wires routers, middleware, and templates.
- The codebase is split into app/routes for page-oriented flows and admin screens, and app/routers for more API-style sacrament endpoints.
- The README’s /sacraments/{sacrament} resource routes map to the unified sacrament API surface.
3. Domain/service boundary
- app/services is the main business-logic layer: certificate issuance, lookup, person handling, ID generation, permission logic, and import processing.
- app/models/sacraments.py and app/validators/canonical_validator.py define the canonical data shape and validation rules that feed certificate creation and duplicate detection.
- app/services/_transforms.py plus _vendor_maps/ normalize imported or vendor-supplied data into the canonical registry model.
4. Registry data model
- The registry is sacrament-specific at the table level, with separate tables for baptism, confirmation, communion, matrimony, and holy orders.
- Despite separate tables, the public interface is unified: each sacrament slug selects the right rules, required fields, and canonical identity mapping.
- Deterministic certificate IDs and record hashes are generated from canonical identity fields, not from display-only form data.
5. Persistence layer
- app/db/connection.py, bootstrap.py, and maintenance.py provide database connectivity, initialization, and operational upkeep.
- SQL structure lives in sql/schema.sql and a later multi-sacrament migration script, showing that the schema evolved from a narrower registry into the current unified one.
- app/db is the boundary between services and PostgreSQL; business logic should not be embedded in routes.
6. Blockchain/audit subsystem
- app/blockchain/layer.py is the tamper-evident ledger layer.
- Issuance and voiding both append deterministic blocks to Postgres, and the repo keeps compatibility with a legacy JSON chain in app/blockchain/blockchain.json.
- The ledger records canonical snapshots, record hashes, sacrament identifiers, and actor metadata so audits can be replayed offline.
7. Security and permissions
- app/security centralizes authentication/session bridging, guard checks, permission definitions, and permission middleware.
- The key authorization boundary is capability-based: cert:create, cert:read, and cert:void.
- This means route handlers are thin; they rely on middleware/guards to decide whether the user can issue, view, or void records.
8. Primary user flows
- The main operational flow is: authenticate → create or import a certificate → persist to Postgres → append blockchain audit entry → render confirmation.
- Lookup/verification flows read registry data and compare it against canonical fields and on-chain hashes.
- Voiding is a controlled update: the record is marked voided in the database and a salted reason hash is written to the blockchain ledger.
9. Import and migration workflow
- app/routers/imports_certs.py, app/services/imports_certs.py, and app/templates/imports_certs/wizard.html implement the historical certificate import pipeline.
- The import path is distinct from normal issuance: it validates external exports, maps vendor fields through transforms, and then commits them into the registry.
- scripts/migrate_blockchain_json.py and scripts/prepare_db.py indicate operational tooling for bootstrapping the database and migrating legacy blockchain data.
10. Presentation layer
- The UI is mostly server-rendered templates under app/templates, with dedicated views for dashboard, lookup, blockchain verification, registry listings, issuance, voiding, and import wizards.
- app/static/js includes small client-side helpers such as copying hashes and displaying registry status; the app is not a heavy SPA.
- This presentation layer sits on top of the route/service layers and does not appear to own domain logic.
11. Verification and registry views
- app/routes/blockchain_verify.py, verification.py, lookup.py, certificate_registry.py, and cpid_registry.py suggest separate screens for audit, verification, and registry browsing.
- These views are likely read-heavy and rely on the same canonical lookup rules as the REST API, but with different user journeys and presentation concerns.
12. Quality and support infrastructure
- Tests cover blockchain behavior, DB maintenance, routes, services, permissions, and visual regressions, which reflects the main architectural seams.
- The docs/ folder documents core subsystems: blockchain audit, database access, imports, UI components, and adding new sacraments.
- Together, the tests and docs reinforce that the system is organized around domain services, not around a single monolithic controller layer.
Main entry points: services Services · db Postgres access · tests Tests · main.py App bootstrap
Components 21
App
Runtime application code
- App bootstrap · Creates the FastAPI app and wires the runtime pieces.
app/main.py - Page routes · Server-rendered page flows for lookup, registry, create, void, and verification.
app/routes - API routes · Sacrament and import endpoints that expose programmatic operations.
app/routers - Services · Core business logic for certificates, imports, identities, persons, and permissions.
app/services - Sacrament model · Canonical registry shapes and shared sacrament data model.
app/models/sacraments.py - Canonical checks · Validates canonical identity and registry data before persistence or issuance.
app/validators/canonical_validator.py - Security · Authentication bridging, permission checks, and guard/middleware enforcement.
app/security - Import flow · Vendor/export validation and mapping into canonical registry records.
app/services/imports_certs.py - Certificates · Creates, voids, and resolves registry certificates and hashes.
app/services/certificate.py - ID generation · Generates stable certificate and record identifiers from canonical fields.
app/services/id_generator.py - Persons · Person lookup and identity handling used by registry flows.
app/services/persons.py
Presentation
Server-rendered pages and static assets
- Templates · Server-rendered pages for dashboard, lookup, registry, issuance, voiding, and import flows.
app/templates - Static assets · Small browser helpers and styles for the rendered UI.
app/static
Data
Persistence, schema, and audit ledger
- Postgres access · Connection, bootstrap, and maintenance boundary for PostgreSQL.
app/db - Schema · Database structure for the multi-sacrament registry.
sql/schema.sql - Migrations · Later schema expansion for the unified sacrament registry.
sql/20240513_multi_sacraments.sql - Ledger · Tamper-evident block layer for issuance, voiding, and verification.
app/blockchain/layer.py - Legacy chain · Compatibility chain used for older blockchain history.
app/blockchain/blockchain.json
Support
Docs, scripts, and tests
Connections 33
- App bootstrap → Page routes: mounts · Registers HTML routes and page flows.
- App bootstrap → API routes: mounts · Registers JSON/API routers.
- App bootstrap → Security: configures · Adds auth and permission enforcement.
- App bootstrap → Templates: renders · Uses server templates for responses.
- App bootstrap → Postgres access: initializes · Starts database connectivity and app lifecycle hooks.
- Page routes → Services: calls · Delegates business logic to service layer.
- API routes → Services: calls · Uses the same service layer for programmatic operations.
- Page routes → Security: guards · Protects user-facing flows with authz checks.
- API routes → Security: guards · Protects API operations with capability checks.
- Services → Sacrament model: uses · Reads the canonical sacrament registry shape.
- Services → Canonical checks: validates · Checks canonical data before record creation or import.
- Services → Certificates: issues · Creates, voids, and resolves certificates.
- Services → Import flow: imports · Runs external certificate import processing.
- Services → ID generation: generates · Derives deterministic identifiers and hashes.
- Services → Persons: resolves · Finds or normalizes person identity data.
- Services → Postgres access: persists · Reads and writes registry state in PostgreSQL.
- Certificates → Ledger: appends · Writes issuance and voiding audit entries.
- Ledger → Legacy chain: compat · Keeps compatibility with historical JSON chain data.
- Postgres access → Schema: defined by · Database runtime follows the SQL schema.
- Postgres access → Migrations: evolved by · Schema changes expand the unified sacrament registry.
- Page routes → Templates: returns · Renders registry, lookup, dashboard, and workflow pages.
- Templates → Static assets: enhanced by · Uses small client-side helpers and styles.
- Ops tools → Postgres access: bootstraps · Prepares and maintains the database environment.
- Ops tools → Ledger: migrates · Converts legacy ledger data into the current store.
- Docs → Services: documents · Explains service boundaries and workflows.
- Docs → Ledger: documents · Explains the audit ledger subsystem.
- Docs → Postgres access: documents · Explains database access and maintenance.
- Tests → Page routes: covers · Verifies route behavior.
- Tests → API routes: covers · Verifies API behavior.
- Tests → Services: covers · Verifies core business logic.
- Tests → Security: covers · Verifies permissions and guards.
- Tests → Ledger: covers · Verifies ledger behavior and validation.
- Tests → Postgres access: covers · Verifies maintenance and database operations.