# quantumhash-corporation/quantumhash_ptw architecture

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

- Interactive diagram: https://gitdiagram.com/quantumhash-corporation/quantumhash_ptw
- Repository: https://github.com/quantumhash-corporation/quantumhash_ptw

## Overview

Drilling Group is a role-scoped electronic Permit to Work system. Users sign in, enter role-specific dashboards and workflows, and manage permits through submission, approval, activation, and closure; supporting capabilities include risk assessment, safety evidence, personnel, schedules, reporting, and audit. The React client calls an Express API, whose controllers enforce workflow rules and use services and database access. README documents the broader product scope; sampled source confirms application routing, PTW handling, authentication, and safety-book retrieval, but not every feature’s implementation links.

Main entry points: [`client/src/App.jsx`](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/App.jsx) (App routes), [`server/src/controllers/ptw.controller.js`](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/controllers/ptw.controller.js) (PTW controller), [`server/src/app.js`](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/app.js) (Express API app), [`server/src/routes/ptw.routes.js`](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/routes/ptw.routes.js) (PTW routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App routes<br/>[App.jsx]"]
  node_authctx["Auth context<br/>[AuthContext.jsx]"]
  node_authsvc["Auth client<br/>[auth.service.js]"]
  node_http["API client<br/>[api.js]"]
  node_dashboard["Role dashboards"]
  node_personnel["Personnel management"]
  node_safetyui["Safety documents"]
end

subgraph group_api["API and access"]
  node_serverapp["Express API app<br/>[app.js]"]
  node_authmw["Authentication and permissions<br/>[auth.js]"]
  node_ptwroutes["PTW routes<br/>[ptw.routes.js]"]
  node_jsaroutes["JSA routes<br/>[jsa.routes.js]"]
end

subgraph group_ptw["Permit workflows"]
  node_ptwpages["Permit screens"]
  node_ptwcontroller["PTW controller<br/>[ptw.controller.js]"]
  node_ptwservice["PTW lifecycle service<br/>[ptw.service.js]"]
  node_permitdocs["Permit documents"]
end

subgraph group_safety["Safety evidence"]
  node_safetybooks["Safety-book retrieval"]
  node_embedding["Embedding generation"]
end

subgraph group_data["Persistence and integrations"]
  node_db[("Database access<br/>[index.js]")]
  node_authoritydb[("Authority records<br/>[authorities.js]")]
  node_qdrant["Vector search<br/>[qdrant-client.js]"]
end

node_user(("Role-based user"))
node_embedapi{{"Embedding API"}}

node_user -->|"uses"| node_app
node_app -->|"checks identity"| node_authctx
node_authctx -->|"loads session"| node_authsvc
node_authsvc -->|"sends requests"| node_http
node_app -->|"routes by role"| node_dashboard
node_app -->|"routes permit work"| node_ptwpages
node_user -.->|"manages personnel"| node_personnel
node_user -->|"accesses safety docs"| node_safetyui
node_http -->|"calls API"| node_serverapp
node_serverapp -->|"mounts routes"| node_ptwroutes
node_serverapp -->|"mounts routes"| node_jsaroutes
node_ptwroutes -->|"guards requests"| node_authmw
node_ptwroutes -->|"dispatches to"| node_ptwcontroller
node_ptwcontroller -->|"uses lifecycle logic"| node_ptwservice
node_ptwcontroller -.->|"coordinates documents"| node_permitdocs
node_ptwcontroller -->|"queries"| node_db
node_authmw -->|"loads authority data"| node_authoritydb
node_safetybooks -->|"generates vectors"| node_embedding
node_safetybooks -->|"searches vectors"| node_qdrant
node_embedding -->|"requests embeddings"| node_embedapi

click node_app "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/App.jsx"
click node_authctx "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/context/AuthContext.jsx"
click node_authsvc "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/services/auth.service.js"
click node_http "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/lib/api.js"
click node_dashboard "https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/components/dashboard/roles"
click node_ptwpages "https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/pages/ptw"
click node_personnel "https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/pages/personnel"
click node_safetyui "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/pages/SafetyDocuments.jsx"
click node_serverapp "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/app.js"
click node_authmw "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/middleware/auth.js"
click node_ptwroutes "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/routes/ptw.routes.js"
click node_jsaroutes "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/routes/jsa.routes.js"
click node_ptwcontroller "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/controllers/ptw.controller.js"
click node_ptwservice "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/ptw.service.js"
click node_permitdocs "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/controllers/permitDocuments.controller.js"
click node_safetybooks "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/jsa-safety-book-retrieval.service.js"
click node_embedding "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/embedding.service.js"
click node_db "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/db/index.js"
click node_authoritydb "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/db/authorities.js"
click node_qdrant "https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/qdrant-client.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_authctx,node_authsvc,node_http,node_dashboard,node_personnel,node_safetyui,node_user toneBlue
class node_serverapp,node_authmw,node_ptwroutes,node_jsaroutes toneAmber
class node_ptwpages,node_ptwcontroller,node_ptwservice,node_permitdocs,node_embedapi toneMint
class node_safetybooks,node_embedding toneRose
class node_db,node_authoritydb,node_qdrant toneIndigo
```

## Components

### Web client

- [App routes](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Auth context](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [Auth client](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/services/auth.service.js): `client/src/services/auth.service.js`
- [API client](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/lib/api.js): `client/src/lib/api.js`
- [Role dashboards](https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/components/dashboard/roles): `client/src/components/dashboard/roles`
- [Personnel management](https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/pages/personnel): `client/src/pages/personnel`
- [Safety documents](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/client/src/pages/SafetyDocuments.jsx): `client/src/pages/SafetyDocuments.jsx`

### API and access

- [Express API app](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/app.js): `server/src/app.js`
- [Authentication and permissions](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/middleware/auth.js): `server/src/middleware/auth.js`
- [PTW routes](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/routes/ptw.routes.js): `server/src/routes/ptw.routes.js`
- [JSA routes](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/routes/jsa.routes.js): `server/src/routes/jsa.routes.js`

### Permit workflows

- [Permit screens](https://github.com/quantumhash-corporation/quantumhash_ptw/tree/main/client/src/pages/ptw): `client/src/pages/ptw`
- [PTW controller](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/controllers/ptw.controller.js): `server/src/controllers/ptw.controller.js`
- [PTW lifecycle service](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/ptw.service.js): `server/src/services/ptw.service.js`
- [Permit documents](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/controllers/permitDocuments.controller.js): `server/src/controllers/permitDocuments.controller.js`

### Safety evidence

- [Safety-book retrieval](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/jsa-safety-book-retrieval.service.js): `server/src/services/jsa-safety-book-retrieval.service.js`
- [Embedding generation](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/embedding.service.js): `server/src/services/embedding.service.js`

### Persistence and integrations

- [Database access](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/db/index.js): `server/src/db/index.js`
- [Authority records](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/db/authorities.js): `server/src/db/authorities.js`
- [Vector search](https://github.com/quantumhash-corporation/quantumhash_ptw/blob/main/server/src/services/qdrant-client.js): `server/src/services/qdrant-client.js`

### Other components

- **Role-based user**
- **Embedding API**

## Connections

- Role-based user → App routes: uses (evidence: `README.md`)
- App routes → Auth context: checks identity (evidence: `client/src/App.jsx`)
- Auth context → Auth client: loads session (evidence: `client/src/context/AuthContext.jsx`)
- Auth client → API client: sends requests (evidence: `client/src/services/auth.service.js`)
- App routes → Role dashboards: routes by role (evidence: `client/src/App.jsx`)
- App routes → Permit screens: routes permit work (evidence: `client/src/App.jsx`)
- Role-based user → Personnel management: manages personnel (evidence: `README.md`)
- Role-based user → Safety documents: accesses safety docs
- API client → Express API app: calls API (evidence: `README.md`)
- Express API app → PTW routes: mounts routes (evidence: `server/src/app.js`)
- Express API app → JSA routes: mounts routes (evidence: `server/src/app.js`)
- PTW routes → Authentication and permissions: guards requests (evidence: `server/src/routes/ptw.routes.js`)
- PTW routes → PTW controller: dispatches to (evidence: `server/src/routes/ptw.routes.js`)
- PTW controller → PTW lifecycle service: uses lifecycle logic (evidence: `server/src/controllers/ptw.controller.js`)
- PTW controller → Permit documents: coordinates documents
- PTW controller → Database access: queries (evidence: `server/src/controllers/ptw.controller.js`)
- Authentication and permissions → Authority records: loads authority data (evidence: `server/src/middleware/auth.js`)
- Safety-book retrieval → Embedding generation: generates vectors (evidence: `server/src/services/jsa-safety-book-retrieval.service.js`)
- Safety-book retrieval → Vector search: searches vectors (evidence: `server/src/services/jsa-safety-book-retrieval.service.js`)
- Embedding generation → Embedding API: requests embeddings (evidence: `server/src/services/embedding.service.js`)
