# priyagaggar/threadcontrol architecture

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

- Interactive diagram: https://gitdiagram.com/priyagaggar/threadcontrol
- Repository: https://github.com/priyagaggar/threadcontrol

## Overview

ThreadControl is a textile-production ERP whose main workflow tracks material from raw-material intake through softening, dyeing, winding, packing, and dispatch. Factory staff enter production data; supervisors approve entries before they affect stock. The application also provides live balances, audit and reporting tools, and administrative features. Its documented platform combines a browser app, a Cloudflare Worker, Firebase Realtime Database, and R2 backups. Relationships below rely on README descriptions; no source excerpts were provided, so implementation-level call paths cannot be verified.

Main entry points: [`worker.js`](https://github.com/priyagaggar/threadcontrol/blob/main/worker.js) (Cloudflare backend), [`assets/js/soft.js`](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/soft.js) (Softening entries), [`assets/js/dye.js`](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dye.js) (Dye lot management), [`assets/js/wind.js`](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/wind.js) (Winding entries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_production["Production workflow"]
  node_rm["Raw material intake<br/>[rm.js]"]
  node_soft["Softening entries<br/>[soft.js]"]
  node_dye["Dye lot management<br/>[dye.js]"]
  node_wind["Winding entries<br/>[wind.js]"]
  node_pack["Packing entries<br/>[pack.js]"]
  node_dispatch["Dispatch<br/>[dispatch.js]"]
end

subgraph group_operations["Operations and oversight"]
  node_approval["Approval queue<br/>[approval.js]"]
  node_stock["Live stock view<br/>[stock.js]"]
  node_dashboard["Dashboard<br/>[dashboard.js]"]
  node_analytics["Analytics and reports<br/>[analytics.js]"]
  node_audit["Edit audit trail<br/>[editlog.js]"]
end

subgraph group_frontend["Application foundation"]
  node_shell["SPA shell<br/>[index.html]"]
  node_router["Page router<br/>[pages.js]"]
  node_core["App state and loading<br/>[core.js]"]
  node_balances["Balance calculations<br/>[shared-balances.js]"]
  node_smartloader["Incremental loading<br/>[smart-loader.js]"]
  node_summaries["Summary loading<br/>[summary-loader.js]"]
  node_indexeddb[("Offline persistence<br/>[idb-storage.js]")]
end

subgraph group_platform["Backend and storage"]
  node_worker["Cloudflare backend<br/>[worker.js]"]
  node_firebase[("Firebase database")]
  node_r2[("R2 backups")]
  node_pwa["Offline service worker<br/>[sw.js]"]
end

node_staff(("Factory staff"))
node_supervisor(("Supervisor"))

node_staff -->|"records intake"| node_rm
node_staff -->|"records entries"| node_soft
node_staff -->|"manages lots"| node_dye
node_staff -->|"records entries"| node_wind
node_staff -->|"records entries"| node_pack
node_staff -->|"records dispatch"| node_dispatch
node_rm -->|"production stage"| node_soft
node_soft -->|"production stage"| node_dye
node_dye -->|"production stage"| node_wind
node_wind -->|"production stage"| node_pack
node_pack -->|"production stage"| node_dispatch
node_supervisor -->|"reviews entries"| node_approval
node_approval -->|"approves stock changes"| node_stock
node_shell -->|"hosts app"| node_router
node_worker -->|"uses database"| node_firebase
node_worker -->|"stores backups"| node_r2
node_worker -->|"refreshes summaries"| node_firebase
node_pwa -->|"supports offline use"| node_shell

click node_shell "https://github.com/priyagaggar/threadcontrol/blob/main/assets/index.html"
click node_router "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/pages.js"
click node_core "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/core.js"
click node_balances "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/shared-balances.js"
click node_smartloader "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/smart-loader.js"
click node_summaries "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/summary-loader.js"
click node_indexeddb "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/idb-storage.js"
click node_rm "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/rm.js"
click node_soft "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/soft.js"
click node_dye "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dye.js"
click node_wind "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/wind.js"
click node_pack "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/pack.js"
click node_dispatch "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dispatch.js"
click node_approval "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/approval.js"
click node_stock "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/stock.js"
click node_dashboard "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dashboard.js"
click node_analytics "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/analytics.js"
click node_audit "https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/editlog.js"
click node_worker "https://github.com/priyagaggar/threadcontrol/blob/main/worker.js"
click node_pwa "https://github.com/priyagaggar/threadcontrol/blob/main/assets/sw.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_rm,node_soft,node_dye,node_wind,node_pack,node_dispatch toneBlue
class node_approval,node_stock,node_dashboard,node_analytics,node_audit toneAmber
class node_shell,node_router,node_core,node_balances,node_smartloader,node_summaries,node_indexeddb toneMint
class node_worker,node_firebase,node_r2,node_pwa toneRose
class node_staff,node_supervisor toneIndigo
```

## Components

### Production workflow

- [Raw material intake](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/rm.js): `assets/js/rm.js`
- [Softening entries](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/soft.js): `assets/js/soft.js`
- [Dye lot management](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dye.js): `assets/js/dye.js`
- [Winding entries](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/wind.js): `assets/js/wind.js`
- [Packing entries](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/pack.js): `assets/js/pack.js`
- [Dispatch](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dispatch.js): `assets/js/dispatch.js`

### Operations and oversight

- [Approval queue](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/approval.js): `assets/js/approval.js`
- [Live stock view](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/stock.js): `assets/js/stock.js`
- [Dashboard](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/dashboard.js): `assets/js/dashboard.js`
- [Analytics and reports](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/analytics.js): `assets/js/analytics.js`
- [Edit audit trail](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/editlog.js): `assets/js/editlog.js`

### Application foundation

- [SPA shell](https://github.com/priyagaggar/threadcontrol/blob/main/assets/index.html): `assets/index.html`
- [Page router](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/pages.js): `assets/js/pages.js`
- [App state and loading](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/core.js): `assets/js/core.js`
- [Balance calculations](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/shared-balances.js): `assets/js/shared-balances.js`
- [Incremental loading](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/smart-loader.js): `assets/js/smart-loader.js`
- [Summary loading](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/summary-loader.js): `assets/js/summary-loader.js`
- [Offline persistence](https://github.com/priyagaggar/threadcontrol/blob/main/assets/js/idb-storage.js): `assets/js/idb-storage.js`

### Backend and storage

- [Cloudflare backend](https://github.com/priyagaggar/threadcontrol/blob/main/worker.js): `worker.js`
- **Firebase database**
- **R2 backups**
- [Offline service worker](https://github.com/priyagaggar/threadcontrol/blob/main/assets/sw.js): `assets/sw.js`

### Other components

- **Factory staff**
- **Supervisor**

## Connections

- Factory staff → Raw material intake: records intake (evidence: `README.md`)
- Factory staff → Softening entries: records entries (evidence: `README.md`)
- Factory staff → Dye lot management: manages lots (evidence: `README.md`)
- Factory staff → Winding entries: records entries (evidence: `README.md`)
- Factory staff → Packing entries: records entries (evidence: `README.md`)
- Factory staff → Dispatch: records dispatch (evidence: `README.md`)
- Raw material intake → Softening entries: production stage (evidence: `README.md`)
- Softening entries → Dye lot management: production stage (evidence: `README.md`)
- Dye lot management → Winding entries: production stage (evidence: `README.md`)
- Winding entries → Packing entries: production stage (evidence: `README.md`)
- Packing entries → Dispatch: production stage (evidence: `README.md`)
- Supervisor → Approval queue: reviews entries (evidence: `README.md`)
- Approval queue → Live stock view: approves stock changes (evidence: `README.md`)
- SPA shell → Page router: hosts app (evidence: `README.md`)
- Cloudflare backend → Firebase database: uses database (evidence: `README.md`)
- Cloudflare backend → R2 backups: stores backups (evidence: `README.md`)
- Cloudflare backend → Firebase database: refreshes summaries (evidence: `README.md`)
- Offline service worker → SPA shell: supports offline use (evidence: `README.md`)
