# audit-tools-deca-lab-cornell/audit-tools-playspace-mobile architecture

> Architecture diagram of the GitHub repository audit-tools-deca-lab-cornell/audit-tools-playspace-mobile, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile
- Repository: https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile

## Overview

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: [`lib/audit/execute-flow.ts`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/execute-flow.ts) (Execute flow), [`lib/audit`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/lib/audit) (Audit domain), [`app/(tabs)`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)) (Tab shell), [`app/(tabs)/execute`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)/execute) (Execute tab)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Route UI"]
  node_root_layout["App shell<br/>expo-router shell<br/>[_layout.tsx]"]
  node_auth_routes["Auth flow<br/>route group"]
  node_tab_shell["Tab shell<br/>route group"]
  node_execute_tab["Execute tab<br/>route group"]
  node_place_detail["Place detail<br/>route screen<br/>[[placeId].tsx]"]
  node_report_detail["Report detail<br/>route screen<br/>[[auditId].tsx]"]
end

subgraph group_audit["Audit System"]
  node_execute_flow{{"Execute flow<br/>workflow<br/>[execute-flow.ts]"}}
  node_question_ui["Question cards<br/>audit UI<br/>[question-card.tsx]"]
  node_table_layout["Table layout<br/>audit UI"]
  node_audit_domain{{"Audit domain<br/>domain logic"}}
  node_export_system{{"Export engine<br/>local export<br/>[export.ts]"}}
end

subgraph group_state["State & Persistence"]
  node_audit_store[("Audit store<br/>state store<br/>[audit-store.ts]")]
  node_mmkv_storage[("MMKV layer<br/>local persistence<br/>[mmkv.ts]")]
  node_auth_store[("Auth store<br/>session store<br/>[auth-store.ts]")]
  node_auth_storage[("Secure store<br/>keychain storage<br/>[storage.ts]")]
  node_notifications_store[("Notifications store<br/>state store")]
end

subgraph group_integrations["Server & Services"]
  node_audit_api["Audit API<br/>REST client<br/>[api.ts]"]
  node_places_api["Places API<br/>REST client<br/>[places-api.ts]"]
  node_notifications_api["Notifications API<br/>REST client<br/>[api.ts]"]
end

subgraph group_shared["Shared UI & Design"]
  node_design_system{{"Design system<br/>ui system<br/>[design-system.ts]"}}
end

subgraph group_tooling["Tooling"]
end

node_root_layout -->|"routes"| node_auth_routes
node_root_layout -->|"routes"| node_tab_shell
node_tab_shell -->|"tab"| node_execute_tab
node_tab_shell -->|"drill-in"| node_place_detail
node_tab_shell -->|"drill-in"| node_report_detail
node_execute_tab -->|"orchestrates"| node_execute_flow
node_execute_flow -->|"reads/writes"| node_audit_store
node_audit_store -->|"persists"| node_mmkv_storage
node_execute_flow -->|"syncs"| node_audit_api
node_execute_flow -->|"resolves"| node_places_api
node_execute_flow -->|"renders"| node_question_ui
node_execute_flow -->|"renders"| node_table_layout
node_audit_domain -->|"calls"| node_audit_api
node_audit_domain -->|"calls"| node_places_api
node_audit_domain -->|"drives"| node_export_system
node_audit_domain -->|"selects"| node_audit_store
node_auth_routes -->|"auth state"| node_auth_store
node_auth_store -->|"persists"| node_auth_storage
node_notifications_store -->|"polls"| node_notifications_api
node_notifications_store -->|"caches"| node_mmkv_storage
node_execute_tab -->|"ui"| node_design_system
node_place_detail -->|"ui"| node_design_system
node_report_detail -->|"exports"| node_export_system

click node_root_layout "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/_layout.tsx"
click node_auth_routes "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(auth)"
click node_tab_shell "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)"
click node_execute_tab "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)/execute"
click node_place_detail "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/place/[placeId].tsx"
click node_report_detail "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/report/[auditId].tsx"
click node_execute_flow "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/execute-flow.ts"
click node_question_ui "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/components/playspace-audit/question-card.tsx"
click node_table_layout "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/components/playspace-audit/section-question-table.tsx"
click node_audit_domain "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/lib/audit"
click node_audit_api "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/api.ts"
click node_places_api "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/places-api.ts"
click node_export_system "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/export.ts"
click node_audit_store "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/audit-store.ts"
click node_mmkv_storage "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/storage/mmkv.ts"
click node_auth_store "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/auth-store.ts"
click node_auth_storage "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/auth/storage.ts"
click node_notifications_store "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/notifications-store.ts"
click node_notifications_api "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/notifications/api.ts"
click node_design_system "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/design-system.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root_layout,node_auth_routes,node_tab_shell,node_execute_tab,node_place_detail,node_report_detail toneBlue
class node_execute_flow,node_question_ui,node_table_layout,node_audit_domain,node_export_system toneAmber
class node_audit_store,node_mmkv_storage,node_auth_store,node_auth_storage,node_notifications_store toneMint
class node_audit_api,node_places_api,node_notifications_api toneRose
class node_design_system toneIndigo
```

## Components

### Route UI

Expo Router screens and navigation shells

- [App shell](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/_layout.tsx): expo-router shell · Top-level app layout and bootstrapping · `app/_layout.tsx`
- [Auth flow](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(auth)): route group · Login and signup presentation · `app/(auth)`
- [Tab shell](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)): route group · Main navigation tabs for the field app · `app/(tabs)`
- [Execute tab](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/app/(tabs)/execute): route group · Entry point for starting or resuming audits · `app/(tabs)/execute`
- [Place detail](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/place/[placeId].tsx): route screen · Assigned place drill-in view · `app/place/[placeId].tsx`
- [Report detail](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/app/report/[auditId].tsx): route screen · Submitted audit drill-in and export view · `app/report/[auditId].tsx`

### Audit System

Core execute workflow and audit domain logic

- [Execute flow](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/execute-flow.ts): workflow · Audit execution orchestration from place to submission · `lib/audit/execute-flow.ts`
- [Question cards](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/components/playspace-audit/question-card.tsx): audit UI · Shared question rendering for execution screens · `components/playspace-audit/question-card.tsx`
- [Table layout](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/components/playspace-audit/section-question-table.tsx): audit UI · Section and question table composition · `components/playspace-audit/section-question-table.tsx`
- [Audit domain](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/tree/master/lib/audit): domain logic · Audit scoring, selectors, helpers, and state coordination · `lib/audit`
- [Export engine](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/export.ts): local export · On-device CSV, XLSX, and PDF generation · `lib/audit/export.ts`

### State & Persistence

Reactive stores and on-device storage boundaries

- [Audit store](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/audit-store.ts): state store · Selector-friendly runtime audit state entrypoint · `stores/audit-store.ts`
- [MMKV layer](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/storage/mmkv.ts): local persistence · Durable on-device persistence for audit and app state · `lib/storage/mmkv.ts`
- [Auth store](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/auth-store.ts): session store · Session restore and credential state · `stores/auth-store.ts`
- [Secure store](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/auth/storage.ts): keychain storage · Expo Secure Store-backed auth persistence · `lib/auth/storage.ts`
- [Notifications store](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/stores/notifications-store.ts): state store · Notification cache and refresh state · `stores/notifications-store.ts`

### Server & Services

REST APIs and external service integration

- [Audit API](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/api.ts): REST client · Primary audit session and payload API client · `lib/audit/api.ts`
- [Places API](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/audit/places-api.ts): REST client · Assigned-place retrieval and place-centric data access · `lib/audit/places-api.ts`
- [Notifications API](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/notifications/api.ts): REST client · Notification fetching and refresh requests · `lib/notifications/api.ts`

### Shared UI & Design

Reusable UI primitives and presentation system

- [Design system](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-mobile/blob/master/lib/design-system.ts): ui system · Tamagui theme, tokens, and responsive layout helpers · `lib/design-system.ts`

## Connections

- 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
