# nrccpak/nrcc-ptw architecture

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

- Interactive diagram: https://gitdiagram.com/nrccpak/nrcc-ptw
- Repository: https://github.com/nrccpak/nrcc-ptw

## Overview

NRCC PTW is an offline-first permit-to-work PWA for requesting, reviewing, and managing work permits and equipment isolations. Its principal workflow is sign-in, permit submission, issuer review, any required isolation assignment and electrician confirmation, then work, de-isolation, and closure. The README also documents shared isolation, trial runs, deadline-based auto-rejection, administrative configuration, and equipment import. The main runtime is concentrated in app.js. Source excerpts show its Firestore access and service-worker caching; some feature relationships are based on README documentation rather than sampled implementation.

Main entry points: [`index.html`](https://github.com/nrccpak/nrcc-ptw/blob/main/index.html) (Application shell), [`app.js`](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js) (Login and roles), [`service-worker.js`](https://github.com/nrccpak/nrcc-ptw/blob/main/service-worker.js) (Offline service worker), [`firestore.rules`](https://github.com/nrccpak/nrcc-ptw/blob/main/firestore.rules) (Firestore rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and interface"]
  node_app_shell["Application shell<br/>[index.html]"]
  node_identity["Login and roles<br/>[app.js]"]
  node_work_dashboard["Role dashboards<br/>[app.js]"]
end

subgraph group_permits["Permit lifecycle"]
  node_permit_request["Permit requests<br/>[app.js]"]
  node_issuer_review["Issuer review<br/>[app.js]"]
  node_permit_expiry["Auto-rejection<br/>[app.js]"]
  node_permit_close["Permit closure<br/>[app.js]"]
end

subgraph group_safety["Isolation safety"]
  node_iso_certificates["Isolation certificates<br/>[app.js]"]
  node_trial_run["Trial-run workflow<br/>[app.js]"]
end

subgraph group_operations["Operations"]
  node_equipment["Equipment register<br/>[app.js]"]
  node_admin_config["Admin configuration<br/>[app.js]"]
end

subgraph group_platform["Offline platform"]
  node_firestore_rules["Firestore rules<br/>[firestore.rules]"]
  node_service_worker["Offline service worker<br/>[service-worker.js]"]
  node_pwa_manifest["PWA manifest"]
end

node_requester(("Permit users"))
node_firebase_auth{{"Firebase Auth"}}
node_firestore[("Firestore data")]

node_requester -->|"uses"| node_app_shell
node_app_shell -->|"loads"| node_identity
node_identity -->|"authenticates"| node_firebase_auth
node_identity -->|"loads profile"| node_firestore
node_identity -->|"renders"| node_work_dashboard
node_work_dashboard -->|"raises permits"| node_permit_request
node_permit_request -->|"writes permits"| node_firestore
node_issuer_review -->|"updates permits"| node_firestore
node_permit_expiry -->|"stamps status"| node_firestore
node_permit_close -->|"updates permits"| node_firestore
node_issuer_review -->|"assigns isolation"| node_iso_certificates
node_iso_certificates -->|"stores certificates"| node_firestore
node_iso_certificates -->|"supports trial run"| node_trial_run
node_iso_certificates -->|"enables closure"| node_permit_close
node_equipment -->|"reads and writes"| node_firestore
node_admin_config -->|"edits configuration"| node_firestore
node_firestore_rules -->|"controls access"| node_firestore
node_app_shell -->|"registers"| node_service_worker
node_service_worker -->|"caches shell"| node_app_shell
node_app_shell -->|"declares installability"| node_pwa_manifest

click node_app_shell "https://github.com/nrccpak/nrcc-ptw/blob/main/index.html"
click node_identity "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_work_dashboard "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_permit_request "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_issuer_review "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_permit_expiry "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_permit_close "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_iso_certificates "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_trial_run "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_equipment "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_admin_config "https://github.com/nrccpak/nrcc-ptw/blob/main/app.js"
click node_firestore_rules "https://github.com/nrccpak/nrcc-ptw/blob/main/firestore.rules"
click node_service_worker "https://github.com/nrccpak/nrcc-ptw/blob/main/service-worker.js"
click node_pwa_manifest "https://github.com/nrccpak/nrcc-ptw/blob/main/manifest.webmanifest"

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_shell,node_identity,node_work_dashboard,node_requester toneBlue
class node_permit_request,node_issuer_review,node_permit_expiry,node_permit_close,node_firestore toneAmber
class node_iso_certificates,node_trial_run toneMint
class node_equipment,node_admin_config toneRose
class node_firestore_rules,node_service_worker,node_pwa_manifest,node_firebase_auth toneIndigo
```

## Components

### Access and interface

- [Application shell](https://github.com/nrccpak/nrcc-ptw/blob/main/index.html): `index.html`
- [Login and roles](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Role dashboards](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`

### Permit lifecycle

- [Permit requests](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Issuer review](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Auto-rejection](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Permit closure](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`

### Isolation safety

- [Isolation certificates](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Trial-run workflow](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`

### Operations

- [Equipment register](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`
- [Admin configuration](https://github.com/nrccpak/nrcc-ptw/blob/main/app.js): `app.js`

### Offline platform

- [Firestore rules](https://github.com/nrccpak/nrcc-ptw/blob/main/firestore.rules): `firestore.rules`
- [Offline service worker](https://github.com/nrccpak/nrcc-ptw/blob/main/service-worker.js): `service-worker.js`
- [PWA manifest](https://github.com/nrccpak/nrcc-ptw/blob/main/manifest.webmanifest): `manifest.webmanifest`

### Other components

- **Permit users**
- **Firebase Auth**
- **Firestore data**

## Connections

- Permit users → Application shell: uses (evidence: `README.md`)
- Application shell → Login and roles: loads (evidence: `README.md`)
- Login and roles → Firebase Auth: authenticates (evidence: `README.md`)
- Login and roles → Firestore data: loads profile (evidence: `app.js`)
- Login and roles → Role dashboards: renders (evidence: `app.js`)
- Role dashboards → Permit requests: raises permits (evidence: `README.md`)
- Permit requests → Firestore data: writes permits (evidence: `app.js`)
- Issuer review → Firestore data: updates permits (evidence: `app.js`)
- Auto-rejection → Firestore data: stamps status (evidence: `README.md`)
- Permit closure → Firestore data: updates permits (evidence: `app.js`)
- Issuer review → Isolation certificates: assigns isolation (evidence: `README.md`)
- Isolation certificates → Firestore data: stores certificates (evidence: `README.md`)
- Isolation certificates → Trial-run workflow: supports trial run (evidence: `README.md`)
- Isolation certificates → Permit closure: enables closure (evidence: `README.md`)
- Equipment register → Firestore data: reads and writes (evidence: `app.js`)
- Admin configuration → Firestore data: edits configuration (evidence: `README.md`)
- Firestore rules → Firestore data: controls access (evidence: `README.md`)
- Application shell → Offline service worker: registers (evidence: `README.md`)
- Offline service worker → Application shell: caches shell (evidence: `service-worker.js`)
- Application shell → PWA manifest: declares installability (evidence: `README.md`)
