# greenqubes/greenqubes-ops architecture

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

- Interactive diagram: https://gitdiagram.com/greenqubes/greenqubes-ops
- Repository: https://github.com/greenqubes/greenqubes-ops
- Video tour (about a minute): https://gitdiagram.com/greenqubes/greenqubes-ops/video

## Overview

This repository is a role-based job-operations web application, supporting jobs from creation and design through scheduling, installation, and completion, with related leave, approvals, file, and communication workflows. It also includes an AI assistant, document scanning, and operational administration. The supplied README is empty, so product capabilities are inferred from the file tree; edges are limited to relationships shown in excerpts or SOURCE INDEX references. Several unsampled UI and API subsystems are represented without speculative connections.

Main entry points: [`src/app/api/assistant/chat/route.ts`](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/assistant/chat/route.ts) (Assistant chat API), [`src/app/api/jobs/[id]/route.ts`](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/jobs/%5Bid%5D/route.ts) (Job operations API), [`src/app/api/bugs/route.ts`](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/bugs/route.ts) (Bug reporting), [`src/lib/storage/r2.ts`](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/storage/r2.ts) (Object storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_jobs["Job lifecycle"]
  node_job_create["Job intake<br/>[NewJobShell.tsx]"]
  node_job_detail["Job details<br/>[JobDetailShell.tsx]"]
  node_job_api["Job operations API<br/>[route.ts]"]
  node_stage_rules["Stage rules<br/>[job-stage.ts]"]
  node_design_score["Design scoring<br/>[design-score.ts]"]
  node_scan_ui["Document scanning<br/>[ScanModal.tsx]"]
  node_scan_worker["Scan worker<br/>[scan.worker.ts]"]
  node_scan_pipeline["Image processing<br/>[pipeline.ts]"]
end

subgraph group_operations["Scheduling and operations"]
  node_schedule["Schedule board<br/>[ScheduleShell.tsx]"]
  node_stages["Stage management<br/>[StageListShell.tsx]"]
  node_arrange["Job arrangement<br/>[ArrangeCard.tsx]"]
  node_approvals["Approvals"]
  node_installer["Installer workflows<br/>[InstallerShell.tsx]"]
  node_leave["Leave and events<br/>[LeaveShell.tsx]"]
end

subgraph group_assistance["AI and files"]
  node_assistant_ui["Assistant workspace<br/>[AssistantShell.tsx]"]
  node_assistant_api["Assistant chat API<br/>[route.ts]"]
  node_retrieval["Chat retrieval<br/>[retrieve.ts]"]
  node_tool_runner["Assistant tools<br/>[tool-runner.ts]"]
  node_object_storage[("Object storage<br/>[r2.ts]")]
end

subgraph group_platform["Platform services"]
  node_admin["Administration<br/>[page.tsx]"]
  node_bug_reports["Bug reporting<br/>[route.ts]"]
  node_telegram["Telegram bot<br/>[bot.ts]"]
  node_database[("Supabase data<br/>[service.ts]")]
  node_session_client["Session client<br/>[server.ts]"]
end

node_user(("Staff user"))
node_external_storage[("Cloudflare R2")]

node_user -.->|"starts intake"| node_job_create
node_job_create -.->|"opens job"| node_job_detail
node_job_detail -.->|"updates job"| node_job_api
node_job_api -->|"checks stages"| node_stage_rules
node_job_api -->|"scores design"| node_design_score
node_job_api -->|"uses service client"| node_database
node_scan_ui -.->|"starts scan"| node_scan_worker
node_scan_worker -->|"processes page"| node_scan_pipeline
node_scan_pipeline -->|"uses image tools"| node_object_storage
node_schedule -.->|"loads job data"| node_job_api
node_user -.->|"coordinates work"| node_schedule
node_user -.->|"manages stages"| node_stages
node_user -.->|"arranges jobs"| node_arrange
node_user -.->|"resolves clashes"| node_approvals
node_user -.->|"handles installation"| node_installer
node_user -.->|"records leave"| node_leave
node_assistant_ui -.->|"sends chat"| node_assistant_api
node_assistant_api -->|"authenticates"| node_session_client
node_assistant_api -->|"retrieves chats"| node_retrieval
node_assistant_api -->|"executes tools"| node_tool_runner
node_assistant_api -->|"loads attachments"| node_object_storage
node_object_storage -->|"stores objects"| node_external_storage
node_user -.->|"administers system"| node_admin
node_user -.->|"reports issue"| node_bug_reports
node_bug_reports -->|"notifies team"| node_telegram
node_bug_reports -->|"resolves screenshot"| node_object_storage
node_bug_reports -->|"records report"| node_database
node_session_client -.->|"connects session"| node_database
node_admin -.->|"reviews scores"| node_design_score

click node_job_create "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/job-detail/NewJobShell.tsx"
click node_job_detail "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/job-detail/JobDetailShell.tsx"
click node_job_api "https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/jobs/%5Bid%5D/route.ts"
click node_stage_rules "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/utils/job-stage.ts"
click node_design_score "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/design-score.ts"
click node_scan_ui "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/scan/ScanModal.tsx"
click node_scan_worker "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/scan/scan.worker.ts"
click node_scan_pipeline "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/scan/pipeline.ts"
click node_schedule "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/schedule/ScheduleShell.tsx"
click node_stages "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/stages/StageListShell.tsx"
click node_arrange "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/arrange/ArrangeCard.tsx"
click node_approvals "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/approvals/ClashResolutionModal.tsx"
click node_installer "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/installer/InstallerShell.tsx"
click node_leave "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/leave/LeaveShell.tsx"
click node_assistant_ui "https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/assistant/AssistantShell.tsx"
click node_assistant_api "https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/assistant/chat/route.ts"
click node_retrieval "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/retrieve.ts"
click node_tool_runner "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/tool-runner.ts"
click node_object_storage "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/storage/r2.ts"
click node_admin "https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/admin/page.tsx"
click node_bug_reports "https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/bugs/route.ts"
click node_telegram "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/telegram/bot.ts"
click node_database "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/supabase/service.ts"
click node_session_client "https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/supabase/server.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_job_create,node_job_detail,node_job_api,node_stage_rules,node_design_score,node_scan_ui,node_scan_worker,node_scan_pipeline,node_user toneBlue
class node_schedule,node_stages,node_arrange,node_approvals,node_installer,node_leave,node_external_storage toneAmber
class node_assistant_ui,node_assistant_api,node_retrieval,node_tool_runner,node_object_storage toneMint
class node_admin,node_bug_reports,node_telegram,node_database,node_session_client toneRose
```

## Components

### Job lifecycle

- [Job intake](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/job-detail/NewJobShell.tsx): `src/features/job-detail/NewJobShell.tsx`
- [Job details](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/job-detail/JobDetailShell.tsx): `src/features/job-detail/JobDetailShell.tsx`
- [Job operations API](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/jobs/%5Bid%5D/route.ts): `src/app/api/jobs/[id]/route.ts`
- [Stage rules](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/utils/job-stage.ts): `src/lib/utils/job-stage.ts`
- [Design scoring](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/design-score.ts): `src/lib/ai/design-score.ts`
- [Document scanning](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/scan/ScanModal.tsx): `src/features/scan/ScanModal.tsx`
- [Scan worker](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/scan/scan.worker.ts): `src/features/scan/scan.worker.ts`
- [Image processing](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/scan/pipeline.ts): `src/lib/scan/pipeline.ts`

### Scheduling and operations

- [Schedule board](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/schedule/ScheduleShell.tsx): `src/features/schedule/ScheduleShell.tsx`
- [Stage management](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/stages/StageListShell.tsx): `src/features/stages/StageListShell.tsx`
- [Job arrangement](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/arrange/ArrangeCard.tsx): `src/features/arrange/ArrangeCard.tsx`
- [Approvals](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/approvals/ClashResolutionModal.tsx): `src/features/approvals/ClashResolutionModal.tsx`
- [Installer workflows](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/installer/InstallerShell.tsx): `src/features/installer/InstallerShell.tsx`
- [Leave and events](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/leave/LeaveShell.tsx): `src/features/leave/LeaveShell.tsx`

### AI and files

- [Assistant workspace](https://github.com/greenqubes/greenqubes-ops/blob/main/src/features/assistant/AssistantShell.tsx): `src/features/assistant/AssistantShell.tsx`
- [Assistant chat API](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/assistant/chat/route.ts): `src/app/api/assistant/chat/route.ts`
- [Chat retrieval](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/retrieve.ts): `src/lib/ai/retrieve.ts`
- [Assistant tools](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/ai/tool-runner.ts): `src/lib/ai/tool-runner.ts`
- [Object storage](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/storage/r2.ts): `src/lib/storage/r2.ts`

### Platform services

- [Administration](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/admin/page.tsx): `src/app/admin/page.tsx`
- [Bug reporting](https://github.com/greenqubes/greenqubes-ops/blob/main/src/app/api/bugs/route.ts): `src/app/api/bugs/route.ts`
- [Telegram bot](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/telegram/bot.ts): `src/lib/telegram/bot.ts`
- [Supabase data](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/supabase/service.ts): `src/lib/supabase/service.ts`
- [Session client](https://github.com/greenqubes/greenqubes-ops/blob/main/src/lib/supabase/server.ts): `src/lib/supabase/server.ts`

### Other components

- **Staff user**
- **Cloudflare R2**

## Connections

- Staff user → Job intake: starts intake
- Job intake → Job details: opens job
- Job details → Job operations API: updates job
- Job operations API → Stage rules: checks stages (evidence: `src/app/api/jobs/[id]/route.ts`)
- Job operations API → Design scoring: scores design (evidence: `src/app/api/jobs/[id]/route.ts`)
- Job operations API → Supabase data: uses service client (evidence: `src/app/api/jobs/[id]/route.ts`)
- Document scanning → Scan worker: starts scan
- Scan worker → Image processing: processes page (evidence: `src/features/scan/scan.worker.ts`)
- Image processing → Object storage: uses image tools (evidence: `src/lib/scan/pipeline.ts`)
- Schedule board → Job operations API: loads job data
- Staff user → Schedule board: coordinates work
- Staff user → Stage management: manages stages
- Staff user → Job arrangement: arranges jobs
- Staff user → Approvals: resolves clashes
- Staff user → Installer workflows: handles installation
- Staff user → Leave and events: records leave
- Assistant workspace → Assistant chat API: sends chat
- Assistant chat API → Session client: authenticates (evidence: `src/app/api/assistant/chat/route.ts`)
- Assistant chat API → Chat retrieval: retrieves chats (evidence: `src/app/api/assistant/chat/route.ts`)
- Assistant chat API → Assistant tools: executes tools (evidence: `src/app/api/assistant/chat/route.ts`)
- Assistant chat API → Object storage: loads attachments (evidence: `src/app/api/assistant/chat/route.ts`)
- Object storage → Cloudflare R2: stores objects (evidence: `src/lib/storage/r2.ts`)
- Staff user → Administration: administers system
- Staff user → Bug reporting: reports issue
- Bug reporting → Telegram bot: notifies team (evidence: `src/app/api/bugs/route.ts`)
- Bug reporting → Object storage: resolves screenshot (evidence: `src/app/api/bugs/route.ts`)
- Bug reporting → Supabase data: records report (evidence: `src/app/api/bugs/route.ts`)
- Session client → Supabase data: connects session
- Administration → Design scoring: reviews scores
