# keeratipong4/agnos-patient-realtime-intake architecture

> Architecture diagram of the GitHub repository keeratipong4/agnos-patient-realtime-intake, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keeratipong4/agnos-patient-realtime-intake
- Repository: https://github.com/keeratipong4/agnos-patient-realtime-intake

## Overview

Agnos is a demo app for pairing a Patient intake form with a Staff live monitor through a shared session UUID. Staff sees field changes, focus and activity status, and can recover a snapshot after joining or reconnecting; submission locks the views. The main path is session creation, role-specific routes, Patient entry and validation, realtime synchronization, and Staff monitoring. Drafts are ephemeral rather than database-backed. Source excerpts show key route, hook, protocol, and UI relationships; unsampled capabilities are retained where the README documents them.

Main entry points: [`src/hooks/use-patient-sync.ts`](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-patient-sync.ts) (Patient sync), [`src/components/patient/patient-form.tsx`](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-form.tsx) (Intake form), [`src/hooks/use-staff-sync.ts`](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-staff-sync.ts) (Staff sync), [`src/app/patient/page.tsx`](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/patient/page.tsx) (Patient route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_session["Session entry"]
  node_launcher_route["Launcher route<br/>[page.tsx]"]
  node_launcher["Session launcher"]
  node_patient_route["Patient route<br/>[page.tsx]"]
  node_staff_route["Staff route<br/>[page.tsx]"]
  node_session_identity["Session identity<br/>[session.ts]"]
  node_invalid_session["Invalid session view"]
end

subgraph group_patient["Patient intake"]
  node_patient_form["Intake form<br/>[patient-form.tsx]"]
  node_validation["Form validation<br/>[validations.ts]"]
  node_form_section["Form sections<br/>[form-section.tsx]"]
  node_field_broadcaster["Field broadcaster"]
  node_idle_tracker["Activity tracker"]
  node_vertical_slice["Vertical-slice demo"]
end

subgraph group_sync["Realtime sync"]
  node_patient_sync["Patient sync"]
  node_staff_sync["Staff sync<br/>[use-staff-sync.ts]"]
  node_event_protocol["Realtime protocol<br/>[realtime-events.ts]"]
  node_supabase_client["Realtime client<br/>[supabase.ts]"]
  node_vertical_hook["Vertical-slice sync"]
end

subgraph group_staff["Staff monitoring"]
  node_staff_monitor["Live monitor<br/>[staff-monitor.tsx]"]
  node_status_badge["Connection badge<br/>[status-badge.tsx]"]
end

node_patient_actor(("Patient"))
node_staff_actor(("Staff"))
node_realtime_service["Supabase Realtime"]

node_launcher_route -->|"renders"| node_launcher
node_patient_actor -.->|"starts session"| node_launcher
node_launcher -->|"links to"| node_patient_route
node_launcher -->|"links to"| node_staff_route
node_patient_route -->|"validates session"| node_session_identity
node_staff_route -->|"validates session"| node_session_identity
node_patient_route -->|"renders if invalid"| node_invalid_session
node_staff_route -->|"renders if invalid"| node_invalid_session
node_patient_route -->|"renders"| node_patient_form
node_staff_route -->|"renders"| node_staff_monitor
node_patient_form -->|"validates with"| node_validation
node_patient_form -->|"renders"| node_form_section
node_patient_form -->|"renders"| node_field_broadcaster
node_patient_form -->|"tracks activity"| node_idle_tracker
node_patient_form -->|"synchronizes with"| node_patient_sync
node_field_broadcaster -->|"sends field changes"| node_patient_sync
node_idle_tracker -.->|"updates status"| node_patient_sync
node_patient_sync -->|"names channel"| node_session_identity
node_staff_sync -->|"names channel"| node_session_identity
node_patient_sync -->|"builds events"| node_event_protocol
node_staff_sync -->|"validates events"| node_event_protocol
node_patient_sync -->|"creates client"| node_supabase_client
node_staff_sync -->|"creates client"| node_supabase_client
node_patient_sync -->|"broadcasts and tracks"| node_realtime_service
node_staff_sync -->|"listens and requests snapshots"| node_realtime_service
node_staff_monitor -->|"reads live state"| node_staff_sync
node_staff_monitor -->|"renders"| node_status_badge
node_staff_actor -.->|"views intake"| node_staff_monitor
node_vertical_slice -->|"uses"| node_vertical_hook
node_vertical_hook -->|"delegates to"| node_patient_sync

click node_launcher_route "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/page.tsx"
click node_launcher "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/session-launcher.tsx"
click node_patient_route "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/patient/page.tsx"
click node_staff_route "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/staff/page.tsx"
click node_session_identity "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/session.ts"
click node_invalid_session "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/common/invalid-session.tsx"
click node_patient_form "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-form.tsx"
click node_validation "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/validations.ts"
click node_form_section "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/form-section.tsx"
click node_field_broadcaster "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-field-sync.tsx"
click node_idle_tracker "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-idle-tracker.ts"
click node_patient_sync "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-patient-sync.ts"
click node_staff_sync "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-staff-sync.ts"
click node_event_protocol "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/realtime-events.ts"
click node_supabase_client "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/supabase.ts"
click node_staff_monitor "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/staff/staff-monitor.tsx"
click node_status_badge "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/common/status-badge.tsx"
click node_vertical_slice "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-vertical-slice.tsx"
click node_vertical_hook "https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-patient-vertical-slice.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_launcher_route,node_launcher,node_patient_route,node_staff_route,node_session_identity,node_invalid_session toneBlue
class node_patient_form,node_validation,node_form_section,node_field_broadcaster,node_idle_tracker,node_vertical_slice toneAmber
class node_patient_sync,node_staff_sync,node_event_protocol,node_supabase_client,node_vertical_hook toneMint
class node_staff_monitor,node_status_badge toneRose
class node_patient_actor,node_staff_actor,node_realtime_service toneIndigo
```

## Components

### Session entry

- [Launcher route](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Session launcher](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/session-launcher.tsx): `src/components/session-launcher.tsx`
- [Patient route](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/patient/page.tsx): `src/app/patient/page.tsx`
- [Staff route](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/app/staff/page.tsx): `src/app/staff/page.tsx`
- [Session identity](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/session.ts): `src/lib/session.ts`
- [Invalid session view](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/common/invalid-session.tsx): `src/components/common/invalid-session.tsx`

### Patient intake

- [Intake form](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-form.tsx): `src/components/patient/patient-form.tsx`
- [Form validation](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/validations.ts): `src/lib/validations.ts`
- [Form sections](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/form-section.tsx): `src/components/patient/form-section.tsx`
- [Field broadcaster](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-field-sync.tsx): `src/components/patient/patient-field-sync.tsx`
- [Activity tracker](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-idle-tracker.ts): `src/hooks/use-idle-tracker.ts`
- [Vertical-slice demo](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/patient/patient-vertical-slice.tsx): `src/components/patient/patient-vertical-slice.tsx`

### Realtime sync

- [Patient sync](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-patient-sync.ts): `src/hooks/use-patient-sync.ts`
- [Staff sync](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-staff-sync.ts): `src/hooks/use-staff-sync.ts`
- [Realtime protocol](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/realtime-events.ts): `src/lib/realtime-events.ts`
- [Realtime client](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`
- [Vertical-slice sync](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/hooks/use-patient-vertical-slice.ts): `src/hooks/use-patient-vertical-slice.ts`

### Staff monitoring

- [Live monitor](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/staff/staff-monitor.tsx): `src/components/staff/staff-monitor.tsx`
- [Connection badge](https://github.com/keeratipong4/agnos-patient-realtime-intake/blob/main/src/components/common/status-badge.tsx): `src/components/common/status-badge.tsx`

### Other components

- **Patient**
- **Staff**
- **Supabase Realtime**

## Connections

- Launcher route → Session launcher: renders (evidence: `src/app/page.tsx`)
- Patient → Session launcher: starts session (evidence: `README.md`)
- Session launcher → Patient route: links to (evidence: `src/components/session-launcher.tsx`)
- Session launcher → Staff route: links to (evidence: `src/components/session-launcher.tsx`)
- Patient route → Session identity: validates session (evidence: `src/app/patient/page.tsx`)
- Staff route → Session identity: validates session (evidence: `src/app/staff/page.tsx`)
- Patient route → Invalid session view: renders if invalid (evidence: `src/app/patient/page.tsx`)
- Staff route → Invalid session view: renders if invalid (evidence: `src/app/staff/page.tsx`)
- Patient route → Intake form: renders (evidence: `src/app/patient/page.tsx`)
- Staff route → Live monitor: renders (evidence: `src/app/staff/page.tsx`)
- Intake form → Form validation: validates with (evidence: `src/components/patient/patient-form.tsx`)
- Intake form → Form sections: renders (evidence: `src/components/patient/patient-form.tsx`)
- Intake form → Field broadcaster: renders (evidence: `src/components/patient/patient-form.tsx`)
- Intake form → Activity tracker: tracks activity (evidence: `src/components/patient/patient-form.tsx`)
- Intake form → Patient sync: synchronizes with (evidence: `src/components/patient/patient-form.tsx`)
- Field broadcaster → Patient sync: sends field changes (evidence: `src/components/patient/patient-field-sync.tsx`)
- Activity tracker → Patient sync: updates status (evidence: `src/hooks/use-idle-tracker.ts`)
- Patient sync → Session identity: names channel (evidence: `src/hooks/use-patient-sync.ts`)
- Staff sync → Session identity: names channel (evidence: `src/hooks/use-staff-sync.ts`)
- Patient sync → Realtime protocol: builds events (evidence: `src/hooks/use-patient-sync.ts`)
- Staff sync → Realtime protocol: validates events (evidence: `src/hooks/use-staff-sync.ts`)
- Patient sync → Realtime client: creates client (evidence: `src/hooks/use-patient-sync.ts`)
- Staff sync → Realtime client: creates client (evidence: `src/hooks/use-staff-sync.ts`)
- Patient sync → Supabase Realtime: broadcasts and tracks (evidence: `src/hooks/use-patient-sync.ts`)
- Staff sync → Supabase Realtime: listens and requests snapshots (evidence: `src/hooks/use-staff-sync.ts`)
- Live monitor → Staff sync: reads live state (evidence: `src/components/staff/staff-monitor.tsx`)
- Live monitor → Connection badge: renders (evidence: `src/components/staff/staff-monitor.tsx`)
- Staff → Live monitor: views intake (evidence: `README.md`)
- Vertical-slice demo → Vertical-slice sync: uses (evidence: `src/components/patient/patient-vertical-slice.tsx`)
- Vertical-slice sync → Patient sync: delegates to (evidence: `src/hooks/use-patient-vertical-slice.ts`)
