# tbstechudt-dotcom/power-ca_mobileapp_staff architecture

> Architecture diagram of the GitHub repository tbstechudt-dotcom/power-ca_mobileapp_staff, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tbstechudt-dotcom/power-ca_mobileapp_staff
- Repository: https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff

## Overview

PowerCA Mobile combines a Node.js replication service with a Flutter field-staff app. The principal workflow copies desktop PostgreSQL data to Supabase through a staging-based forward sync; staff use the cloud-backed mobile app, and mobile-created records return to desktop through incremental reverse sync. Scheduling and sync metadata support recurring, incremental runs. The README documents mobile features, but the tree and excerpts do not expose the Flutter application’s Dart source, so its internal feature components are represented at the app-directory level; relationships below rely on documented flows where implementation links were not sampled.

Main entry points: [`sync/production/engine-staging.js`](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/engine-staging.js) (Staging sync engine), [`powerca_mobile`](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/tree/main/powerca_mobile) (Flutter mobile app), [`sync/production/reverse-sync-engine.js`](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/reverse-sync-engine.js) (Reverse sync engine), [`sync/production/runner-staging.js`](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/runner-staging.js) (Forward sync runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_replication["Data replication"]
  node_sync_engine["Staging sync engine<br/>[engine-staging.js]"]
  node_sync_config["Sync mappings<br/>[config.js]"]
  node_forward_runner["Forward sync runner<br/>[runner-staging.js]"]
  node_reverse_runner["Reverse sync runner"]
  node_reverse_engine["Reverse sync engine"]
  node_metadata[("Sync metadata<br/>[engine-staging.js]")]
end

subgraph group_operations["Sync operations"]
  node_scheduler["Sync scheduler<br/>[sync-scheduler.js]"]
end

subgraph group_mobile["Mobile experience"]
  node_mobile_app["Flutter mobile app"]
  node_local_cache[("Local SQLite cache")]
end

subgraph group_services["Cloud services"]
  node_desktop[("Desktop PostgreSQL")]
  node_cloud_db[("Supabase database")]
  node_auth_functions["Authentication functions<br/>[index.ts]"]
  node_realtime["Supabase Realtime"]
end

node_staff(("Field staff"))

node_forward_runner -->|"runs"| node_sync_engine
node_sync_engine -->|"reads desktop"| node_desktop
node_sync_engine -->|"stages and writes"| node_cloud_db
node_sync_engine -->|"uses mappings"| node_sync_config
node_sync_engine -->|"tracks sync"| node_metadata
node_scheduler -.->|"schedules sync"| node_forward_runner
node_reverse_runner -->|"runs"| node_reverse_engine
node_reverse_engine -->|"reads mobile data"| node_cloud_db
node_reverse_engine -->|"writes records"| node_desktop
node_reverse_engine -->|"uses mappings"| node_sync_config
node_staff -->|"uses"| node_mobile_app
node_mobile_app -->|"queries and updates"| node_cloud_db
node_mobile_app -.->|"authenticates"| node_auth_functions
node_mobile_app -.->|"receives updates"| node_realtime
node_mobile_app -.->|"caches offline"| node_local_cache

click node_sync_engine "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/engine-staging.js"
click node_sync_config "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/config.js"
click node_forward_runner "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/runner-staging.js"
click node_reverse_runner "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/reverse-sync-runner.js"
click node_reverse_engine "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/reverse-sync-engine.js"
click node_metadata "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/engine-staging.js"
click node_scheduler "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/scheduler/sync-scheduler.js"
click node_mobile_app "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/tree/main/powerca_mobile"
click node_auth_functions "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/supabase/functions/auth-login/index.ts"
click node_local_cache "https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/tree/main/powerca_mobile"

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_sync_engine,node_sync_config,node_forward_runner,node_reverse_runner,node_reverse_engine,node_metadata toneBlue
class node_scheduler toneAmber
class node_mobile_app,node_local_cache toneMint
class node_desktop,node_cloud_db,node_auth_functions,node_realtime toneRose
class node_staff toneIndigo
```

## Components

### Data replication

- [Staging sync engine](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/engine-staging.js): `sync/production/engine-staging.js`
- [Sync mappings](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/config.js): `sync/production/config.js`
- [Forward sync runner](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/runner-staging.js): `sync/production/runner-staging.js`
- [Reverse sync runner](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/reverse-sync-runner.js): `sync/production/reverse-sync-runner.js`
- [Reverse sync engine](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/reverse-sync-engine.js): `sync/production/reverse-sync-engine.js`
- [Sync metadata](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/production/engine-staging.js): `sync/production/engine-staging.js`

### Sync operations

- [Sync scheduler](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/sync/scheduler/sync-scheduler.js): `sync/scheduler/sync-scheduler.js`

### Mobile experience

- [Flutter mobile app](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/tree/main/powerca_mobile): `powerca_mobile`
- [Local SQLite cache](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/tree/main/powerca_mobile): `powerca_mobile`

### Cloud services

- **Desktop PostgreSQL**
- **Supabase database**
- [Authentication functions](https://github.com/tbstechudt-dotcom/power-ca_mobileapp_staff/blob/main/supabase/functions/auth-login/index.ts): `supabase/functions/auth-login/index.ts`
- **Supabase Realtime**

### Other components

- **Field staff**

## Connections

- Forward sync runner → Staging sync engine: runs (evidence: `README.md`)
- Staging sync engine → Desktop PostgreSQL: reads desktop (evidence: `README.md`)
- Staging sync engine → Supabase database: stages and writes (evidence: `README.md`)
- Staging sync engine → Sync mappings: uses mappings (evidence: `sync/production/engine-staging.js`)
- Staging sync engine → Sync metadata: tracks sync (evidence: `sync/production/engine-staging.js`)
- Sync scheduler → Forward sync runner: schedules sync (evidence: `README.md`)
- Reverse sync runner → Reverse sync engine: runs (evidence: `README.md`)
- Reverse sync engine → Supabase database: reads mobile data (evidence: `README.md`)
- Reverse sync engine → Desktop PostgreSQL: writes records (evidence: `README.md`)
- Reverse sync engine → Sync mappings: uses mappings (evidence: `sync/production/reverse-sync-engine.js`)
- Field staff → Flutter mobile app: uses (evidence: `README.md`)
- Flutter mobile app → Supabase database: queries and updates (evidence: `README.md`)
- Flutter mobile app → Authentication functions: authenticates
- Flutter mobile app → Supabase Realtime: receives updates (evidence: `README.md`)
- Flutter mobile app → Local SQLite cache: caches offline (evidence: `README.md`)
