# faribro/childcare-support---phase-3- architecture

> Architecture diagram of the GitHub repository faribro/childcare-support---phase-3-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/faribro/childcare-support---phase-3-
- Repository: https://github.com/faribro/childcare-support---phase-3-

## Overview

Childcare Support Phase 3 is an offline-first PWA for frontline workers to record child nutrition and education-support assessments, save and sync submissions, and let supervisors review programme records and analytics. Its main workflow runs from mobile assessment and local persistence through queued central sync to the server-side submission adapter and Google Sheets/Apps Script integration. Separate branches cover authentication, record exports, and supervisor reporting/GIS. The README documents the product capabilities; sampled source and the SOURCE INDEX support only the specific internal relationships shown below.

Main entry points: [`src/app/assessment/new/page.tsx`](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/assessment/new/page.tsx) (Assessment workflow), [`src/lib/server/canonicalSubmissionAdapter.ts`](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/canonicalSubmissionAdapter.ts) (Canonical submission service), [`src/lib/read-model/supervisorReadModel.ts`](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/read-model/supervisorReadModel.ts) (Supervisor read model), [`src/features/submission/submissionWorker.ts`](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionWorker.ts) (Sync dispatcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_field["Field assessment"]
  node_assessment["Assessment workflow<br/>[page.tsx]"]
  node_nutrition["Nutrition assessment"]
  node_education["Education and grant support"]
  node_validation["Submission validation"]
end

subgraph group_offline["Offline and sync"]
  node_localdb[("Offline IndexedDB<br/>[dexieDb.ts]")]
  node_drafts["Draft persistence<br/>[draftRepository.ts]"]
  node_outbox["Submission outbox"]
  node_syncworker["Sync dispatcher"]
  node_syncgateway["Submission gateway"]
end

subgraph group_server["Server services"]
  node_syncapi["Sync endpoint<br/>[route.ts]"]
  node_submissionapi["Submission API<br/>[route.ts]"]
  node_adapter["Canonical submission service"]
  node_sheetstore[("Sheet-backed store<br/>[mockSheetStore.ts]")]
  node_export["PDF record export"]
end

subgraph group_supervisor["Supervisor tools"]
  node_supervisorui["Supervisor workspace<br/>[page.tsx]"]
  node_readmodel["Supervisor read model"]
  node_analytics["Analytics and cohort views<br/>[page.tsx]"]
  node_gis["GIS views"]
end

subgraph group_platform["PWA and access"]
  node_authapi["Login and session APIs<br/>[route.ts]"]
  node_sessions["Session service<br/>[sessionService.ts]"]
  node_authorization["Authorization<br/>[authorisation.ts]"]
  node_serviceworker["PWA service worker<br/>[sw.ts]"]
end

node_worker(("Frontline worker"))
node_sheets[("Google Sheets and Apps Script")]

node_worker -->|"records assessment"| node_assessment
node_assessment -.->|"calculates nutrition"| node_nutrition
node_assessment -.->|"captures support"| node_education
node_assessment -.->|"validates submission"| node_validation
node_assessment -->|"autosaves draft"| node_drafts
node_drafts -->|"stores draft"| node_localdb
node_outbox -->|"stores queue"| node_localdb
node_syncworker -->|"dispatches queued items"| node_outbox
node_syncworker -->|"sends submissions"| node_syncgateway
node_syncgateway -.->|"requests sync"| node_syncapi
node_syncapi -->|"uses submission service"| node_adapter
node_submissionapi -->|"validates payload"| node_validation
node_submissionapi -->|"delegates submission"| node_adapter
node_adapter -->|"uses store"| node_sheetstore
node_adapter -.->|"syncs central records"| node_sheets
node_authapi -->|"authenticates user"| node_sessions
node_authapi -->|"checks access"| node_authorization
node_authorization -->|"verifies session"| node_sessions
node_supervisorui -.->|"loads supervisor data"| node_readmodel
node_readmodel -.->|"reads submission data"| node_adapter
node_analytics -.->|"presents analytics"| node_readmodel
node_gis -.->|"supports geographic review"| node_supervisorui
node_export -.->|"exports record data"| node_adapter
node_assessment -.->|"runs as installed PWA"| node_serviceworker

click node_assessment "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/assessment/new/page.tsx"
click node_nutrition "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/clinical/nutritionCalculations.ts"
click node_education "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/components/education/ExpensesAndApprovalGrid.tsx"
click node_validation "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/validations/submissionSchema.ts"
click node_localdb "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/db/dexieDb.ts"
click node_drafts "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/db/draftRepository.ts"
click node_outbox "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionQueueRepository.ts"
click node_syncworker "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionWorker.ts"
click node_syncgateway "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionGateway.ts"
click node_syncapi "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/sync/route.ts"
click node_submissionapi "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/submissions/route.ts"
click node_adapter "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/canonicalSubmissionAdapter.ts"
click node_sheetstore "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/mockSheetStore.ts"
click node_authapi "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/auth/login/route.ts"
click node_sessions "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/sessionService.ts"
click node_authorization "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/authorisation.ts"
click node_export "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/pdfExportService.ts"
click node_supervisorui "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/supervisor/page.tsx"
click node_readmodel "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/read-model/supervisorReadModel.ts"
click node_analytics "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/supervisor/analytics/page.tsx"
click node_gis "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/components/gis/GISMapComponent.tsx"
click node_serviceworker "https://github.com/faribro/childcare-support---phase-3-/blob/main/src/sw.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_assessment,node_nutrition,node_education,node_validation toneBlue
class node_localdb,node_drafts,node_outbox,node_syncworker,node_syncgateway,node_sheets toneAmber
class node_syncapi,node_submissionapi,node_adapter,node_sheetstore,node_export toneMint
class node_supervisorui,node_readmodel,node_analytics,node_gis,node_worker toneRose
class node_authapi,node_sessions,node_authorization,node_serviceworker toneIndigo
```

## Components

### Field assessment

- [Assessment workflow](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/assessment/new/page.tsx): `src/app/assessment/new/page.tsx`
- [Nutrition assessment](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/clinical/nutritionCalculations.ts): `src/lib/clinical/nutritionCalculations.ts`
- [Education and grant support](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/components/education/ExpensesAndApprovalGrid.tsx): `src/components/education/ExpensesAndApprovalGrid.tsx`
- [Submission validation](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/validations/submissionSchema.ts): `src/lib/validations/submissionSchema.ts`

### Offline and sync

- [Offline IndexedDB](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/db/dexieDb.ts): `src/lib/db/dexieDb.ts`
- [Draft persistence](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/db/draftRepository.ts): `src/lib/db/draftRepository.ts`
- [Submission outbox](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionQueueRepository.ts): `src/features/submission/submissionQueueRepository.ts`
- [Sync dispatcher](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionWorker.ts): `src/features/submission/submissionWorker.ts`
- [Submission gateway](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/features/submission/submissionGateway.ts): `src/features/submission/submissionGateway.ts`

### Server services

- [Sync endpoint](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/sync/route.ts): `src/app/api/sync/route.ts`
- [Submission API](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/submissions/route.ts): `src/app/api/submissions/route.ts`
- [Canonical submission service](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/canonicalSubmissionAdapter.ts): `src/lib/server/canonicalSubmissionAdapter.ts`
- [Sheet-backed store](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/mockSheetStore.ts): `src/lib/server/mockSheetStore.ts`
- [PDF record export](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/pdfExportService.ts): `src/lib/server/pdfExportService.ts`

### Supervisor tools

- [Supervisor workspace](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/supervisor/page.tsx): `src/app/supervisor/page.tsx`
- [Supervisor read model](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/read-model/supervisorReadModel.ts): `src/lib/read-model/supervisorReadModel.ts`
- [Analytics and cohort views](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/supervisor/analytics/page.tsx): `src/app/supervisor/analytics/page.tsx`
- [GIS views](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/components/gis/GISMapComponent.tsx): `src/components/gis/GISMapComponent.tsx`

### PWA and access

- [Login and session APIs](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/app/api/auth/login/route.ts): `src/app/api/auth/login/route.ts`
- [Session service](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/sessionService.ts): `src/lib/server/sessionService.ts`
- [Authorization](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/lib/server/authorisation.ts): `src/lib/server/authorisation.ts`
- [PWA service worker](https://github.com/faribro/childcare-support---phase-3-/blob/main/src/sw.ts): `src/sw.ts`

### Other components

- **Frontline worker**
- **Google Sheets and Apps Script**

## Connections

- Frontline worker → Assessment workflow: records assessment
- Assessment workflow → Nutrition assessment: calculates nutrition
- Assessment workflow → Education and grant support: captures support
- Assessment workflow → Submission validation: validates submission
- Assessment workflow → Draft persistence: autosaves draft
- Draft persistence → Offline IndexedDB: stores draft (evidence: `src/lib/db/draftRepository.ts`)
- Submission outbox → Offline IndexedDB: stores queue (evidence: `src/features/submission/submissionQueueRepository.ts`)
- Sync dispatcher → Submission outbox: dispatches queued items (evidence: `src/features/submission/submissionWorker.ts`)
- Sync dispatcher → Submission gateway: sends submissions (evidence: `src/features/submission/submissionWorker.ts`)
- Submission gateway → Sync endpoint: requests sync
- Sync endpoint → Canonical submission service: uses submission service (evidence: `src/app/api/sync/route.ts`)
- Submission API → Submission validation: validates payload (evidence: `src/app/api/submissions/route.ts`)
- Submission API → Canonical submission service: delegates submission (evidence: `src/app/api/submissions/route.ts`)
- Canonical submission service → Sheet-backed store: uses store (evidence: `src/lib/server/canonicalSubmissionAdapter.ts`)
- Canonical submission service → Google Sheets and Apps Script: syncs central records
- Login and session APIs → Session service: authenticates user (evidence: `src/app/api/auth/login/route.ts`)
- Login and session APIs → Authorization: checks access (evidence: `src/app/api/auth/login/route.ts`)
- Authorization → Session service: verifies session (evidence: `src/lib/server/authorisation.ts`)
- Supervisor workspace → Supervisor read model: loads supervisor data
- Supervisor read model → Canonical submission service: reads submission data
- Analytics and cohort views → Supervisor read model: presents analytics
- GIS views → Supervisor workspace: supports geographic review
- PDF record export → Canonical submission service: exports record data
- Assessment workflow → PWA service worker: runs as installed PWA
