# vishalpriyans/unofficial_optiqueue architecture

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

- Interactive diagram: https://gitdiagram.com/vishalpriyans/unofficial_optiqueue
- Repository: https://github.com/vishalpriyans/unofficial_optiqueue

## Overview

#### Purpose and Runtime
OptiQueue is a Next.js 15 / React 19 operating-theatre scheduling prototype. It models case scheduling, OT utilization, conflicts, and emergency insertion primarily in browser-side TypeScript. The main application entry is `app/page.tsx`; global application composition and styling begin at `app/layout.tsx` and `app/globals.css`.

#### Application Surfaces and Roles
The app contains a control-tower workflow plus separate doctor and administrator experiences. Primary route boundaries are:
- Main scheduler/control tower: `app/page.tsx`
- Doctor dashboard and portal: `app/doctor-dashboard/page.tsx`, `app/doctor/page.tsx`
- Administrative dashboard: `app/admin-dashboard/page.tsx`
- Role-specific login routes: `app/doctor-login/page.tsx`, `app/admin-login/page.tsx`

#### Scheduling Domain State
The central scheduling model, sample cases, and local client state are organized in:
- `components/optiqueue/types.ts`
- `components/optiqueue/store.ts`
- `components/optiqueue/sample-data.ts`

UI actions load/add/remove cases through the local store, then feed case and resource data into scheduling, visualization, conflict, KPI, and notification features. This is prototype-local state rather than a persistent schedule database.

#### Optimization and Priority Pipeline
The scheduling engine assigns cases to theatres and times using heuristic logic, priority, and turnover considerations:
- `components/optiqueue/scheduler.ts`
- `components/optiqueue/priority-engine.ts`
- `components/optiqueue/predictor.ts`

This is the principal decision boundary: scheduling logic is TypeScript colocated with presentation components and can later move behind serverless APIs. The README identifies no current durable backend or queueing infrastructure.

#### Conflict and Emergency Handling
Generated or loaded schedules are evaluated for time, theatre, surgeon, equipment, and priority conflicts. Conflicts are surfaced for interactive review and resolution:
- `components/optiqueue/conflict-detector.ts`
- `components/optiqueue/conflict-analysis-dashboard.tsx`
- `components/optiqueue/conflict-display.tsx`

Emergency insertion is a separate rescheduling path that introduces urgent cases, then invokes emergency scheduling/replanning behavior:
- `components/optiqueue/emergency-inserter.tsx`
- `components/optiqueue/emergency-scheduler.ts`
- `components/optiqueue/constraint-checker.tsx`

#### Operational Visualization and Doctor Workflow
Schedule outputs are rendered as a Gantt/timeline control tower with utilization and KPI views:
- `components/optiqueue/gantt.tsx`
- `components/optiqueue/utilization-dashboard.tsx`
- `components/optiqueue/control-tower-kpis.tsx`

The doctor-facing workflow has separate sample data and store boundaries, supporting case cards, surgeon timelines, and emergency assistance:
- `components/optiqueue/doctor/doctor-dashboard.tsx`
- `components/optiqueue/doctor/store.ts`
- `components/optiqueue/doctor/surgeon-timeline.tsx`

#### Auth, Assistant, and External Boundaries
Next App Router route handlers expose authentication/session and assistant endpoints:
- `app/api/auth/admin-login/route.ts`
- `app/api/auth/check-session/route.ts`
- `app/api/assistant/route.ts`

Client-side protection appears in `components/auth/session-protection.tsx` and `components/optiqueue/auth/protected-route.tsx`. Notifications are abstracted as a local service/UI layer in `components/optiqueue/notifications/notification-service.ts`; no concrete database, identity provider, messaging provider, or AI provider is evident from the supplied tree.

Main entry points: [`components/optiqueue/store.ts`](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/store.ts) (Schedule state), [`components/optiqueue/scheduler.ts`](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/scheduler.ts) (Scheduling engine), [`app/layout.tsx`](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/layout.tsx) (App composition), [`app/page.tsx`](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/page.tsx) (Control tower)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["Application surfaces"]
  node_layout["App composition<br/>Next.js layout<br/>[layout.tsx]"]
  node_control_tower["Control tower<br/>scheduler route<br/>[page.tsx]"]
  node_doctor_dashboard_route["Doctor dashboard<br/>doctor route<br/>[page.tsx]"]
  node_doctor_portal["Doctor portal<br/>doctor route<br/>[page.tsx]"]
  node_admin_dashboard["Admin dashboard<br/>admin route<br/>[page.tsx]"]
  node_login_routes["Role login routes<br/>[page.tsx]"]
end

subgraph group_scheduling["Scheduling core"]
  node_schedule_state[("Schedule state<br/>local client store<br/>[store.ts]")]
  node_sample_cases["Sample cases<br/>seed data<br/>[sample-data.ts]"]
  node_scheduler{{"Scheduling engine<br/>heuristic scheduler<br/>[scheduler.ts]"}}
  node_priority_pipeline{{"Priority and prediction<br/>decision logic<br/>[priority-engine.ts]"}}
  node_conflict_review["Conflict review<br/>conflict analysis UI"]
  node_emergency_replan["Emergency replanning<br/>emergency workflow"]
  node_operations_views["Operational views<br/>Gantt and KPI UI<br/>[gantt.tsx]"]
  node_notifications["Notifications<br/>local notification service"]
end

subgraph group_doctor["Doctor workflow"]
  node_doctor_store[("Doctor state<br/>local client store<br/>[store.ts]")]
  node_doctor_workspace["Doctor workspace<br/>doctor dashboard UI"]
end

subgraph group_api["Route handlers"]
  node_session_protection["Session protection<br/>client auth guard"]
  node_auth_api["Auth session API<br/>route handler<br/>[route.ts]"]
  node_assistant_api["Assistant API<br/>route handler<br/>[route.ts]"]
end

node_layout -->|"composes"| node_control_tower
node_layout -->|"composes"| node_doctor_dashboard_route
node_layout -->|"composes"| node_admin_dashboard
node_sample_cases -->|"loads"| node_schedule_state
node_control_tower -->|"reads and updates"| node_schedule_state
node_schedule_state -->|"cases and resources"| node_scheduler
node_priority_pipeline -->|"priority inputs"| node_scheduler
node_scheduler -->|"schedule assignments"| node_schedule_state
node_schedule_state -->|"evaluates schedule"| node_conflict_review
node_schedule_state -->|"renders schedule"| node_operations_views
node_emergency_replan -->|"replans urgent case"| node_scheduler
node_emergency_replan -->|"checks revised schedule"| node_conflict_review
node_conflict_review -->|"surfaces alerts"| node_notifications
node_doctor_dashboard_route -->|"renders"| node_doctor_workspace
node_doctor_portal -->|"renders"| node_doctor_workspace
node_doctor_workspace -->|"reads and updates"| node_doctor_store
node_session_protection -->|"checks session"| node_auth_api
node_login_routes -->|"authenticates"| node_auth_api
node_admin_dashboard -->|"protected by"| node_session_protection
node_control_tower -.->|"assistant requests"| node_assistant_api

click node_layout "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/layout.tsx"
click node_control_tower "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/page.tsx"
click node_doctor_dashboard_route "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor-dashboard/page.tsx"
click node_doctor_portal "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor/page.tsx"
click node_admin_dashboard "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/admin-dashboard/page.tsx"
click node_login_routes "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor-login/page.tsx"
click node_schedule_state "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/store.ts"
click node_sample_cases "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/sample-data.ts"
click node_scheduler "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/scheduler.ts"
click node_priority_pipeline "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/priority-engine.ts"
click node_conflict_review "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/conflict-analysis-dashboard.tsx"
click node_emergency_replan "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/emergency-inserter.tsx"
click node_operations_views "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/gantt.tsx"
click node_notifications "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/notifications/notification-service.ts"
click node_doctor_store "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/doctor/store.ts"
click node_doctor_workspace "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/doctor/doctor-dashboard.tsx"
click node_session_protection "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/auth/session-protection.tsx"
click node_auth_api "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/api/auth/check-session/route.ts"
click node_assistant_api "https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/api/assistant/route.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_layout,node_control_tower,node_doctor_dashboard_route,node_doctor_portal,node_admin_dashboard,node_login_routes toneBlue
class node_schedule_state,node_sample_cases,node_scheduler,node_priority_pipeline,node_conflict_review,node_emergency_replan,node_operations_views,node_notifications toneAmber
class node_doctor_store,node_doctor_workspace toneMint
class node_session_protection,node_auth_api,node_assistant_api toneRose
```

## Components

### Application surfaces

- [App composition](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/layout.tsx): Next.js layout · Sets global application composition and styling. · `app/layout.tsx`
- [Control tower](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/page.tsx): scheduler route · Primary theatre scheduling workspace. · `app/page.tsx`
- [Doctor dashboard](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor-dashboard/page.tsx): doctor route · `app/doctor-dashboard/page.tsx`
- [Doctor portal](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor/page.tsx): doctor route · `app/doctor/page.tsx`
- [Admin dashboard](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/admin-dashboard/page.tsx): admin route · `app/admin-dashboard/page.tsx`
- [Role login routes](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/doctor-login/page.tsx): login routes · `app/doctor-login/page.tsx`

### Scheduling core

Browser-local scheduling and operational analysis.

- [Schedule state](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/store.ts): local client store · Holds cases and prototype-local schedule state. · `components/optiqueue/store.ts`
- [Sample cases](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/sample-data.ts): seed data · `components/optiqueue/sample-data.ts`
- [Scheduling engine](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/scheduler.ts): heuristic scheduler · Assigns cases to theatres and times. · `components/optiqueue/scheduler.ts`
- [Priority and prediction](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/priority-engine.ts): decision logic · Supplies priority and predictive inputs to scheduling. · `components/optiqueue/priority-engine.ts`
- [Conflict review](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/conflict-analysis-dashboard.tsx): conflict analysis UI · Detects and presents time, resource, and priority conflicts. · `components/optiqueue/conflict-analysis-dashboard.tsx`
- [Emergency replanning](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/emergency-inserter.tsx): emergency workflow · Inserts urgent cases and validates replanned schedules. · `components/optiqueue/emergency-inserter.tsx`
- [Operational views](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/gantt.tsx): Gantt and KPI UI · Renders timeline, utilization, and control-tower KPIs. · `components/optiqueue/gantt.tsx`
- [Notifications](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/notifications/notification-service.ts): local notification service · `components/optiqueue/notifications/notification-service.ts`

### Doctor workflow

- [Doctor state](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/doctor/store.ts): local client store · Separate doctor-facing sample data and state boundary. · `components/optiqueue/doctor/store.ts`
- [Doctor workspace](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/optiqueue/doctor/doctor-dashboard.tsx): doctor dashboard UI · Supports case cards, surgeon timelines, and emergency assistance. · `components/optiqueue/doctor/doctor-dashboard.tsx`

### Route handlers

App Router endpoints with no identified external provider.

- [Session protection](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/components/auth/session-protection.tsx): client auth guard · `components/auth/session-protection.tsx`
- [Auth session API](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/api/auth/check-session/route.ts): route handler · Handles admin login and session checks. · `app/api/auth/check-session/route.ts`
- [Assistant API](https://github.com/vishalpriyans/unofficial_optiqueue/blob/main/app/api/assistant/route.ts): route handler · Assistant endpoint; no AI provider is identified. · `app/api/assistant/route.ts`

## Connections

- App composition → Control tower: composes
- App composition → Doctor dashboard: composes
- App composition → Admin dashboard: composes
- Sample cases → Schedule state: loads
- Control tower → Schedule state: reads and updates
- Schedule state → Scheduling engine: cases and resources
- Priority and prediction → Scheduling engine: priority inputs
- Scheduling engine → Schedule state: schedule assignments
- Schedule state → Conflict review: evaluates schedule
- Schedule state → Operational views: renders schedule
- Emergency replanning → Scheduling engine: replans urgent case
- Emergency replanning → Conflict review: checks revised schedule
- Conflict review → Notifications: surfaces alerts
- Doctor dashboard → Doctor workspace: renders
- Doctor portal → Doctor workspace: renders
- Doctor workspace → Doctor state: reads and updates
- Session protection → Auth session API: checks session
- Role login routes → Auth session API: authenticates
- Admin dashboard → Session protection: protected by
- Control tower → Assistant API: assistant requests
