Intelligent Legal Correspondence
Universidad Nacional de Colombia · 2026 - At present
A directorate of the university signs resolutions, travel allowances and commissions that arrive by email from every department on campus. This application turns that inbox into a traceable workflow: an agent ingests the mail, an AI summarizes and classifies it, the review team assigns it, whoever holds the signature decides, and the approved document comes back signed, archived and delivered to whoever asked for it.
Architecture and Tech Stack
Core Architecture
- Framework: Next.js 16 (App Router), React 19, TypeScript
- Database and auth: Supabase, with private document storage
- AI: Vercel AI SDK over a Mistral model
- Documents: PDF text extraction with an OCR fallback, plus server-side stamping of the signature onto the rendered page
- Google: Gmail API for intake and Drive API for archiving, each with its own scoped credentials
- UI: shadcn/ui + Tailwind CSS 4, always in Spanish through a label map
- Tests: Vitest over the signing, rollback, activity and prompt logic
Layered Architecture
Request Flow
Key Features
Features at a Glance
Automatic Gmail intake
Messages are pulled straight from the institutional mailbox, so nothing has to be forwarded by hand, and PDF or Word attachments are picked up automatically. Word files are converted, and scanned documents fall back to OCR.
Executive summary, topic and suggested action
For each request the AI writes an executive summary, classifies the topic into one of the office's real categories and suggests an action: approve, report or forward. It abstains to "other" when unsure — a wrong confident label costs more than an honest "unclassified".
Sign-off checklist
A heuristic detects which of the required sign-offs a document already carries, reading both the email and the stamps inside the PDF text. A missing sign-off is surfaced as an observation, never as a hard block — the person reviewing decides.
Role-based inbox
One inbox, two views. Whoever signs decides (approve, report, forward or deny with a mandatory reason); the review role adjusts sign-offs and observations, assigns, signs, dispatches and can reopen an already-processed request to correct it — keeping the original note.
Placeable signature
The signature image is loaded, dragged and resized over the rendered PDF page, and stamped server-side. The signed file is archived, the unsigned original is discarded, and the document is emailed to the requester detected from the CC.
Technical Highlights
The classifier was measured, not assumed
The action prompt was rewritten from the team's real corrections and evaluated against a labelled corpus, which turned a subjective "this prompt feels better" into a measurable improvement with no regression on the approve class. Forwarding remains the hard class — deciding which department a document should go to depends on routing knowledge the text simply doesn't contain.
The signature is never stored
It is loaded in the browser, kept in memory, and sent only at the moment of signing. There is no signature file on the server and no signature column in the database — nothing to leak if either is ever compromised.
Access is closed by construction
Sign-in is restricted to institutional accounts, and every restriction is re-validated server-side — a client-side-only check is not a check. Signing in is not enough either: an account has to be provisioned in advance. Authorization is enforced at the data layer as well as in the application, so a privileged operation is verified on every path that can reach it.
An email corpus that keeps improving the model
A labelled corpus pairs the classifier's own output with the correction a human actually made. That is what makes it possible to measure a prompt change instead of guessing at it.
English code, Spanish domain
Tables, columns and identifiers are in English, while the state machine keeps the domain's own Spanish terms and the UI is always Spanish through a single label map. Nobody hardcodes a label, and nobody has to translate a status in their head.
Impact and Scalability
- Intake, review, drafting, signature and delivery live in one flow instead of scattered mailboxes and shared folders.
- An event log keeps an audit trail of who did what and when.
- Classification quality is measurable against a labelled corpus, so the next prompt change can be proven rather than argued.
Notes
Built with Next.js 16, Supabase, the Vercel AI SDK over Mistral, the Gmail and Drive APIs, pdf-lib and shadcn/ui. The repository is private — it belongs to the Centro de Prototipado at the National University of Colombia.