# tesspitch/nurse-shift architecture

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

- Interactive diagram: https://gitdiagram.com/tesspitch/nurse-shift
- Repository: https://github.com/tesspitch/nurse-shift

## Overview

This is a Thai nurse-shift and estimated-income LIFF app. The main user flow is entering settings and shifts, reviewing calendar/month history, and calculating an estimate; the remote path authenticates LINE users and persists versioned state through Supabase. Separate backend capabilities include configurable LINE reminders, a LINE bot/Rich Menu webhook, CSV/JSON transfer, and PDF summaries. Edges reflect excerpts, SOURCE INDEX references, or README claims; several UI and notification details are unsampled, so their links are shown only where documented or explicitly left unverified.

Main entry points: [`src/app.js`](https://github.com/tesspitch/nurse-shift/blob/main/src/app.js) (LIFF web app), [`src/service.js`](https://github.com/tesspitch/nurse-shift/blob/main/src/service.js) (Local and remote service), [`supabase/functions/app-api/index.ts`](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/app-api/index.ts) (App API endpoint), [`supabase/functions/_shared/application/app-api-actions.js`](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/application/app-api-actions.js) (API actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Shift planner"]
  node_app["LIFF web app<br/>[app.js]"]
  node_calendar["Calendar and shifts<br/>[app.js]"]
  node_bulk["Bulk shift planning<br/>[bulk-shifts.js]"]
  node_historyui["Month history"]
  node_service["Local and remote service<br/>[service.js]"]
  node_cachedhistory["History cache"]
end

subgraph group_domain["Payroll domain"]
  node_date["Thai calendar dates<br/>[date.js]"]
  node_payrollui["Income estimate<br/>[calculations.js]"]
  node_shiftapp["Shift time rules<br/>[shift-time.js]"]
  node_payroll["Payroll summary<br/>[payroll.js]"]
end

subgraph group_backend["Application API"]
  node_api["App API endpoint<br/>[index.ts]"]
  node_http["HTTP responses<br/>[app-api-http.js]"]
  node_actions["API actions<br/>[app-api-actions.js]"]
  node_validation["State validation"]
  node_state[("User state repository")]
  node_history[("History repository")]
  node_histusecase["History use case"]
end

subgraph group_notifications["LINE notifications"]
  node_rules[("Notification rules")]
  node_schedule["Schedule calculation"]
  node_reminder["Reminder function<br/>[index.ts]"]
  node_expiration["Expiration notices"]
  node_delivery["LINE delivery<br/>[line-delivery.js]"]
  node_webhook["LINE webhook<br/>[index.ts]"]
  node_bot["LINE bot responses<br/>[line-bot.js]"]
end

subgraph group_transfer["Personal data tools"]
  node_transfer["CSV and JSON transfer<br/>[data-transfer.js]"]
end

node_nurse(("Nurse"))
node_line["LINE platform"]

node_nurse -->|"uses"| node_app
node_app -->|"renders"| node_calendar
node_app -->|"builds plan"| node_bulk
node_bulk -->|"checks overlap"| node_shiftapp
node_app -->|"renders dates"| node_date
node_app -->|"calculates"| node_payrollui
node_payrollui -->|"uses time rules"| node_shiftapp
node_payrollui -->|"uses summary"| node_payroll
node_app -->|"loads and saves"| node_service
node_service -->|"caches months"| node_cachedhistory
node_service -->|"requests history"| node_historyui
node_historyui -->|"loads months"| node_cachedhistory
node_app -->|"exports and imports"| node_transfer
node_nurse -.->|"downloads PDF"| node_app
node_service -->|"posts actions"| node_api
node_api -->|"formats responses"| node_http
node_api -->|"dispatches"| node_actions
node_api -->|"loads and saves state"| node_state
node_actions -->|"validates state"| node_validation
node_actions -->|"updates rules"| node_rules
node_actions -->|"requests history"| node_histusecase
node_histusecase -->|"reads month"| node_history
node_reminder -->|"claims due jobs"| node_schedule
node_reminder -->|"checks expiration"| node_expiration
node_reminder -->|"sends notices"| node_delivery
node_delivery -->|"pushes message"| node_line
node_nurse -.->|"configures reminders"| node_line
node_line -->|"posts events"| node_webhook
node_webhook -->|"routes postbacks"| node_bot
node_bot -.->|"replies"| node_line

click node_app "https://github.com/tesspitch/nurse-shift/blob/main/src/app.js"
click node_calendar "https://github.com/tesspitch/nurse-shift/blob/main/src/app.js"
click node_bulk "https://github.com/tesspitch/nurse-shift/blob/main/src/modules/shifts/application/bulk-shifts.js"
click node_historyui "https://github.com/tesspitch/nurse-shift/blob/main/src/modules/history/application/get-month-history.js"
click node_service "https://github.com/tesspitch/nurse-shift/blob/main/src/service.js"
click node_cachedhistory "https://github.com/tesspitch/nurse-shift/blob/main/src/infrastructure/history/cached-history-repository.js"
click node_date "https://github.com/tesspitch/nurse-shift/blob/main/src/date.js"
click node_payrollui "https://github.com/tesspitch/nurse-shift/blob/main/src/calculations.js"
click node_shiftapp "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/shift-time.js"
click node_payroll "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/payroll.js"
click node_transfer "https://github.com/tesspitch/nurse-shift/blob/main/src/data-transfer.js"
click node_api "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/app-api/index.ts"
click node_http "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/http/app-api-http.js"
click node_actions "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/application/app-api-actions.js"
click node_validation "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/user-state-validation.js"
click node_state "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/user-state-repository.js"
click node_history "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/history-repository.js"
click node_histusecase "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/application/get-month-history.js"
click node_rules "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/notification-rule-repository.js"
click node_schedule "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/notification-scheduling.js"
click node_reminder "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/send-reminders/index.ts"
click node_expiration "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/expiration-notification.js"
click node_delivery "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/line-delivery.js"
click node_webhook "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/line-webhook/index.ts"
click node_bot "https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/line-bot.js"

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_app,node_calendar,node_bulk,node_historyui,node_service,node_cachedhistory toneBlue
class node_date,node_payrollui,node_shiftapp,node_payroll toneAmber
class node_api,node_http,node_actions,node_validation,node_state,node_history,node_histusecase toneMint
class node_rules,node_schedule,node_reminder,node_expiration,node_delivery,node_webhook,node_bot toneRose
class node_transfer,node_nurse,node_line toneIndigo
```

## Components

### Shift planner

- [LIFF web app](https://github.com/tesspitch/nurse-shift/blob/main/src/app.js): `src/app.js`
- [Calendar and shifts](https://github.com/tesspitch/nurse-shift/blob/main/src/app.js): `src/app.js`
- [Bulk shift planning](https://github.com/tesspitch/nurse-shift/blob/main/src/modules/shifts/application/bulk-shifts.js): `src/modules/shifts/application/bulk-shifts.js`
- [Month history](https://github.com/tesspitch/nurse-shift/blob/main/src/modules/history/application/get-month-history.js): `src/modules/history/application/get-month-history.js`
- [Local and remote service](https://github.com/tesspitch/nurse-shift/blob/main/src/service.js): `src/service.js`
- [History cache](https://github.com/tesspitch/nurse-shift/blob/main/src/infrastructure/history/cached-history-repository.js): `src/infrastructure/history/cached-history-repository.js`

### Payroll domain

- [Thai calendar dates](https://github.com/tesspitch/nurse-shift/blob/main/src/date.js): `src/date.js`
- [Income estimate](https://github.com/tesspitch/nurse-shift/blob/main/src/calculations.js): `src/calculations.js`
- [Shift time rules](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/shift-time.js): `supabase/functions/_shared/domain/shift-time.js`
- [Payroll summary](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/payroll.js): `supabase/functions/_shared/domain/payroll.js`

### Application API

- [App API endpoint](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/app-api/index.ts): `supabase/functions/app-api/index.ts`
- [HTTP responses](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/http/app-api-http.js): `supabase/functions/_shared/http/app-api-http.js`
- [API actions](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/application/app-api-actions.js): `supabase/functions/_shared/application/app-api-actions.js`
- [State validation](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/domain/user-state-validation.js): `supabase/functions/_shared/domain/user-state-validation.js`
- [User state repository](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/user-state-repository.js): `supabase/functions/_shared/infrastructure/supabase/user-state-repository.js`
- [History repository](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/history-repository.js): `supabase/functions/_shared/infrastructure/supabase/history-repository.js`
- [History use case](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/application/get-month-history.js): `supabase/functions/_shared/application/get-month-history.js`

### LINE notifications

- [Notification rules](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/infrastructure/supabase/notification-rule-repository.js): `supabase/functions/_shared/infrastructure/supabase/notification-rule-repository.js`
- [Schedule calculation](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/notification-scheduling.js): `supabase/functions/_shared/notification-scheduling.js`
- [Reminder function](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/send-reminders/index.ts): `supabase/functions/send-reminders/index.ts`
- [Expiration notices](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/expiration-notification.js): `supabase/functions/_shared/expiration-notification.js`
- [LINE delivery](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/line-delivery.js): `supabase/functions/_shared/line-delivery.js`
- [LINE webhook](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/line-webhook/index.ts): `supabase/functions/line-webhook/index.ts`
- [LINE bot responses](https://github.com/tesspitch/nurse-shift/blob/main/supabase/functions/_shared/line-bot.js): `supabase/functions/_shared/line-bot.js`

### Personal data tools

- [CSV and JSON transfer](https://github.com/tesspitch/nurse-shift/blob/main/src/data-transfer.js): `src/data-transfer.js`

### Other components

- **Nurse**
- **LINE platform**

## Connections

- Nurse → LIFF web app: uses (evidence: `README.md`)
- LIFF web app → Calendar and shifts: renders (evidence: `src/app.js`)
- LIFF web app → Bulk shift planning: builds plan (evidence: `src/app.js`)
- Bulk shift planning → Shift time rules: checks overlap (evidence: `src/modules/shifts/application/bulk-shifts.js`)
- LIFF web app → Thai calendar dates: renders dates (evidence: `src/app.js`)
- LIFF web app → Income estimate: calculates (evidence: `src/app.js`)
- Income estimate → Shift time rules: uses time rules (evidence: `src/calculations.js`)
- Income estimate → Payroll summary: uses summary (evidence: `src/calculations.js`)
- LIFF web app → Local and remote service: loads and saves (evidence: `src/app.js`)
- Local and remote service → History cache: caches months (evidence: `src/service.js`)
- Local and remote service → Month history: requests history (evidence: `src/service.js`)
- Month history → History cache: loads months (evidence: `src/modules/history/application/get-month-history.js`)
- LIFF web app → CSV and JSON transfer: exports and imports (evidence: `src/app.js`)
- Nurse → LIFF web app: downloads PDF (evidence: `README.md`)
- Local and remote service → App API endpoint: posts actions (evidence: `src/service.js`)
- App API endpoint → HTTP responses: formats responses (evidence: `supabase/functions/app-api/index.ts`)
- App API endpoint → API actions: dispatches (evidence: `supabase/functions/app-api/index.ts`)
- App API endpoint → User state repository: loads and saves state (evidence: `supabase/functions/app-api/index.ts`)
- API actions → State validation: validates state (evidence: `supabase/functions/_shared/application/app-api-actions.js`)
- API actions → Notification rules: updates rules (evidence: `supabase/functions/_shared/application/app-api-actions.js`)
- API actions → History use case: requests history (evidence: `supabase/functions/app-api/index.ts`)
- History use case → History repository: reads month (evidence: `supabase/functions/_shared/application/get-month-history.js`)
- Reminder function → Schedule calculation: claims due jobs (evidence: `supabase/functions/send-reminders/index.ts`)
- Reminder function → Expiration notices: checks expiration (evidence: `supabase/functions/send-reminders/index.ts`)
- Reminder function → LINE delivery: sends notices (evidence: `supabase/functions/send-reminders/index.ts`)
- LINE delivery → LINE platform: pushes message (evidence: `supabase/functions/_shared/line-delivery.js`)
- Nurse → LINE platform: configures reminders (evidence: `README.md`)
- LINE platform → LINE webhook: posts events (evidence: `README.md`)
- LINE webhook → LINE bot responses: routes postbacks (evidence: `supabase/functions/line-webhook/index.ts`)
- LINE bot responses → LINE platform: replies (evidence: `README.md`)
