# pallab-js/stonecrusher_nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/pallab-js/stonecrusher_nextjs
- Repository: https://github.com/pallab-js/stonecrusher_nextjs

## Overview

StoneOps is a local-first operations dashboard for a single stone-crusher unit. Staff sign in, use role-gated operational pages to record production, inventory, sales/dispatch, purchases and expenses, then review reports, maps and printed documents. Server actions validate and process mutations through repository queries against a local SQLite database; dashboard and reporting views summarize that operational data. The README documents settings, demo data and JSON backup/restore as additional capabilities. Some feature wiring is documented but unsampled, so those relationships cite the README rather than implying source inspection.

Main entry points: [`lib/db.ts`](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/db.ts) (SQLite database), [`app/(app)/maps/page.tsx`](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/(app)/maps/page.tsx) (Offline maps), [`app/login/login-form.tsx`](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/login/login-form.tsx) (PIN login), [`lib/repo/operations.ts`](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/operations.ts) (Operations repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and shell"]
  node_login["PIN login<br/>[login-form.tsx]"]
  node_auth["PIN and roles<br/>[auth.ts]"]
  node_session["Session cookie<br/>[session.ts]"]
  node_shell["App shell<br/>[app-shell.tsx]"]
end

subgraph group_operations["Unit operations"]
  node_production["Production shifts"]
  node_inventory["Inventory ledger<br/>[inventory-view.tsx]"]
  node_sales["Sales and dispatch<br/>[sales-table.tsx]"]
  node_orders["Customer orders<br/>[orders-table.tsx]"]
  node_purchasing["Purchases and GRNs"]
  node_expenses["Expenses<br/>[expenses-table.tsx]"]
  node_masters["Customer and supplier masters<br/>[masters.ts]"]
  node_mutations["Operational actions<br/>[production.ts]"]
  node_operations_repo["Operations repository<br/>[operations.ts]"]
end

subgraph group_insight["Insights and maps"]
  node_dashboard["Dashboard<br/>[dashboard.tsx]"]
  node_analytics["Analytics queries<br/>[analytics.ts]"]
  node_reports["Reports and export<br/>[reports-view.tsx]"]
  node_report_queries["Report queries<br/>[reports.ts]"]
  node_maps["Offline maps<br/>[page.tsx]"]
  node_map_views["Map views<br/>[plant-map.tsx]"]
end

subgraph group_persistence["Local data"]
  node_sqlite[("SQLite database<br/>[db.ts]")]
  node_settings["Settings and seed data<br/>[settings-view.tsx]"]
end

subgraph group_documents["Print and backup"]
  node_statements["Statements<br/>[statements.ts]"]
  node_print["Print documents"]
  node_backup["JSON backup<br/>[backup.ts]"]
  node_backup_api["Backup endpoint<br/>[route.ts]"]
end

node_staff(("Staff"))

node_staff -->|"enters PIN"| node_login
node_login -->|"verifies PIN"| node_auth
node_login -->|"sets session"| node_session
node_shell -->|"checks access"| node_auth
node_shell -->|"presents modules"| node_staff
node_production -.->|"submits shifts"| node_mutations
node_sales -->|"uses order data"| node_orders
node_sales -->|"reads sales data"| node_operations_repo
node_mutations -.->|"writes operations"| node_operations_repo
node_operations_repo -->|"queries and updates"| node_sqlite
node_masters -->|"queries masters"| node_sqlite
node_dashboard -->|"renders metrics"| node_analytics
node_analytics -->|"queries summaries"| node_sqlite
node_reports -->|"renders reports"| node_report_queries
node_report_queries -->|"queries periods"| node_sqlite
node_maps -->|"loads plant summary"| node_analytics
node_maps -->|"loads products and customers"| node_masters
node_maps -->|"supplies map data"| node_map_views
node_statements -->|"queries balances"| node_sqlite
node_print -->|"shows statement data"| node_statements
node_settings -->|"manages roles and data"| node_staff
node_backup_api -->|"imports and exports"| node_backup
node_backup -.->|"backs up database"| node_sqlite

click node_login "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/login/login-form.tsx"
click node_auth "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/auth.ts"
click node_session "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/session.ts"
click node_shell "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/shell/app-shell.tsx"
click node_production "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/production-table.tsx"
click node_inventory "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/inventory-view.tsx"
click node_sales "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/sales-table.tsx"
click node_orders "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/orders-table.tsx"
click node_purchasing "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/purchases-table.tsx"
click node_expenses "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/expenses-table.tsx"
click node_masters "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/masters.ts"
click node_mutations "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/actions/production.ts"
click node_operations_repo "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/operations.ts"
click node_dashboard "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/dashboard.tsx"
click node_analytics "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/analytics.ts"
click node_reports "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/reports-view.tsx"
click node_report_queries "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/reports.ts"
click node_maps "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/(app)/maps/page.tsx"
click node_map_views "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/maps/plant-map.tsx"
click node_sqlite "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/db.ts"
click node_statements "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/statements.ts"
click node_print "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/print/statement-sheet.tsx"
click node_settings "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/settings-view.tsx"
click node_backup "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/backup.ts"
click node_backup_api "https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/api/backup/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_login,node_auth,node_session,node_shell toneBlue
class node_production,node_inventory,node_sales,node_orders,node_purchasing,node_expenses,node_masters,node_mutations,node_operations_repo toneAmber
class node_dashboard,node_analytics,node_reports,node_report_queries,node_maps,node_map_views toneMint
class node_sqlite,node_settings toneRose
class node_statements,node_print,node_backup,node_backup_api,node_staff toneIndigo
```

## Components

### Access and shell

- [PIN login](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/login/login-form.tsx): `app/login/login-form.tsx`
- [PIN and roles](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/auth.ts): `lib/auth.ts`
- [Session cookie](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/session.ts): `lib/session.ts`
- [App shell](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/shell/app-shell.tsx): `components/shell/app-shell.tsx`

### Unit operations

- [Production shifts](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/production-table.tsx): `components/modules/production-table.tsx`
- [Inventory ledger](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/inventory-view.tsx): `components/modules/inventory-view.tsx`
- [Sales and dispatch](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/sales-table.tsx): `components/modules/sales-table.tsx`
- [Customer orders](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/orders-table.tsx): `components/modules/orders-table.tsx`
- [Purchases and GRNs](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/purchases-table.tsx): `components/modules/purchases-table.tsx`
- [Expenses](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/expenses-table.tsx): `components/modules/expenses-table.tsx`
- [Customer and supplier masters](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/masters.ts): `lib/repo/masters.ts`
- [Operational actions](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/actions/production.ts): `actions/production.ts`
- [Operations repository](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/operations.ts): `lib/repo/operations.ts`

### Insights and maps

- [Dashboard](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/dashboard.tsx): `components/modules/dashboard.tsx`
- [Analytics queries](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/analytics.ts): `lib/repo/analytics.ts`
- [Reports and export](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/reports-view.tsx): `components/modules/reports-view.tsx`
- [Report queries](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/reports.ts): `lib/repo/reports.ts`
- [Offline maps](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/(app)/maps/page.tsx): `app/(app)/maps/page.tsx`
- [Map views](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/maps/plant-map.tsx): `components/maps/plant-map.tsx`

### Local data

- [SQLite database](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/db.ts): `lib/db.ts`
- [Settings and seed data](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/modules/settings-view.tsx): `components/modules/settings-view.tsx`

### Print and backup

- [Statements](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/repo/statements.ts): `lib/repo/statements.ts`
- [Print documents](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/components/print/statement-sheet.tsx): `components/print/statement-sheet.tsx`
- [JSON backup](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/lib/backup.ts): `lib/backup.ts`
- [Backup endpoint](https://github.com/pallab-js/stonecrusher_nextjs/blob/main/app/api/backup/route.ts): `app/api/backup/route.ts`

### Other components

- **Staff**

## Connections

- Staff → PIN login: enters PIN (evidence: `README.md`)
- PIN login → PIN and roles: verifies PIN
- PIN login → Session cookie: sets session
- App shell → PIN and roles: checks access (evidence: `components/shell/app-shell.tsx`)
- App shell → Staff: presents modules (evidence: `README.md`)
- Production shifts → Operational actions: submits shifts
- Sales and dispatch → Customer orders: uses order data (evidence: `components/modules/sales-table.tsx`)
- Sales and dispatch → Operations repository: reads sales data (evidence: `app/(app)/sales/page.tsx`)
- Operational actions → Operations repository: writes operations
- Operations repository → SQLite database: queries and updates (evidence: `lib/repo/operations.ts`)
- Customer and supplier masters → SQLite database: queries masters (evidence: `lib/repo/masters.ts`)
- Dashboard → Analytics queries: renders metrics (evidence: `app/(app)/dashboard/page.tsx`)
- Analytics queries → SQLite database: queries summaries (evidence: `lib/repo/analytics.ts`)
- Reports and export → Report queries: renders reports (evidence: `app/(app)/reports/page.tsx`)
- Report queries → SQLite database: queries periods (evidence: `lib/repo/reports.ts`)
- Offline maps → Analytics queries: loads plant summary (evidence: `app/(app)/maps/page.tsx`)
- Offline maps → Customer and supplier masters: loads products and customers (evidence: `app/(app)/maps/page.tsx`)
- Offline maps → Map views: supplies map data (evidence: `app/(app)/maps/page.tsx`)
- Statements → SQLite database: queries balances (evidence: `lib/repo/statements.ts`)
- Print documents → Statements: shows statement data (evidence: `components/print/statement-sheet.tsx`)
- Settings and seed data → Staff: manages roles and data (evidence: `README.md`)
- Backup endpoint → JSON backup: imports and exports (evidence: `app/api/backup/route.ts`)
- JSON backup → SQLite database: backs up database
