
Summary
Key points of this document
- 1. Background: Why Consolidate into a Single Platform
- 2. Core Architecture (Local-First + Minimal Go Backend)
- 3. Unified Domains & Large-Scale Public Data
Overview
When municipal business platforms, commercial business platforms, AI, public data, statutory calculation engines, infrastructure, and operations tooling live across separate repositories, cross-repo synchronization and maintenance costs quickly escalate.
This document outlines the architecture for consolidating these systems into one Local-First unified monorepo and application. By pairing an in-browser execution layer (SolidJS 2 + Web Worker + SQLite Wasm on OPFS + Rust Wasm) for zero-latency UI with a minimal Go backend (sync-api via ConnectRPC) dedicated strictly to eight core platform responsibilities and server-authoritative operations, both municipalities and businesses can operate on a single, reliable foundation.
1. Background: Why Consolidate into a Single Platform
Challenges of Fragmented Repositories and Build Tooling
Previously, municipal systems (Go + React Router + PostgreSQL + Bazel), business systems (numerous Cloudflare Workers + D1 + React), and supporting domains (AI, data, statutory rules, standards, infrastructure, admin) were split across separate repositories. Distributing shared rules and maintaining Bazel pipelines created substantial operational overhead.
In the new design, Bazel is retired in favor of pnpm workspaces (TypeScript) + Cargo workspace (Rust) + Go modules (Go) orchestrated by a thin justfile and mise.toml, uniting municipal and commercial workloads on one codebase.
| Comparison | Legacy Architecture (Multi-Repo) | Unified Platform (Single Monorepo) |
|---|---|---|
| Repositories | Split across business, AI, data, law, infra, and admin | Consolidated into one monorepo (legacy repos archived Read-Only after cutover) |
| Frontend | React Router / React across multiple builds | SolidJS 2 + Tailwind CSS v4 + Ark UI + TanStack Table (React fully retired) |
| Execution Model | Server-First cloud API calls on every interaction | Local-First (OPFS SQLite Wasm + Rust Wasm) for 60–120fps zero-latency UI |
| Backend | Large Go monolith + dozens of Cloudflare Workers | Minimal Go sync-api (8 core responsibilities + server authority only) |
| Build & Tooling | Bazel + BuildBuddy | justfile + mise.toml + native language toolchains |
| Tenant Control | Separate apps and per-tenant implementations | Single platform + PostgreSQL RLS + Feature Toggles |
2. Core Architecture (Local-First + Minimal Go Backend)
The core principle is strict separation of concerns: computation, search, and document generation run inside the browser (Web Worker + SQLite Wasm + Rust Wasm), while the Go sync-api handles authentication, differential sync, server authority, key issuance, and external proxying.
Frontend Modernization & 120fps Motion Standard
- SolidJS 2: Fine-grained reactivity without virtual DOM overhead maintains 60–120fps even on large tables (with SolidJS 1.9.x as a defined fallback if the Phase 1 PoC gate detects ecosystem incompatibility).
- Tailwind CSS v4 + Ark UI + @tanstack/solid-table: Zero-runtime styling, state-machine-driven accessible inputs (Japanese era DatePicker,
tabular-numscurrency fields, Splitter panes), and virtual scrolling for thousands of records. - 120fps Motion Standard: Strictly SVG icons via Lucide Solid (zero emojis), GPU-composited transitions (
transform/opacity), View Transitions API, Sync Pulse status indicators, and aCmd+Kcross-domain command palette.
In-Browser Storage & Multi-Tab Concurrency
- SQLite Wasm (
opfs-sahpool+ FTS5trigram): Sub-50ms local full-text search across tens of thousands of records. Prioritizesopfs-sahpool(single-thread Dedicated Worker, no COOP/COEP orSharedArrayBufferrequired). - Physical Tenant Isolation: One SQLite file per tenant (
/opfs/tenant_{tenant_id}.db), withclear_local_db_on_logoutwiping OPFS data on shared terminals. - Web Locks API + BroadcastChannel:
navigator.locks.requestelects a single leader tab owning the Web Worker; follower tabs proxy RPCs overBroadcastChanneland seamlessly take over if the leader closes.
Rust Wasm vs. Go sync-api Split
| Workload | Runtime | Examples | Rationale |
|---|---|---|---|
| Pure Calculation & Rules | Rust core-engine | Payroll/tax/social-insurance math (integer-only, no float), property matching, approval routing, SEO/AIO scoring | Zero network latency and zero server compute load |
| Local Search & Analytics | SQLite Wasm + core-engine | Document search, ledger cross-tabs, cash-flow forecasting, demographic mesh aggregation | Full tenant dataset is local; executes in milliseconds |
| Document Generation | Rust doc-engine (Lazy) | Approval PDFs, invoices, payslips, Zengin banking files, Excel/CSV, barcodes/QR | Eliminates heavy server-side PDF rendering containers |
| Auth, RLS & Server Authority | Go sync-api (ConnectRPC) | Go Auth (Argon2id / Passkey / OIDC / __Host- Cookie), diff sync, document numbering, approval locks, reservation slot holds, monthly closing, disbursement Saga, R2 presigned URLs, SaaS proxy | Guarantees atomicity across devices, hides secrets, and enforces RLS |
Sync Protocol & Three-App Isolation
sync_log.seq&rbac_epoch: Monotonicseqcursor prevents missed commits;rbac_epochtriggers immediate local Tier 2 purge upon permission revocation. Non-retryable Push errors are evicted from Outbox to prevent poison pills.- Three Sync Tiers: Tier 1 (full sync for masters/active work), Tier 2 (RBAC & recency-scoped sensitive/historical data), Tier 3 (server-only: credentials, audit logs, >3-year archives, R2 binaries).
- R2 Two-Phase Commit: Short-lived PUT presigned URL ->
ConfirmUploadwith Go-sideHeadObjectverification -> periodic GC for orphanedpendingobjects. - Three Separate Apps:
apps/web(Staff, Local-First),apps/public(Citizens/Customers, lightweight Server-First without OPFS/COOP-COEP), andapps/admin(Platform Ops, isolated domain with MFA + Cloudflare Access).
3. Unified Domains & Large-Scale Public Data
| Domain | Scope & Key Capabilities | Architectural Highlights |
|---|---|---|
1. government-core | Document management, approval workflows, org/staff/RBAC masters | user_org_assignments supports multi-department concurrent posts; numbering & approval locks are server-authoritative |
2. citizen-services | Vacant-house bank + 10 municipal modules (disasters, digital circular, elderly monitoring, health events, sports, attendance, language classes, regional insights, public data, bid qualifications) | Dynamic per-tenant enablement via feature_entitlements; regional insight math runs in Rust core-engine |
3. reservations | Unified phone (Twilio), Web, LINE, and counter bookings + AI voice/chat | HoldReservationSlot enforces held (10-min TTL) -> confirmed under PostgreSQL row locks (zero double-booking) |
4. communications | Ads (Meta/Google/LINE), social scheduling, LINE 1-on-1 chat & rich menus, CMS, SEO/MEO/AIO audits | Prohibited-word checks and SEO/AIO scoring run instantaneously in core-engine |
5. ledger | Unified party master (ledger_parties), employees, deals, purchases, payroll, expenses, reconciliation, monthly closing | Deterministic integer-only Rust math; CloseLedgerMonth server lock blocks writes to closed months |
6. payments | Collections, disbursements, refunds, bank statement matching, Zengin format export | Locks amount/account hash at approval; executes external transfers via Transactional Outbox / Saga |
7. integrations | Google Workspace (SSO/Directory/Calendar/Drive/Gmail), freee, LINE, Twilio, Stripe, GitHub | OAuth tokens encrypted in sync-api (ProxyService); arbitrary URLs blocked to prevent SSRF |
For nationwide public datasets (tens of millions of assembly-minute, tender, and grant chunks), data is collected and ONNX-embedded off-cluster, then queried on demand (Tier 3) via DuckDB (Parquet) + LanceDB on Cloud Run (min_instances=0) reading from same-region GCS.
4. Balancing Safety and Velocity (5 Quality Pillars, Quint/CUE, ETL Cutover)
- Five Quality Pillars: Maintainability (single monorepo + Protobuf contract), Performance (P95 warm start < 1.5s, local FTS5 search < 50ms, INP < 100ms), Security (OPFS isolation + Go Auth + RLS), Reliability (offline recovery + server locks + integer math), and Observability (OpenTelemetry
traceparentsingle Trace ID from@sentry/solidthrough Web Worker/Wasm, Gosync-api, Cloud SQL, and SaaS proxies with strict PII scrubbing). - Targeted Quint & CUE: Quint verifies only mission-critical state machines (diff sync, authority locks, disbursement Saga, tenant isolation), while CUE validates cross-cutting
RBAC × Feature Toggle × Sync Tierpolicies and deployment configs—leaving CRUD and UI validation to native type systems and Property-Based Testing. - Zero-Base Schema + Deterministic ETL Cutover: No dual-write coexistence; a Go ETL CLI deterministically maps legacy IDs to UUIDv7 (via
uuid_v5) and blocks cutover unless record counts, monetary totals, foreign keys, RLS, and R2 object checks pass 100% (Fail-Closed). Legacy repositories are preserved as Read-Only archives.
Summary
Combining in-browser Local-First responsiveness (SolidJS 2 + OPFS SQLite Wasm + Rust Wasm) with a minimal Go sync-api, targeted Quint/CUE formal verification, and deterministic ETL creates a sustainable, unified platform for both municipal and commercial operations.


