Architecting the Vancouver Transparency Agent: Rust Orchestration & Serverless Edge Dashboards
Architectural Context & The Problem
Municipal transparency is the cornerstone of civic trust. However, programmatically extracting public meeting minutes, legislative agendas, and official city council decisions presents a host of engineering challenges. Most municipal portals are built on legacy Single Page Applications (SPAs) or dynamically generated layouts that rely heavily on client-side JavaScript execution.
Initially, our team architected the Vancouver Transparency Agent (VTA) using a Python-based orchestrator coupled with Playwright for headless browser automation. While functional, this setup quickly exposed critical production bottlenecks. Headless browser automation is notoriously fragile, prone to timing glitches, and exhibits a massive memory footprint. Running multiple Playwright instances inside low-resource containers frequently caused out-of-memory (OOM) crashes and led to non-deterministic execution behaviors.
To achieve the deterministic speed and reliability required for a continuous civic audit system, we initiated a complete rewrite. We migrated the core orchestrator from Python to a compiled Rust agent (vta-core). By decoupling dynamic DOM rendering and offloading complex web scraping to a dedicated local endpoint, we reduced memory consumption by over 90% and established a deterministic, asynchronous runtime suited for long-term agent execution.
Alternative Approaches Considered
During the design phase of the new architecture, we evaluated several technologies to handle dynamic browser scraping and database persistence.
First, for headless scraping, we considered embedding standard Puppeteer or Playwright bindings directly into the Rust agent using crates like playwright-rust. We rejected this approach. Native browser bindings introduce heavy Node.js or dynamic library dependencies into the compiled Rust binary, defeating the purpose of a lightweight, containerized agent core.
Instead, we opted to route all browser automation through a local Firecrawl Model Context Protocol (MCP) server. Firecrawl operates as an isolated microservice, executing JavaScript rendering and returning clean Markdown payloads. Connecting to the local Firecrawl server over Server-Sent Events (SSE) allows us to cleanly bypass Windows-specific named pipe exhaustion issues during local development while maintaining process isolation. If a browser context crashes inside Firecrawl, the main Rust agent remains completely unaffected.
For data persistence, we evaluated using the official Google Cloud Firestore SDK. Firebase/Firestore SDKs are heavyweight, pull in massive dependency trees, and occasionally lag behind standard language features. Because the vta-core agent only requires stateless document creation and queries, we rejected the SDK. We opted to execute raw HTTP requests directly against the Firestore REST API using the reqwest client and serde_json for serialization. This keeps our dependency footprint minimal, simplifies compilation, and ensures maximum execution speed.
System Deep-Dive: Rust Agent & Edge Frontend
The VTA system is partitioned into two main components: the vta-core orchestrator agent and the vta-web Next.js frontend dashboard.
#### The vta-core Rust Agent
The backend agent is built on the asynchronous tokio runtime, coordinating scheduled transparency crawls using tokio-cron-scheduler. Its pipeline follows a strict, sequential data flow:
- Scouting (Firecrawl MCP): The scout module connects to the local Firecrawl microservice. It sends target Municipal SPA URLs, crawls dynamic agenda lists, and streams back cleaned markdown payloads.
- Analysis (Gemini API): To analyze the meeting records without running into token limits or JSON truncation, we implement two-stage sequential batching. First, we extract high-level meeting metadata from the main portal. Then, the agent deep-scrapes and analyzes each meeting sequentially in a single-request loop using
gemini-3.1-flash-lite. The model rates the civic impact and extracts key highlights. - Persistence (Firestore REST): Analysis results are serialized into structured Rust types via
serdeand pushed to Google Cloud Firestore via direct HTTP POST requests.
#### The vta-web Next.js Frontend
The user-facing dashboard is designed to run on the Cloudflare Workers Edge Runtime using the OpenNext adapter. Because the edge environment lacks filesystem access and native Node.js cryptographic libraries, we built a zero-dependency Edge Authentication Flow in lib/gcp-auth.ts:
- PEM to DER Translation: We read the GCP service account credentials from environment variables, sanitizing the PEM private key block, and convert it to a binary DER format in-memory.
- RS256 JWT Generation: Using the native Web Crypto API (
crypto.subtle.importKeyandcrypto.subtle.sign), we construct and sign a JSON Web Token assertion scoped to the Datastore API. - OAuth2 Token Exchange: The frontend performs an HTTP POST fetch to Google's token endpoint to trade the signed JWT for a short-lived Bearer access token.
- Caching Manifold: The token is cached in-memory with a 3,500-second expiration buffer, preventing redundant authentication calls on subsequent page loads.
Data is fetched directly from Firestore REST endpoints using this token and server-side rendered (SSR) into a print-newspaper styled layout. To maintain an objective, journalistic standard, we completely eradicated subjective alert and severity indicators, separating high-impact items into a prominent "Features" section while routine items aggregate under "Local In Brief."
Lessons Learned & Edge Cases
Developing and deploying a cross-platform system like VTA yielded critical engineering insights.
One major hurdle was managing a dual-environment runtime. During local development, the agent ran on a Windows host using Docker Desktop, whereas production target deployment occurred on a remote Linux server. Windows Docker environments handle network loops and file mounts differently than native Linux. For example, named pipe communication between the Rust core and the local Firecrawl server often triggered descriptor exhaustion on Windows. We resolved this by routing all communication strictly over standard TCP loopbacks (127.0.0.1:8080) and using Server-Sent Events (SSE).
Another constraint was managing memory during PDF processing. Municipalities frequently attach massive agenda files to SPA portals. To parse these, vta-core stream-downloads attached PDFs and extracts text in-memory. To prevent memory leaks or container crashes on low-resource nodes, we instituted a 20MB Size Gate. When downloading, the stream enforces a strict byte-limit check. If a PDF exceeds 20MB, the download aborts immediately, and the system falls back to page markdown scraping. This guarantees that the agent stays well within its 8GB RAM boundary, maintaining 100% operational uptime.