SYSTEM ARCHITECTURE · TECHNICAL SPECIFICATION
Architecture & Pipeline
An automated, verifiable intelligence record for Ethiopian federal regulatory enactments. Designed as a batch-shaped pipeline with static-first delivery, immutable content-addressed blob storage, and adversarial verification gates.
Ingestion & Acquisition
- Python CLI batch worker (
erl crawl) - Per-source adapters: MoJ, NBE, MoR, CMA
- Sitemap discovery ladders over dynamic forms
- Custom TLS bundle completion (
mor.gov.et)
State & Synthesis Engine
- Cloudflare R2: Immutable raw blobs (
content_hash) - PostgreSQL 16: Transaction savepoints & invariant constraints
- Change Engine:
normalized_hashsilent-edit detection - Gemini 3.5 Flash Lite: Summaries, kind, & significance
Static Build & Delivery
- Contract JSON export (
erl export) - Next.js static build (
output: "export") - Edge CDN asset distribution (0ms request compute)
- Private Admin on Unix socket + Tailscale VPN
1. System Constraints
The system architecture is governed by four non-negotiable operational constraints. Every design decision originates from these rules:
Constraint A: One-Operator Maintenance
One part-time person operates this system. The design aggressively favors fewer moving parts, minimal dependencies, and a modular monolith over distributed microservice orchestration.
Constraint B: Zero Persistent Database Connections
To operate within serverless quotas and allow Postgres to auto-suspend after 5 minutes of inactivity, the database connection is never held open. There is no connection pool, no polling daemon, and no live database query on user page views. The architecture is strictly batch-shaped: every command connects, executes, commits, and exits.
Constraint C: Provenance or It Does Not Ship
The platform refuses to publish any regulatory entry that lacks verifiable, traceable provenance. If neither the source nor the document text provides a verified official identity and raw document hash, publication is blocked.
Constraint D: Static-First Public Delivery
The public website is rendered to static HTML at build time (output: "export"). There are no server-side request handlers, no runtime database queries, and no client-side data fetching. This eliminates attack vectors, guarantees instant edge delivery, and ensures complete indexability for search raters and AI crawlers without requiring JavaScript execution.
2. Ingestion & Silent-Edit Detection
Government websites frequently publish legal updates without RSS feeds, stable APIs, or consistent change notices. Ingestion is handled by dedicated Python source adapters implementing a strict discover(), fetch(), and parse() interface:
- Ministry of Justice (MoJ): Bypasses dynamic JavaScript filter forms that fail with Cloudflare 524 timeouts by traversing structured XML sitemap ladders.
- National Bank of Ethiopia (NBE): Crawls open-directory document structures with blocklist filtering to ignore plugin and theme assets.
- Ministry of Revenues (MoR): Bypasses missing intermediate TLS certificates using a pinned custom CA authority bundle (
deploy/tls/mor.gov.et.pem). - Capital Market Authority (CMA): Captures both enacted directives and advance consultation drafts.
The Two-Hash Verification Model
A core capability of the library is detecting when a government entity silently modifies an existing regulation after publication. Relying solely on raw file bytes creates intolerable false positives: PDF generators alter /CreationDate and /ID tokens upon re-export, and web portals rotate dynamic nonces and footer timestamps.
The engine solves this by decoupling raw storage from semantic change detection using two distinct SHA-256 hashes:
content_hash
Computed directly from the raw incoming bytes of the downloaded artifact (PDF or HTML).
- Stored immutably in Cloudflare R2 object storage
- Never overwritten or mutated
- Provides cryptographic provenance for dispute resolution
normalized_hash
Computed from extracted document text after aggressive canonicalization.
- Collapses all whitespace into single spaces
- Applies Unicode NFC normalization and strips zero-width chars
- Eliminates boilerplate navigation, nonces, and rotating footers
- Fires a silent edit alert only when regulatory text changes
3. AI & Verification Pipeline
Raw regulatory documents are ingested, classified, and synthesized through an automated pipeline powered by gemini-3.5-flash-lite:
- Cost-Capped High Throughput: Model selection provides high request quotas, 5–8 second latency per legal document, and robust Amharic-to-English legal comprehension without hitting tight rate limits.
- Structured Extraction: The model generates a concise 2–4 sentence executive summary (
gist), classifies the instrument type (proclamation, directive, amendment, process change, or enforcement), and rates market significance. - Relational Invariant Gates: Before publication,
erl checkexecutes database-level integrity assertions. PostgreSQL constraints enforce foreign key integrity and audit logging (recording automated reviewer attribution asauto/gemini-3.5-flash-lite). - Tiered Publication: Distinguishes Tier-1 document pointers (verbatim official text and raw links) from Tier-2 reviewed entries (carrying AI synthesis). All AI-interpreted entries prominently display fallibility notices requiring readers to verify against the primary document.
4. Infrastructure & Security
The physical architecture isolates administrative operations from public readers:
| Component | Technology | Network & Security Boundary |
|---|---|---|
| Cron Worker | Python 3.11 CLI (uv) | Runs scheduled batch runs on Railway worker; short-lived outbound connections. |
| Relational State | PostgreSQL 16 | Isolated private network; accessible only by worker and admin socket. |
| Blob Storage | Cloudflare R2 | Content-addressed storage; public bucket policies restrict unreviewed artifacts. |
| Public Web | Next.js 16 (Static Export) | 100% static assets on Edge CDN. No DB credentials, no dynamic APIs, zero attack surface. |
| Admin Console | Unix Domain Socket | Zero public web route. Accessible exclusively via private Tailscale VPN (admin.tailnet). |
5. How It Was Built
The Ethiopian Regulation Library was designed and built using a spec-first, multi-agent autonomous development workflow.
Multi-Agent Roster & Markdown State Management
Rather than relying on conversational chat or single-prompt generation, the system was built by decomposing engineering responsibilities across dedicated autonomous subagents:
supervisor: Milestone planning, documentation tracking, and dispatching.planner: Technical approach formulations and recording rejected alternatives.researcher: Empirical verification of live government endpoints and network behaviors.coder: Implementation of Python adapters, SQL migrations, and frontend components.adversary: Dedicated agent attacking the coder's output—actively searching for false citations, silent failure modes, and schema integrity leaks without self-rationalizing bugs.tester: Golden-file snapshot corpora and live contract test suites.
Persistent Markdown State Management
Agent amnesia between sessions was solved by maintaining structured markdown state files as the external memory bank:
plan/: 10-part foundational planning package (PRD, crawler architecture, database schema, security).Architecture.md: Build-phase decisions, rationales, and rejected alternatives.learnings.md: Hard-won empirical facts (e.g. L-5 sitemap discovery, L-7 normalized hash, L-11 database savepoints).progress.md: Chronological session log and verification proofs.Blockers.md: Explicit blocker tracking and resolution criteria.
Verification Notice: This architecture document reflects the active production configuration of mnaddis.com. For source coverage statistics, consult the Coverage page. To report discrepancies, visit Corrections.