# hwarinn66/stock-recording-typescript architecture

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

- Interactive diagram: https://gitdiagram.com/hwarinn66/stock-recording-typescript
- Repository: https://github.com/hwarinn66/stock-recording-typescript

## Overview

Warehouse Stock Management is a Next.js inventory system backed by MySQL, with a companion Android scanner. The main workflow is to manage products and print QR labels, scan incoming or reserved outgoing items, update stock and transaction history, then refresh dashboard and history views. Other documented capabilities include hierarchical locations, stock opname and adjustment, emergency workflows, reports, Excel export/backup, and live updates. Service internals beyond the shown transaction and database code are represented at subsystem level; documented workflows use README evidence.

Main entry points: [`src/app/api/[...path]/route.ts`](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/app/api/%5B...path%5D/route.ts) (API router), [`src/services/transactions.ts`](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/transactions.ts) (Stock transactions), [`src/lib/db.ts`](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/db.ts) (SQL access and events), [`src/components/workspace/index.ts`](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/index.ts) (Workspace router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_workspace["Workspace router<br/>[index.ts]"]
  node_dashboard["Dashboard<br/>[dashboard.tsx]"]
  node_products_ui["Product management<br/>[products.tsx]"]
  node_management_ui["Management and history<br/>[management.tsx]"]
  node_opname_ui["Stock opname<br/>[opname.tsx]"]
  node_labels_ui["QR labels<br/>[labels.tsx]"]
  node_reservations_ui["Reservation history<br/>[reservations.tsx]"]
  node_emergency_ui["Emergency workflow<br/>[emergency.tsx]"]
  node_live_hook["Live updates<br/>[use-live.ts]"]
end

subgraph group_operations["Inventory operations"]
  node_transactions["Stock transactions<br/>[transactions.ts]"]
  node_scan_batches["Scan batches<br/>[scan-batches.ts]"]
  node_reservations["Reservations<br/>[reservations.ts]"]
  node_products["Product catalog<br/>[products.ts]"]
  node_locations["Location hierarchy<br/>[locations.ts]"]
  node_opname["Opname adjustments<br/>[opname.ts]"]
  node_labels["Label generation<br/>[labels.ts]"]
  node_stock_rules["Stock rules<br/>[stock.ts]"]
end

subgraph group_platform["API and persistence"]
  node_api_client["Browser API client<br/>[client.ts]"]
  node_api_routes["API router<br/>[route.ts]"]
  node_events_route["SSE endpoint<br/>[route.ts]"]
  node_auth["Session authentication<br/>[auth.ts]"]
  node_db_layer["SQL access and events<br/>[db.ts]"]
end

subgraph group_support["Reporting and support"]
  node_reports["Reports and exports<br/>[reports.ts]"]
  node_excel_backup["Excel backup<br/>[excel-backup.ts]"]
  node_emergency["Emergency services<br/>[emergency.ts]"]
end

node_staff(("Warehouse staff"))
node_scanner["Android scanner<br/>[MainActivity.kt]"]
node_mysql[("MySQL / MariaDB")]

node_staff -->|"uses"| node_workspace
node_workspace -->|"selects view"| node_dashboard
node_workspace -->|"selects view"| node_products_ui
node_workspace -->|"selects view"| node_management_ui
node_workspace -->|"selects view"| node_opname_ui
node_workspace -->|"selects view"| node_labels_ui
node_staff -->|"manages items"| node_products_ui
node_products_ui -->|"requests data"| node_api_client
node_management_ui -->|"requests data"| node_api_client
node_opname_ui -.->|"requests data"| node_api_client
node_labels_ui -.->|"requests data"| node_api_client
node_api_client -->|"calls API"| node_api_routes
node_scanner -.->|"scans items"| node_api_routes
node_api_routes -->|"checks sessions"| node_auth
node_api_routes -->|"dispatches"| node_transactions
node_api_routes -->|"dispatches"| node_products
node_api_routes -->|"dispatches"| node_reservations
node_api_routes -->|"dispatches"| node_locations
node_api_routes -->|"dispatches"| node_opname
node_api_routes -->|"dispatches"| node_labels
node_api_routes -->|"dispatches"| node_reports
node_api_routes -->|"dispatches"| node_excel_backup
node_api_routes -->|"dispatches"| node_emergency
node_transactions -->|"claims scan batch"| node_scan_batches
node_transactions -->|"claims reservation"| node_reservations
node_transactions -->|"validates quantity"| node_stock_rules
node_transactions -->|"writes transaction"| node_db_layer
node_products -.->|"reads and writes"| node_db_layer
node_locations -->|"reads and writes"| node_db_layer
node_opname -.->|"records adjustment"| node_transactions
node_excel_backup -->|"reads data"| node_db_layer
node_emergency -->|"uses transaction logic"| node_transactions
node_reports -.->|"reads data"| node_db_layer
node_db_layer -->|"queries"| node_mysql
node_db_layer -.->|"publishes revisions"| node_events_route
node_events_route -.->|"streams updates"| node_live_hook
node_live_hook -.->|"refreshes view"| node_dashboard
node_staff -->|"scans workflow"| node_scanner
node_staff -->|"reviews history"| node_management_ui
node_staff -->|"records counts"| node_opname_ui
node_staff -->|"prints labels"| node_labels_ui
node_staff -.->|"reviews pickups"| node_reservations_ui
node_management_ui -->|"opens tools"| node_emergency_ui
node_emergency_ui -->|"requests data"| node_api_client

click node_scanner "https://github.com/hwarinn66/stock-recording-typescript/blob/main/mobile/android/app/src/main/kotlin/com/warehouse/warehouse_scanner/MainActivity.kt"
click node_workspace "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/index.ts"
click node_dashboard "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/dashboard.tsx"
click node_products_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/products.tsx"
click node_management_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/management.tsx"
click node_opname_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/opname.tsx"
click node_labels_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/labels.tsx"
click node_reservations_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/reservations.tsx"
click node_emergency_ui "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/emergency.tsx"
click node_live_hook "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/hooks/use-live.ts"
click node_api_client "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/client.ts"
click node_api_routes "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/app/api/%5B...path%5D/route.ts"
click node_events_route "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/app/api/events/route.ts"
click node_auth "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/auth.ts"
click node_transactions "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/transactions.ts"
click node_scan_batches "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/scan-batches.ts"
click node_reservations "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/reservations.ts"
click node_products "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/products.ts"
click node_locations "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/locations.ts"
click node_opname "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/opname.ts"
click node_labels "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/labels.ts"
click node_reports "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/reports.ts"
click node_excel_backup "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/excel-backup.ts"
click node_emergency "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/emergency.ts"
click node_stock_rules "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/stock.ts"
click node_db_layer "https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/db.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_workspace,node_dashboard,node_products_ui,node_management_ui,node_opname_ui,node_labels_ui,node_reservations_ui,node_emergency_ui,node_live_hook toneBlue
class node_transactions,node_scan_batches,node_reservations,node_products,node_locations,node_opname,node_labels,node_stock_rules,node_mysql toneAmber
class node_api_client,node_api_routes,node_events_route,node_auth,node_db_layer toneMint
class node_reports,node_excel_backup,node_emergency toneRose
class node_staff toneIndigo
class node_scanner toneTeal
```

## Components

### Web experience

- [Workspace router](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/index.ts): `src/components/workspace/index.ts`
- [Dashboard](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/dashboard.tsx): `src/components/workspace/dashboard.tsx`
- [Product management](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/products.tsx): `src/components/workspace/products.tsx`
- [Management and history](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/management.tsx): `src/components/workspace/management.tsx`
- [Stock opname](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/opname.tsx): `src/components/workspace/opname.tsx`
- [QR labels](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/labels.tsx): `src/components/workspace/labels.tsx`
- [Reservation history](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/reservations.tsx): `src/components/workspace/reservations.tsx`
- [Emergency workflow](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/components/workspace/emergency.tsx): `src/components/workspace/emergency.tsx`
- [Live updates](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/hooks/use-live.ts): `src/hooks/use-live.ts`

### Inventory operations

- [Stock transactions](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/transactions.ts): `src/services/transactions.ts`
- [Scan batches](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/scan-batches.ts): `src/services/scan-batches.ts`
- [Reservations](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/reservations.ts): `src/services/reservations.ts`
- [Product catalog](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/products.ts): `src/services/products.ts`
- [Location hierarchy](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/locations.ts): `src/services/locations.ts`
- [Opname adjustments](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/opname.ts): `src/services/opname.ts`
- [Label generation](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/labels.ts): `src/services/labels.ts`
- [Stock rules](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/stock.ts): `src/lib/stock.ts`

### API and persistence

- [Browser API client](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/client.ts): `src/lib/client.ts`
- [API router](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/app/api/%5B...path%5D/route.ts): `src/app/api/[...path]/route.ts`
- [SSE endpoint](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/app/api/events/route.ts): `src/app/api/events/route.ts`
- [Session authentication](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [SQL access and events](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/lib/db.ts): `src/lib/db.ts`

### Reporting and support

- [Reports and exports](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/reports.ts): `src/services/reports.ts`
- [Excel backup](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/excel-backup.ts): `src/services/excel-backup.ts`
- [Emergency services](https://github.com/hwarinn66/stock-recording-typescript/blob/main/src/services/emergency.ts): `src/services/emergency.ts`

### Other components

- **Warehouse staff**
- [Android scanner](https://github.com/hwarinn66/stock-recording-typescript/blob/main/mobile/android/app/src/main/kotlin/com/warehouse/warehouse_scanner/MainActivity.kt): `mobile/android/app/src/main/kotlin/com/warehouse/warehouse_scanner/MainActivity.kt`
- **MySQL / MariaDB**

## Connections

- Warehouse staff → Workspace router: uses (evidence: `README.md`)
- Workspace router → Dashboard: selects view (evidence: `src/components/workspace/index.ts`)
- Workspace router → Product management: selects view (evidence: `src/components/workspace/index.ts`)
- Workspace router → Management and history: selects view (evidence: `src/components/workspace/index.ts`)
- Workspace router → Stock opname: selects view (evidence: `src/components/workspace/index.ts`)
- Workspace router → QR labels: selects view (evidence: `src/components/workspace/index.ts`)
- Warehouse staff → Product management: manages items (evidence: `README.md`)
- Product management → Browser API client: requests data (evidence: `src/components/workspace/products.tsx`)
- Management and history → Browser API client: requests data (evidence: `src/components/workspace/management.tsx`)
- Stock opname → Browser API client: requests data
- QR labels → Browser API client: requests data
- Browser API client → API router: calls API (evidence: `src/lib/client.ts`)
- Android scanner → API router: scans items (evidence: `README.md`)
- API router → Session authentication: checks sessions (evidence: `src/app/api/[...path]/route.ts`)
- API router → Stock transactions: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Product catalog: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Reservations: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Location hierarchy: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Opname adjustments: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Label generation: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Reports and exports: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Excel backup: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- API router → Emergency services: dispatches (evidence: `src/app/api/[...path]/route.ts`)
- Stock transactions → Scan batches: claims scan batch (evidence: `src/services/transactions.ts`)
- Stock transactions → Reservations: claims reservation (evidence: `src/services/transactions.ts`)
- Stock transactions → Stock rules: validates quantity (evidence: `src/services/transactions.ts`)
- Stock transactions → SQL access and events: writes transaction (evidence: `src/services/transactions.ts`)
- Product catalog → SQL access and events: reads and writes
- Location hierarchy → SQL access and events: reads and writes (evidence: `src/services/locations.ts`)
- Opname adjustments → Stock transactions: records adjustment
- Excel backup → SQL access and events: reads data (evidence: `src/services/excel-backup.ts`)
- Emergency services → Stock transactions: uses transaction logic (evidence: `src/services/emergency.ts`)
- Reports and exports → SQL access and events: reads data
- SQL access and events → MySQL / MariaDB: queries (evidence: `src/lib/db.ts`)
- SQL access and events → SSE endpoint: publishes revisions (evidence: `src/app/api/events/route.ts`)
- SSE endpoint → Live updates: streams updates
- Live updates → Dashboard: refreshes view
- Warehouse staff → Android scanner: scans workflow (evidence: `README.md`)
- Warehouse staff → Management and history: reviews history (evidence: `README.md`)
- Warehouse staff → Stock opname: records counts (evidence: `README.md`)
- Warehouse staff → QR labels: prints labels (evidence: `README.md`)
- Warehouse staff → Reservation history: reviews pickups
- Management and history → Emergency workflow: opens tools (evidence: `src/components/workspace/management.tsx`)
- Emergency workflow → Browser API client: requests data (evidence: `src/components/workspace/emergency.tsx`)
