System Architecture

How fieldmid is built

A six-repo platform that combines PowerSync, Supabase, Mastra, and the PowerSync Rust SDK into an offline-first, AI-powered field incident management system.

Data flow

Incidents flow from the field to the cloud and back through four layers.

Capture
  • Mobile app (Expo)
  • Voice + photo + text
  • OP-SQLite local DB
Sync
  • PowerSync engine
  • 9 Sync Streams
  • SQLite <-> Postgres
AI Review
  • Mastra agents
  • Triage + escalation
  • Compliance + summaries
Monitor
  • Web dashboard
  • Rust edge TUI
  • Realtime + push

Technology integrations

Each partner technology plays a distinct, meaningful role in the platform.

PowerSync

PowerSync

Core requirement

Sync engine that bridges SQLite on every client with PostgreSQL in the cloud.

  • 9 Sync Streams scoped by role — workers see their own incidents, supervisors see their site, admins see everything, and edge devices receive a parameterized critical feed.
  • Mobile app writes incidents to local OP-SQLite; PowerSync reconciles them with Supabase Postgres when connectivity returns.
  • Rust edge daemon uses the PowerSync Rust SDK (pre-alpha) to sync a read-only SQLite on rugged Linux devices with a TUI dashboard.
  • The web dashboard can subscribe to PowerSync for optional real-time reads alongside Supabase Realtime.
Supabase

Supabase

Best Submission Using Supabase

PostgreSQL backend with Auth, Edge Functions, Realtime subscriptions, and Row Level Security.

  • 10 SQL migrations define the full schema: organizations, sites, workers, incidents, escalations, compliance rules, audit reports, notifications, push tokens, and CLI auth sessions.
  • 5 Edge Functions handle signup gating, admin role management, PowerSync write ingestion (with Mastra triage), push notifications, and CLI browser-based auth.
  • Supabase Auth manages email/password and OAuth (Google, GitHub) across web and mobile.
  • Row Level Security enforces per-org, per-role data isolation throughout.
Mastra

Mastra

Best Submission Using Mastra

AI agent framework powering incident triage, escalation workflows, compliance audits, and shift summaries.

  • Triage Agent classifies incidents by severity (LOW through CRITICAL) with risk scoring, critical keyword detection, and tag extraction.
  • Escalation Workflow is a two-step orchestration: prepare an escalation message, then conditionally dispatch to supervisors via email, Slack, or push.
  • Compliance Agent audits incidents against organization rules and generates flagged-pattern reports.
  • Summary Agent produces end-of-shift reports with incident counts, resolution rates, and management-ready narratives.

Local-first principles

FieldMid is designed around the idea that the network is a luxury, not a requirement.

Offline by default

The mobile app writes every incident to local SQLite via OP-SQLite before anything touches the network. Workers can report voice notes, photos, and checklists with zero signal.

Local database as source of truth

PowerSync keeps a full SQLite replica on every device. Queries, reads, and UI rendering all operate on local data — no spinners waiting on the cloud.

Opportunistic sync

When connectivity returns, PowerSync automatically reconciles local changes with Supabase Postgres. Conflict resolution is handled in the background without user intervention.

Instant local reads

The Rust edge daemon, mobile app, and optional web reads all query SQLite directly. Latency is measured in microseconds, not network round-trips.

Resilient operations

Even when cloud services are unreachable, workers keep reporting, the edge daemon keeps monitoring, and queued actions sync when the connection stabilizes.

Decentralized agents

Cloud-side Mastra agents process incidents after sync. The system doesn't depend on real-time AI access — it catches up asynchronously when data arrives.

Sync Streams

PowerSync Sync Streams scope what data each client receives. FieldMid defines 9 streams that filter data by user role and device type.

StreamAudienceDescription
worker_selfField workersOwn incidents only
worker_sync_logField workersPersonal sync status and queue depth
worker_siteField workersAssigned site metadata
supervisor_siteSupervisorsAll incidents and escalations for supervised sites
admin_overviewAdmins30-day incident feed across the entire organization
edge_critical_feedEdge devicesCritical incidents parameterized by site_id (used by Rust daemon)
user_profile_selfAll usersCurrent user profile, role, and membership
user_join_requestsAll usersOrganization membership requests
user_notificationsAll usersIn-app and push notification payloads

Repositories

FieldMid is split across six repositories, each with a focused responsibility.

mobile-app-repo

private

Expo + React Native + PowerSync + OP-SQLite

Offline-first field incident reporting with voice, photo, and checklist capture

core-repo

private

Next.js 16 + Supabase Realtime + Mastra client

Role-based web dashboard for admins, supervisors, and workers

supabase-repo

private

PostgreSQL + Edge Functions + PowerSync config

Database schema, 5 Edge Functions, 9 Sync Stream definitions

mastra-agents-repo

private

Mastra + Cerebras (llama3.1-8b)

4 AI agents and an escalation workflow for triage, compliance, and summaries

rust-edge-repo

private

Rust + PowerSync Rust SDK + ratatui

Read-only edge daemon with TUI for rugged Linux devices

landing-page-repo

public

Next.js 16 + shadcn/ui + Motion

Marketing site, platform guide, and this architecture page

Try the platform

Sign up as a field worker or create an organization workspace to see the full flow — from offline incident capture to AI-powered supervisor dashboards.