About the Project

Justinian organized Roman law into one unified body called the Corpus Juris Civilis. His loyal general Belisarius reunified the empire under it. Corpus does the same for US law — and dispatches Belisarius, our AI agent, to unite American law into one searchable platform.

Soon to be live at corpuslaw.us

Inspiration

Corpus didn't start as a hackathon project. It started with a law being weaponized against me.

The City of Philadelphia, Mississippi, misapplied a municipal ordinance and used it to arrest my mother—all over my dog breaking off its leash. An issue that should have never escalated resulted in a citizen being taken into custody over a minor infraction.

When I went online to find the actual text of the law they cited, I couldn’t find it. Not on any website. Not in any database. Not anywhere. Like hundreds of small municipalities across the country, Philadelphia had never digitized its municipal code.

The law was real enough to enforce against a citizen. But it was not real enough to read.

That asymmetry—enforceable but unreadable—is the thing I could not stop thinking about. So I decided to fix it.

The obstruction

I filed a public-records request under the Mississippi Public Records Act (Miss. Code Ann. § 25-61), which guarantees the right to inspect public records without paying a fee. I told them I wanted to build an app with the data and asked, over and over, to inspect the municipal records without paying.

So I filed a public-records request under the Mississippi Public Records Act (Miss. Code Ann. § 25-61), which guarantees the right to inspect public records without paying a fee. The city's response was to obstruct: they improperly combined three separate records requests into a single $1,675 fee estimate and refused to itemize it. They demanded payment for inspection that state law explicitly provides for free. I filed an Ethics Commission complaint (Case No. R-25-060). The clock kept running — 7 working days to respond became 240+ days of silence.

After more than 240 days, I refiled the request and told them the application was about to be made. This time, they allowed me to inspect the physical code book — but only partially. The rest of the request remains unfulfilled.

I photographed every page I could see. Then I built an OCR pipeline to turn those photographs into searchable text. That pipeline became Corpus, and the idea has grown ever since.

What I Learned

The law is only as accessible as its least-digitized jurisdiction. Federal and state codes are well-served by existing tools. But municipal law — the ordinances that actually govern daily life: zoning, noise, animals, parking, curfews — is a digital desert. Small towns either can't afford codifier contracts (CivicPlus/Municode charges municipalities thousands per year) or simply never digitized their code books at all. A citizen can be charged under an ordinance they have no way of reading.

FOIA is not self-enforcing. Mississippi law gives public bodies 7 working days to respond to records requests and explicitly guarantees the right to inspect without paying a fee. In practice, a city can simply ignore the deadline, inflate fee estimates to make access prohibitive, or improperly bundle requests to discourage follow-through. Without public accountability infrastructure — a scoreboard that counts every day of non-compliance — the statute is a paper tiger.

Vision models can reconstruct physical law books. Photographing a code book produces messy, overlapping, out-of-order images. I learned that multi-image page reconstruction — sending all photos of one physical page to a vision model in a single call so the photos correct each other — produces dramatically better transcription than processing each photo independently. The Qwen3-VL models running locally on my M4 Max Mac Studio turned 641 photographs into 197 reconstructed pages of faithful, verbatim legal text.

How I Built It

Corpus is built as a monorepo with four major subsystems:

1. The Corpus (legal text platform)

  • Database: PostgreSQL with pgvector (HNSW index), ltree for hierarchical code structure, and pg_trgm for fuzzy text search. One store handles hierarchy + semantic + keyword search.
  • Ingestion: A single HMAC-signed webhook accepts parsed law nodes from any source. Federal law comes from GovInfo USLM XML and the eCFR API. Mississippi state law is mirrored from official sources. Municipal codes arrive through three tiers: (Tier I) direct harvest of official public-domain pages, (Tier II) clerk-verified outreach, and (Tier III) filed public-records requests.
  • Search: Hybrid retrieval — vector (voyage-law-2 embeddings, legal-domain tuned) fused with full-text search via Reciprocal Rank Fusion. Every code section has one canonical, SEO-indexed URL.
  • Frontend: Next.js + Tailwind, server-rendered for SEO, with a plain-language toggle (the "Basilika" act — translating dense legal text into plain English).

2. The Transparency Scoreboard

  • Every filed FOIA request is tracked with its statutory response window (7 working days under § 25-61). The "days overdue" counter is computed live from current_date − due_on — never hardcoded, never unsourced.
  • Each jurisdiction has a public ledger of neutral, structured facts: when a request was filed, when it was acknowledged, when a fee was demanded, when records were released. The agent never writes free-text accusations — only dated, sourced events.
  • When a clerk demands a fee, Stripe payment links are generated for the exact amount, enabling public crowdfunding of FOIA fees.

3. The OCR Pipeline (Philadelphia, MS)

  • 641 photographs of the physical Philadelphia code book were ingested into a batch system (corpus-raw/ocr/ms-philadelphia-book-5/).
  • A page-grouped multi-image reconstruction pipeline sends all overlapping photos of one physical page to a Qwen3-VL vision model in a single call. The model cross-corrects across photos and produces a faithful, verbatim transcription — misspellings preserved and flagged [sic], signatures recorded as /s/ Name, Title or [not signed].
  • A staff-only review UI at /admin/ocr displays the source photo beside the extracted text. A human reviews every page, corrects OCR errors, and locks it. Only locked pages are exported and ingested. The model output is never trusted blindly.
  • 197 reconstructed pages were produced from the 641 photos, running entirely on local hardware (M4 Max Mac Studio, LM Studio, MLX 4-bit quantization).

4. Belisarius (Autonomous Agent)

  • An AI agent that forms real legal entities (LLCs and nonprofit corporations) in Mississippi end-to-end, bridging modern financial rails to legacy government portals that have no API.
  • Earn: The founder pays via a real Stripe Checkout session covering the state filing fee + registered agent fee + Corpus margin.
  • Spend: Stripe Issuing mints a single-use virtual card loaded with the exact state filing fee, merchant-locked to the MS Secretary of State so over-spend is structurally impossible.
  • Operate: An RPA sub-agent files on corp.sos.ms.gov, intercepts and parses the Certificate of Formation PDF, and delivers it with a full audit trail.
  • Two non-bypassable human approval gates front every irreversible step (moving money, submitting to the government). Every action appends to an append-only transparency ledger.

Challenges We Faced

Physical code books are messy. Photographing a bound municipal code book in a clerk's office produces overlapping, out-of-order, sometimes blurry images. EXIF timestamps didn't help — page turns don't show up as clean gaps (cadence was a noisy 2–28 seconds between every shot). The initial per-photo OCR pipeline emitted duplicate and conflicting sections. We solved this by rebuilding around page-grouped multi-image reconstruction: a cheap vision pass detects physical page boundaries, all photos of one page go to the model together, and a human confirms the grouping before transcription.

Fee obstruction as a FOIA barrier. Philadelphia improperly combined three separate records requests into a single $1,675 fee estimate and refused to itemize. Mississippi law explicitly guarantees the right to inspect records without paying a fee, but there's no enforcement mechanism when a city simply ignores that. This is why the transparency scoreboard exists — public pressure with receipts, not legal threats. The fact that Philadelphia eventually began publishing its code after we counted every day of silence is the first proof the method works.

Legacy government portals have no API. The Mississippi Secretary of State's business filing portal (corp.sos.ms.gov) is a web form with no programmatic interface. Belisarius can't just POST a filing — it has to drive the portal like a human would. This required building an RPA layer that navigates the form, submits the filing, and then intercepts the returned Certificate PDF — all behind a human approval gate because filing with the state is irreversible.

Trusting AI with irreversible actions. The core tension of an agent that earns, spends, and operates is: how do you let it act without losing control? Our answer is two non-bypassable human gates — one before any money moves, one before any government submission. The agent can research, draft, and prepare, but a human must approve every irreversible step. The transparency ledger records every action so there's always an audit trail.

What's Next for Corpus

Geographic expansion. Philadelphia, MS is the proof of concept. The same three-tier acquisition strategy — harvest official sites, verify with clerks, file records requests — scales to every municipality in the country. We're starting with Mississippi's 300+ municipalities, then expanding to other states with strong public-records laws.

The FOIA flywheel. Every records request we file, every day of silence we count, every fee estimate we crowdsource — it all feeds back into the transparency scoreboard. As more jurisdictions are tracked, the scoreboard becomes a national civic-transparency index. Cities that comply get credit; cities that obstruct get a public clock.

Belisarius beyond Mississippi. The formation flow is built for Mississippi today, but the architecture is state-agnostic. Each state needs its own PRA rules (response windows, fee posture), its own SOS portal adapter, and its own filing-fee pricing. The framework is designed to extend one state at a time.

A public API and MCP server — already live. The code corpus isn't just searchable through the web app — it's programmatically accessible to any developer or AI agent. The REST API (/api/v1) exposes search, node retrieval, code-body browsing, GIS zoning data, and coverage metrics, all behind API-key auth with credit-based metering via Stripe. The MCP server (/api/mcp) exposes the same data as three tools — search_law, get_law_node, and list_coverage — so any MCP-compatible agent (Claude Desktop, Cursor, Hermes) can search and cite US law directly. The MCP server and REST API share the same underlying library functions, so they can never drift apart. This is the platform play: Corpus is the data layer other agents build on.

The GIS zoning layer (Agrimensor). We're already building the spatial chain: extracting zoning district classifications from code text, matching them to public GIS datasets, and rendering zoning-compliance maps. The goal is a citizen-facing map that shows what you can build on any parcel — powered by the same municipal code we extracted from photographs.

Built With

  • amazon-aurora-rds
  • aws-sdk
  • better-auth
  • dashscope-4-ai/ml-models:-voyage-law-2
  • ecfr
  • geopandas+shapely
  • git
  • github
  • google-oauth
  • govinfo
  • hmac-webhook-4-platforms/tools:-pnpm
  • httpx
  • ionos-vps
  • lm-studio
  • ltree
  • maplibre-gl
  • mcp
  • next.js
  • openai-sdk
  • pg-trgm
  • pgvector
  • psycopg/pg
  • python
  • qwen-vl-max-6-apis/protocols:-stripe
  • qwen3-vl-30b-a3b
  • qwen3-vl-8b
  • react-19
  • react-markdown-5-database-technologies:-postgresql-(aurora)
  • sql
  • sql-12-frameworks/libraries:-next.js-15
  • stripe-sdk
  • tailwind
  • typescript
  • upstash-redis-6-cloud/infra-services:-vercel
  • vitest
Share this project:

Updates