How audit-tools-deca-lab-cornell/audit-tools-playspace-mobile works
1. Product boundary
- This is a native mobile field app for auditors, built with Expo + Expo Router + Tamagui.
- It is intentionally not the manager dashboard product; the mobile scope is assigned-place discovery, audit execution, submitted-audit reporting, and client-side export.
2. Route-driven presentation layer
- The app/ directory is the top-level navigation surface.
- It is split into an auth area (login, signup) and a tab shell (execute, places, reports, settings).
- Deeper flows are route-based too: app/execute/[placeId]/*, app/place/[placeId].tsx, and app/report/[auditId].tsx represent drill-in detail and workflow screens rather than separate app modules.
3. Audit execution as the central workflow
- The most important product path is the Execute flow, which starts or resumes an audit for a place.
- That flow includes pre-audit questions, section-level question answering, quantity-gated follow-up scales, notes, and submission gating.
- The execute screens are backed by shared audit components in components/playspace-audit/, which render question cards and section/question table layouts.
4. Domain logic lives under lib/audit/
- This folder is the main business-logic boundary for audit behavior.
- It contains API clients, sync helpers, scoring helpers, place helpers, selectors, export logic, and execution-flow orchestration.
- The audit subsystem is where the app turns backend audit payloads into a usable editing, scoring, and export experience.
5. Offline-first state architecture
- Audit editing is built around a three-layer model:
- Legend State for live in-session reactive state
- MMKV for durable on-device persistence
- REST API sync as the server source of truth
- Dirty local edits are persisted and later flushed by foreground and background sync code.
- This separation is the core architectural choice of the repo.
6. Persistent stores and state boundaries
- stores/audit-store.ts is the main runtime audit state entrypoint and wraps the reactive audit model with a selector-friendly interface.
- Other app state is split by concern: auth-store, places-store, preferences-store, and notifications-store.
- lib/storage/ contains the low-level MMKV layer and notification cache persistence.
7. Server integration and data contracts
- Backend communication is REST-based and centralized in API modules like lib/audit/api.ts, lib/audit/places-api.ts, lib/audit/dashboard-api.ts, lib/auth/api.ts, and lib/notifications/api.ts.
- Payloads are validated with Zod, especially for audit sessions and assigned-place summaries.
- The app supports older payload compatibility by falling back from score_totals to legacy summary_score when needed.
8. Auth and session restoration
- Auth session data is stored separately from audit state, using Expo Secure Store for keychain/keystore-backed persistence.
- lib/auth/storage.ts and stores/auth-store.ts handle session persistence and restoration.
- This keeps credentials isolated from the general MMKV audit snapshot.
9. Places, reports, and lightweight field browsing
- The Places tab surfaces assigned places, search/filter/sort behavior, and place details.
- The Reports tab surfaces submitted audits with preview and export actions.
- These views are intentionally lighter-weight than the execute flow and reuse shared list/filter UI from components/ui/.
10. Client-side export is a distinct subsystem
- Submitted audits can be exported locally to CSV, XLSX, and PDF.
- Export logic is concentrated in lib/audit/export.ts and lib/audit/export-helpers.ts.
- The export surface is part of the mobile product, not a backend service, so report generation happens on-device.
11. Localization is instrument-driven
- lib/i18n/ manages app localization across multiple locales.
- The shared UI copy is split into locale JSON files, while lib/instrument.ts acts as the structural source of truth for the audit instrument.
- Locale-specific instrument bundles overlay translated display copy onto the shared instrument model.
12. Notifications are a separate but connected subsystem
- Notification fetching and refresh logic live in lib/notifications/.
- The app uses polling plus a local cache, with a dedicated notifications store and UI surfaces like the bell icon and notifications panel.
- This subsystem is adjacent to the main audit workflow but not part of audit state itself.
13. UI system and cross-cutting presentation
- Shared visual primitives live in components/ui/, while themes.ts, lib/design-system.ts, and Tamagui config files define the design system boundary.
- lib/responsive* helpers provide device-aware layout behavior, which matters because the app targets both phone and tablet form factors.
14. Operational tooling and quality gates
- The repo includes scripts and tests for translation extraction, audit contract verification, notification behavior, and screenshot automation.
- CI and local hooks enforce formatting, linting, and type safety, but these are supportive controls rather than runtime architecture.
Main entry points: execute-flow.ts Execute flow · audit Audit domain · (tabs) Tab shell · execute Execute tab
Components 20
Route UI
Expo Router screens and navigation shells
- App shell · Top-level app layout and bootstrapping
app/_layout.tsx - Auth flow · Login and signup presentation
app/(auth) - Tab shell · Main navigation tabs for the field app
app/(tabs) - Execute tab · Entry point for starting or resuming audits
app/(tabs)/execute - Place detail · Assigned place drill-in view
app/place/[placeId].tsx - Report detail · Submitted audit drill-in and export view
app/report/[auditId].tsx
Audit System
Core execute workflow and audit domain logic
- Execute flow · Audit execution orchestration from place to submission
lib/audit/execute-flow.ts - Question cards · Shared question rendering for execution screens
components/playspace-audit/question-card.tsx - Table layout · Section and question table composition
components/playspace-audit/section-question-table.tsx - Audit domain · Audit scoring, selectors, helpers, and state coordination
lib/audit - Export engine · On-device CSV, XLSX, and PDF generation
lib/audit/export.ts
State & Persistence
Reactive stores and on-device storage boundaries
- Audit store · Selector-friendly runtime audit state entrypoint
stores/audit-store.ts - MMKV layer · Durable on-device persistence for audit and app state
lib/storage/mmkv.ts - Auth store · Session restore and credential state
stores/auth-store.ts - Secure store · Expo Secure Store-backed auth persistence
lib/auth/storage.ts - Notifications store · Notification cache and refresh state
stores/notifications-store.ts
Server & Services
REST APIs and external service integration
- Audit API · Primary audit session and payload API client
lib/audit/api.ts - Places API · Assigned-place retrieval and place-centric data access
lib/audit/places-api.ts - Notifications API · Notification fetching and refresh requests
lib/notifications/api.ts
Shared UI & Design
Reusable UI primitives and presentation system
- Design system · Tamagui theme, tokens, and responsive layout helpers
lib/design-system.ts
Connections 23
- App shell → Auth flow: routes · Mounts auth flow
- App shell → Tab shell: routes · Mounts main field-app navigation
- Tab shell → Execute tab: tab · Execute is the central workflow entry
- Tab shell → Place detail: drill-in · Places tab links to place details
- Tab shell → Report detail: drill-in · Reports tab links to submitted audit details
- Execute tab → Execute flow: orchestrates · Launches or resumes audits
- Execute flow → Audit store: reads/writes · Uses live audit state for editing and submission
- Audit store → MMKV layer: persists · Dirty edits are saved locally
- Execute flow → Audit API: syncs · Fetches and flushes server source of truth
- Execute flow → Places API: resolves · Loads assigned-place context
- Execute flow → Question cards: renders · Uses shared question card presentation
- Execute flow → Table layout: renders · Uses section/question table layout
- Audit domain → Audit API: calls · Central audit business logic uses REST payloads
- Audit domain → Places API: calls · Place helpers and selectors depend on place data
- Audit domain → Export engine: drives · Prepares submitted audits for local export
- Audit domain → Audit store: selects · Selector layer shapes UI-friendly state
- Auth flow → Auth store: auth state · Login and signup depend on session state
- Auth store → Secure store: persists · Session data stored separately from MMKV audit snapshots
- Notifications store → Notifications API: polls · Refreshes notifications from server
- Notifications store → MMKV layer: caches · Caches notification data locally
- Execute tab → Design system: ui · Screens share Tamagui primitives and responsive behavior
- Place detail → Design system: ui · Uses shared field-browser components
- Report detail → Export engine: exports · Triggers local report generation