Skip to content

An AI agent that writes site reports.This is how it's built.

ReportAI turns what a technician dictates on a building site into their company's own Word report, ready to review and sign. I designed, built and deployed it end to end: the agent, the backend, the field app and the servers.

Built with

  • FastAPIAPI, captures and webhooks
  • LangGraphstateful agent with pauses
  • Pydantic v2schemas and validation
  • PostgreSQL 16data, queue and graph state
  • Claude or another modelextraction, configurable
  • Whispertranscription
  • docxtpl + GotenbergWord to PDF
  • Nuxt 4 + Vue 3panel, field app and this site
  • PWAown service worker, offline queue
  • Docker ComposeTraefik in SaaS, Caddy self-hosted

Who uses it, what goes in, what comes out.

In short. A technician dictates the visit on their phone, even with no signal. ReportAI writes the report in their company's template, someone at the office reviews it, and the client gets the PDF by email.

Sheet
1 / 7
Scale
1:1000
  1. 1Dictate

    The technician records the visit in the app. With no signal, it waits on the phone and uploads on its own.

  2. 2Fill in

    The audio becomes text and a model fills the template's fields, each with the sentence it comes from.

  3. 3Review

    Whatever is missing is flagged. A person completes it and approves.

  4. 4Deliver

    The PDF comes out in the company's own Word template, to the configured recipients.

Detail

Two ways to install it, one codebase

Hosted
Multi-tenant, on my server.
On the client's server
One company, installed with one command and a setup wizard.

One variable, SINGLE_TENANT, picks the mode. The same code and the same tests serve both.

What runs on the server and what leaves it.

In short. The same containers in both modes. Only four outside services receive report data: transcription, the model, outgoing email and the connected chats.

Sheet
2 / 7
Scale
1:100

ReportAI's server · Hetzner · Docker Compose

Click any piece to see what it does.

From audio to report, inside.

In short. What you dictate goes through five stages to become a PDF, and a person approves it before it goes out.

Inside, a 25-node LangGraph graph. Pick a stage to see what it does, with what, and what leaves the server.

Sheet 3 / 7 · Scale 1:10

Dictate

Stage 1 of 5

You record the visit in the phone app, with photos if you like. With no signal, it waits on the phone and uploads on its own.

  • The app makes the report's id before uploading and sends it as the Idempotency-Key: a retry returns the same report, never two.
  • The report and its queued job are created in one Postgres transaction: both exist or neither does.
  • Telegram and email come in the same way, deduplicated by each message's id.

Design decision

A queue in Postgres, no Redis, no broker: one less piece to run on each client's server. Jobs are claimed with FOR UPDATE SKIP LOCKED and a lease; if the worker dies, another one picks the job up.

input · app → POST /capture → backend

1:19

queued job

kind: runstatus: queuedattempts: 0/3

↳ one transaction: report + job

What leaves the serverThe recording travels from the phone to the server. Nothing else.

Click a stage or use the arrow keys.

Many companies, one codebase.

In short. Each company sees only its own, has a ceiling on what it can spend, and can take its data away or delete it. And the same code installs, with a single company, on a client's server.

Sheet
4 / 7
Scale
1:10
Isolation in code, tested route by route
Every route takes the company from the signed-in user, never from the request, and loads rows through one helper that filters by it. Another company's report answers 404, not 403: a 403 would confirm the id exists. A test walks the OpenAPI with two companies, tries all 31 routes with an id, and fails if a new route shows up unclassified.
Quotas and capped spend
The quota is a count(*) over the period's reports. Every plan has a daily AI spend cap, and the platform a global breaker. Every model call records its cost and tokens.
The data belongs to the company
A full export as a zip. After a deletion request there are 30 days of grace; then it is deleted in order (graph state, files, rows), so a crash halfway leaves nothing orphaned. Audio retention is configurable.
Everyone, their own access
Three office roles (admin, approver and viewer) and the technician, who only sees their own. Technicians sign in with a magic link or an 8-character code, because the app installed on an iPhone doesn't share its session with Safari, and stay signed in for 30 days with no password.
backend/app/core/scoping.py
async def get_scoped_or_404(repo, id_, *, tenant_id):
    obj = await repo.get_by_id(id_)
    if obj is None or obj.tenant_id != tenant_id:
        raise ResourceNotFoundException()
    return obj

Isolation matrix

31 routes with an id, requested by another company's admin: 31 answers of 404 and nothing changed. As a technician, 403 or 404: never a 2xx.

Design decision

Isolation in code rather than Postgres RLS, for now: one place to review and one test that covers it all. RLS comes with the first company that asks for it.

Recording where there's no signal.

In short. On a building site, signal comes and goes. The app records anyway, keeps the visit on the phone and uploads it on its own when the signal is back, never twice even when it retries.

Sheet
5 / 7
Scale
1:10
  1. 1Records

    Opus at 32 kbps (AAC on iPhone; about 240 KB a minute), with the screen kept on by Wake Lock while it records.

  2. 2Waits on the phone

    Each capture goes to IndexedDB, tied to the session token's user rather than the profile in memory: on a shared tablet, one person's capture never uploads as someone else's.

  3. 3Uploads on its own

    When the network is back, the queue drains with a timeout sized to each upload. The report's id travels as the Idempotency-Key: a retry returns the same report.

  4. 4Opens offline

    A hand-written service worker (83 lines) keeps the app's shell. On one bar of signal, the page waits at most 4 seconds for the network, and each start-up API call 3; then the app opens with what it saved.

The same app serves a Content-Security-Policy with a fresh nonce on every page from Nuxt's own server, identical in SaaS and self-hosted. A smoke test in CI starts the built server and checks it.

Design decision

A hand-written service worker rather than @vite-pwa/nuxt: the plugin had an open bug that left the manifest at 404 with our preset, and it put Workbox in the build. What we needed was under a hundred lines.

How I know it works.

In short. “The model is usually right” isn't enough for me. Every change goes through tests, types and CI; extraction through a golden set; and major changes through an independent review.

Sheet
6 / 7
Scale
1:1
backend tests
899
pytest against a real Postgres, on every push
frontend tests
81
plus a smoke test of the built server and the whole flow in a browser
invented details in the golden set
0
83 cases: Claude, 99.7% of fields right; OpenAI, 97.5%
Lighthouse accessibility
100
mobile, production build
of AI per report
≈ 0.03 USD
the sample report: 0.028 USD of extraction with Claude Sonnet 5, plus transcription

Every evaluation published, with its commit, its model and what it cost

How I build it

  1. 1 · Me

    Specify

    Requirements, architecture and each task's contract: scope, interfaces and the tests it must pass.

  2. 2 · AI agents

    Implement

    Each on its own branch, with its tests.

  3. 3 · Me and an independent review

    Review

    I read every diff. Major changes also go through a review that doesn't know my reasoning.

  4. 4 · CI

    Prove

    Lint, types, migrations against the models, tests, the whole flow in a browser, the image build and a CSP smoke test.

AI writes much of the code. I answer for every line.

Incident: the public demo let bursts through

The landing's demo is anonymous and every try spends AI, so it allows 3 tries per visitor and a daily ceiling.

Found
An independent review saw that the limit was checked at the start of the request and recorded at the end, with several queries in between.
Reproduced
With a test: 20 simultaneous requests from one IP, 20 accepted.
Cause
Checking and recording were two steps, and every request saw the counter at zero.
Fix
One step under a Postgres lock (pg_advisory_xact_lock): each request counts once the previous one has recorded. Plus a daily AI budget of its own.
Result
The same test: exactly 3 accepted, in 6 out of 6 runs.
Twenty simultaneous requests against a limit of 3

Before

20 of 20 accepted

After

3 of 20 accepted

Other things caught before production

  • Independent review

    A proof-of-concept XSS that went through the CSP itself: the nonce was signed with a regular expression that also signed “<script” inside an attribute. Now a tag-aware scanner signs it.

  • Independent review

    On a shared tablet, one technician's recording could upload under another's session. The queue is now tied to the token's user.

  • End-to-end test

    A voice note sent along with text was silently dropped, on every channel. Now it is transcribed and added to the text.

Revision table.

In short. The decisions that shape the system, with what they cost. Each one has a serious alternative that was turned down on purpose.

Sheet
7 / 7
Scale
NTS
  1. 11 Aug 2026

    A LangGraph graph, not a single model call

    Why
    The flow has state and pauses: it waits for a person, asks for what's missing, retries and survives a restart.
    Turned down, and its cost
    A chain of calls: every pause would be hand-written code and a restart would lose the report.
  2. 1 Oct 2026

    The job queue, in Postgres

    Why
    Postgres is already there; every extra piece is operations on a client's server.
    Turned down, and its cost
    Redis with Celery: more throughput than needed and one more piece to watch.
  3. 1 Oct 2026

    Blank rather than invented

    Why
    In a document someone signs, a plausible date nobody said is worse than a gap.
    Turned down, and its cost
    Letting the model fill in: more fields filled, some of them false.
  4. 6 Nov 2026

    One codebase for SaaS and self-hosting

    Why
    One test suite; one variable picks the mode.
    Turned down, and its cost
    Two products: twice the maintenance.
  5. 6 Nov 2026

    Isolation in code, with a test matrix

    Why
    One place to review and a test that fails if a route is left out.
    Turned down, and its cost
    RLS from day one: more defence in depth, with no client asking for it yet.
  6. 6 Nov 2026

    The app (PWA) as the main channel

    Why
    No dependence on Meta or Telegram, frictionless sign-up and review in a form.
    Turned down, and its cost
    A shared Telegram or WhatsApp bot: every company would depend on someone else's account.
  7. 6 Nov 2026

    Magic link and an 8-character code

    Why
    No passwords on site; the code because the app installed on an iPhone doesn't share its session with Safari.
    Turned down, and its cost
    Email and password.
  8. 8 Nov 2026

    A hand-written service worker

    Why
    Under a hundred lines that do exactly what is needed.
    Turned down, and its cost
    @vite-pwa/nuxt: a 404 manifest with our preset, and Workbox in the build.
  9. 9 Nov 2026

    The demo's limits, in one step under a lock

    Why
    A burst gets the same tries as someone clicking one at a time.
    Turned down, and its cost
    The login limiter's “may overshoot by a few”: here a burst got 20 tries through against a limit of 3.
  10. 18 Nov 2026

    Personal keys for the MCP server, not company ones

    Why
    A key acts as its person through the panel's own checks: an assistant never sees or does more than they can, and nothing is approved or sent from the AI.
    Turned down, and its cost
    One key per company: a technician's assistant would see everyone's reports.
  11. 25 Nov 2026

    Our own OAuth 2.1 for the MCP server, with CIMD

    Why
    claude.ai and ChatGPT connect without copying keys; each token is good for this server only, rotates and dies with its person's account.
    Turned down, and its cost
    An external identity provider (WorkOS, Auth0): one more data processor, and self-host can't depend on it.

What it doesn't do yet

  • It doesn't charge: the plans and their quotas exist, but there are no payments.
  • It doesn't run the site's follow-up cycle (findings, actions and checking them at the next visit).
  • It speaks Spanish and English.
  • Recording with the screen locked is tested on Android, not on iPhone.
  • It isolates in code; no Postgres RLS yet.

If you need someone to take AI to production, let's talk.

ReportAI is one of my projects. The others, my experience and how I work are on my portfolio.

or write to adrian@vazquezdev.pro