# ddaza-cell/onduty architecture

> Architecture diagram of the GitHub repository ddaza-cell/onduty, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ddaza-cell/onduty
- Repository: https://github.com/ddaza-cell/onduty

## Overview

#### Purpose and entry points
OnDuty is a medical-staff attendance, scheduling, and payroll PWA. The React client starts at `frontend/src/main.jsx` and composes routes/UI through `frontend/src/App.jsx`. The Express API starts from `backend/src/index.js`, configures application middleware/routes in `backend/src/app.js`, and persists operational data through Prisma.

#### Client application and access boundary
The frontend is a Vite React PWA with protected, role-aware workflows. Authentication state is centralized in `frontend/src/store/authStore.js`; API requests use `frontend/src/services/api.js`; route access is enforced by `frontend/src/components/ProtectedRoute.jsx` and administrative dashboard access by `frontend/src/components/AdminGuardDashboard.jsx`. Primary user surfaces cover attendance, schedules, swaps/cessions, payroll, reporting, and administration under `frontend/src/pages/`.

#### Identity, authorization, and sessions
The backend auth module provides JWT access/refresh flows and role-based access for employee, supervisor, and admin actors. Route/service boundaries reside in `backend/src/modules/auth/auth.routes.js` and `backend/src/modules/auth/auth.service.js`; shared request authentication is in `backend/src/middlewares/auth.js`. Redis (`backend/src/redis.js`) supports refresh-token allowlisting/revocation and is an infrastructure dependency alongside the primary database.

#### Biometric enrollment and attendance
Attendance is a controlled pipeline: the browser captures camera input and performs liveness/descriptor work (`frontend/src/components/FaceCapture.jsx`, `frontend/src/modules/biometric/liveness.js`), then calls backend biometric and attendance endpoints (`backend/src/modules/biometric/biometric.routes.js`, `backend/src/modules/attendance/attendance.routes.js`). CompreFace is the authoritative external Docker service for facial recognition decisions. The backend also encrypts optional client-generated facial descriptor backups through `backend/src/modules/biometric/crypto.service.js`; models are packaged under `backend/public/models/` and `frontend/public/models/`.

#### Shift operations and coverage lifecycle
Scheduling supports rotation templates, assignments, vacancies, substitutions, swaps, and full/partial T24 cessions. The API is separated by workflow in `backend/src/modules/shifts/shift.routes.js`, `backend/src/modules/shifts/swap.routes.js`, and `backend/src/modules/shifts/cession.routes.js`, with cession business logic in `backend/src/services/cession.service.js`. Corresponding employee-facing interaction points include `frontend/src/components/ShiftSwapPanel.jsx` and `frontend/src/components/ShiftCessionPanel.jsx`; supervisors administer schedules from `frontend/src/pages/AdminShiftManagementPage.jsx`.

#### Payroll, reporting, and time automation
Attendance and shift records feed payroll calculation, holiday/shift premiums, projections, and closure via `backend/src/modules/pay/pay.routes.js` and `backend/src/services/pay.service.js`. Users access individual and administrative payroll through `frontend/src/pages/MyPayPage.jsx` and `frontend/src/pages/PayrollPage.jsx`. A background automatic-checkout process in `backend/src/jobs/autoCheckout.job.js` manages time-bound attendance completion independently of browser sessions.

#### Realtime delivery, offline behavior, and deployment
Socket.io integration (`backend/src/socket.js`, `frontend/src/hooks/useSocket.js`) provides realtime operational events. Web Push is handled by `backend/src/modules/push/push.routes.js`, `backend/src/services/push.service.js`, and service worker `frontend/public/sw-push.js`; email delivery is isolated in `backend/src/services/email.service.js`. The client queues offline operations in `frontend/src/services/offlineQueue.js`, critical for attendance continuity. Docker Compose defines the multi-service runtime in `docker-compose.yml` and production variant `docker-compose.prod.yml`; Nginx configuration is at `nginx/nginx.conf`. Prisma schema and migrations define the relational boundary in `backend/prisma/schema.prisma`.

Main entry points: [`backend/src/app.js`](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/app.js) (Express application), [`frontend/src/App.jsx`](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/App.jsx) (React application), [`backend/src/modules/attendance/attendance.routes.js`](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/attendance/attendance.routes.js) (Biometric attendance), [`backend/prisma/schema.prisma`](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/prisma/schema.prisma) (Operational database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React PWA"]
  node_client_app["React application<br/>PWA shell<br/>[App.jsx]"]
  node_auth_store["Auth state<br/>client store<br/>[authStore.js]"]
  node_client_api["API client<br/>HTTP client<br/>[api.js]"]
  node_route_guards["Route guards<br/>access control<br/>[ProtectedRoute.jsx]"]
  node_face_capture["Face capture &amp; liveness<br/>biometric client<br/>[FaceCapture.jsx]"]
  node_offline_queue["Offline operation queue<br/>client queue<br/>[offlineQueue.js]"]
  node_client_realtime["Socket client<br/>realtime hook<br/>[useSocket.js]"]
end

subgraph group_api["Express API"]
  node_server_app["Express application<br/>API composition<br/>[app.js]"]
  node_auth_module["Authentication<br/>auth module<br/>[auth.routes.js]"]
  node_auth_middleware["Request authentication<br/>middleware<br/>[auth.js]"]
  node_socket_server["Socket server<br/>realtime transport<br/>[socket.js]"]
end

subgraph group_operations["Operational Workflows"]
  node_biometric_attendance["Biometric attendance<br/>API workflows"]
  node_shift_workflows["Shift coverage<br/>API workflows<br/>[shift.routes.js]"]
  node_payroll["Payroll calculation<br/>pay service<br/>[pay.service.js]"]
  node_auto_checkout["Automatic checkout<br/>background job"]
  node_notifications["Push &amp; email delivery<br/>notification services<br/>[push.service.js]"]
end

subgraph group_infra["Data &amp; Delivery"]
  node_prisma_db[("Operational database<br/>Prisma relational data<br/>[schema.prisma]")]
  node_redis[("Redis<br/>session store<br/>[redis.js]")]
  node_compreface{{"CompreFace<br/>face recognition service"}}
  node_deployment["Docker Compose &amp; Nginx<br/>runtime deployment<br/>[docker-compose.yml]"]
end

node_client_app -->|"uses"| node_auth_store
node_client_app -->|"protects routes with"| node_route_guards
node_client_app -->|"calls"| node_client_api
node_client_app -->|"hosts"| node_face_capture
node_offline_queue -->|"replays operations"| node_client_api
node_client_realtime -->|"realtime events"| node_socket_server
node_client_api -->|"HTTPS requests"| node_server_app
node_server_app -->|"routes auth"| node_auth_module
node_server_app -->|"applies"| node_auth_middleware
node_server_app -->|"routes"| node_biometric_attendance
node_server_app -->|"routes"| node_shift_workflows
node_server_app -->|"routes"| node_payroll
node_auth_module -->|"refresh token state"| node_redis
node_auth_module -->|"identity data"| node_prisma_db
node_biometric_attendance -->|"recognition decision"| node_compreface
node_biometric_attendance -->|"attendance records"| node_prisma_db
node_shift_workflows -->|"shift records"| node_prisma_db
node_payroll -->|"reads attendance and shifts"| node_prisma_db
node_auto_checkout -->|"completes attendance"| node_biometric_attendance
node_socket_server -->|"operational events"| node_client_realtime
node_notifications -->|"web push"| node_client_app
node_deployment -->|"runs API"| node_server_app
node_deployment -->|"runs service"| node_compreface

click node_client_app "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/App.jsx"
click node_auth_store "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/store/authStore.js"
click node_client_api "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/services/api.js"
click node_route_guards "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/components/ProtectedRoute.jsx"
click node_face_capture "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/components/FaceCapture.jsx"
click node_offline_queue "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/services/offlineQueue.js"
click node_client_realtime "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/hooks/useSocket.js"
click node_server_app "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/app.js"
click node_auth_module "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/auth/auth.routes.js"
click node_auth_middleware "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/middlewares/auth.js"
click node_biometric_attendance "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/attendance/attendance.routes.js"
click node_shift_workflows "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/shifts/shift.routes.js"
click node_payroll "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/services/pay.service.js"
click node_auto_checkout "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/jobs/autoCheckout.job.js"
click node_notifications "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/services/push.service.js"
click node_socket_server "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/socket.js"
click node_prisma_db "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/prisma/schema.prisma"
click node_redis "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/redis.js"
click node_deployment "https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/docker-compose.yml"

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_client_app,node_auth_store,node_client_api,node_route_guards,node_face_capture,node_offline_queue,node_client_realtime toneBlue
class node_server_app,node_auth_module,node_auth_middleware,node_socket_server toneAmber
class node_biometric_attendance,node_shift_workflows,node_payroll,node_auto_checkout,node_notifications toneMint
class node_prisma_db,node_redis,node_compreface,node_deployment toneRose
```

## Components

### React PWA

- [React application](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/App.jsx): PWA shell · Routes and role-aware user workflows. · `frontend/src/App.jsx`
- [Auth state](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/store/authStore.js): client store · `frontend/src/store/authStore.js`
- [API client](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/services/api.js): HTTP client · `frontend/src/services/api.js`
- [Route guards](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/components/ProtectedRoute.jsx): access control · `frontend/src/components/ProtectedRoute.jsx`
- [Face capture & liveness](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/components/FaceCapture.jsx): biometric client · `frontend/src/components/FaceCapture.jsx`
- [Offline operation queue](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/services/offlineQueue.js): client queue · Preserves operations during connectivity loss. · `frontend/src/services/offlineQueue.js`
- [Socket client](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/frontend/src/hooks/useSocket.js): realtime hook · `frontend/src/hooks/useSocket.js`

### Express API

- [Express application](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/app.js): API composition · Middleware and module route registration. · `backend/src/app.js`
- [Authentication](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/auth/auth.routes.js): auth module · JWT access/refresh flows and role authorization. · `backend/src/modules/auth/auth.routes.js`
- [Request authentication](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/middlewares/auth.js): middleware · `backend/src/middlewares/auth.js`
- [Socket server](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/socket.js): realtime transport · `backend/src/socket.js`

### Operational Workflows

- [Biometric attendance](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/attendance/attendance.routes.js): API workflows · Enrollment, recognition, and attendance endpoints. · `backend/src/modules/attendance/attendance.routes.js`
- [Shift coverage](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/modules/shifts/shift.routes.js): API workflows · Assignments, swaps, and T24 cessions. · `backend/src/modules/shifts/shift.routes.js`
- [Payroll calculation](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/services/pay.service.js): pay service · Calculates premiums, projections, and closures. · `backend/src/services/pay.service.js`
- [Automatic checkout](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/jobs/autoCheckout.job.js): background job · Completes time-bound attendance independently of sessions. · `backend/src/jobs/autoCheckout.job.js`
- [Push & email delivery](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/services/push.service.js): notification services · `backend/src/services/push.service.js`

### Data & Delivery

- [Operational database](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/prisma/schema.prisma): Prisma relational data · Primary persistence boundary for operational records. · `backend/prisma/schema.prisma`
- [Redis](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/backend/src/redis.js): session store · Refresh-token allowlisting and revocation. · `backend/src/redis.js`
- **CompreFace**: face recognition service · Authoritative facial recognition decision service.
- [Docker Compose & Nginx](https://github.com/ddaza-cell/onduty/blob/ui-gestion-turnos/docker-compose.yml): runtime deployment · Multi-service runtime and reverse proxy boundary. · `docker-compose.yml`

## Connections

- React application → Auth state: uses
- React application → Route guards: protects routes with
- React application → API client: calls
- React application → Face capture & liveness: hosts
- Offline operation queue → API client: replays operations
- Socket client → Socket server: realtime events
- API client → Express application: HTTPS requests
- Express application → Authentication: routes auth
- Express application → Request authentication: applies
- Express application → Biometric attendance: routes
- Express application → Shift coverage: routes
- Express application → Payroll calculation: routes
- Authentication → Redis: refresh token state
- Authentication → Operational database: identity data
- Biometric attendance → CompreFace: recognition decision
- Biometric attendance → Operational database: attendance records
- Shift coverage → Operational database: shift records
- Payroll calculation → Operational database: reads attendance and shifts
- Automatic checkout → Biometric attendance: completes attendance
- Socket server → Socket client: operational events
- Push & email delivery → React application: web push
- Docker Compose & Nginx → Express application: runs API
- Docker Compose & Nginx → CompreFace: runs service
