# pasakorn-dev/ww_sys architecture

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

- Interactive diagram: https://gitdiagram.com/pasakorn-dev/ww_sys
- Repository: https://github.com/pasakorn-dev/ww_sys

## Overview

This is a branch-oriented wood-production management system: staff sign in, choose operational screens, synchronize legacy branch data, manage prices, inspect saw/wet/dry-wood activity, and view or export production and performance reports. The React application calls an Express API; authenticated routes dispatch to controllers, which use PostgreSQL models and, for legacy synchronization, branch-specific MySQL connections. The graph preserves the documented report and synchronization feature families. Some page implementations and controllers were not sampled, so uncertain page-to-endpoint links are omitted.

Main entry points: [`ww-frontend/src/App.jsx`](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/App.jsx) (App routing), [`ww-frontend/src/services/apiFetch.js`](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/services/apiFetch.js) (API request helper), [`ww-backend/src/routes/masterRoutes.js`](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/masterRoutes.js) (Master routes), [`ww-backend/src/config/db.js`](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/config/db.js) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Staff web app"]
  node_app["App routing<br/>[App.jsx]"]
  node_login["Login<br/>[Login.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_branches["Branches<br/>[Branches.jsx]"]
  node_syncui["Wood sync screens<br/>[SyncMaster.jsx]"]
  node_sawui["Saw wood screens<br/>[CheckSawWood.jsx]"]
  node_priceui["Wood price manager"]
  node_reportui["Production reports"]
  node_performanceui["Performance reports"]
  node_coverui["Wet/dry cover reports"]
  node_fetch["API request helper<br/>[apiFetch.js]"]
end

subgraph group_api["Backend API"]
  node_server["Express server<br/>[server.js]"]
  node_auth["Token verification<br/>[authMiddleware.js]"]
  node_masterroutes["Master routes<br/>[masterRoutes.js]"]
  node_reportroutes["Report routes<br/>[reportRoutes.js]"]
  node_transactionroutes["Transaction routes"]
end

subgraph group_operations["Operational data"]
  node_master["Master data and sync"]
  node_transactions["Transaction sync"]
  node_woodprice["Wood price operations"]
  node_branchesmodel["Branch data<br/>[branchModel.js]"]
  node_transactionmodel["Transaction queries"]
  node_pg[("PostgreSQL<br/>[db.js]")]
  node_mysql[("Branch MySQL<br/>[mysqlDb.js]")]
end

subgraph group_reporting["Reports"]
  node_reportcontroller["Report generation"]
  node_reportmodel["Report queries<br/>[reportModel.js]"]
end

node_staff(("Staff user"))

node_staff -->|"opens"| node_app
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_branches
node_app -->|"routes to"| node_syncui
node_app -->|"routes to"| node_sawui
node_app -->|"routes to"| node_priceui
node_app -->|"routes to"| node_reportui
node_app -->|"routes to"| node_performanceui
node_app -->|"routes to"| node_coverui
node_priceui -->|"requests through"| node_fetch
node_fetch -->|"clears expired session"| node_staff
node_server -->|"mounts"| node_masterroutes
node_server -->|"mounts"| node_reportroutes
node_server -->|"mounts"| node_transactionroutes
node_masterroutes -->|"guards routes"| node_auth
node_reportroutes -->|"guards routes"| node_auth
node_transactionroutes -->|"guards routes"| node_auth
node_masterroutes -->|"dispatches"| node_master
node_masterroutes -->|"dispatches"| node_woodprice
node_reportroutes -->|"dispatches"| node_reportcontroller
node_transactionroutes -->|"dispatches"| node_transactions
node_master -->|"reads legacy data"| node_mysql
node_master -->|"writes synced data"| node_pg
node_transactions -->|"reads legacy records"| node_mysql
node_transactions -->|"loads and upserts"| node_transactionmodel
node_transactionmodel -->|"queries"| node_pg
node_reportcontroller -->|"queries"| node_reportmodel
node_reportmodel -->|"queries"| node_pg
node_woodprice -.->|"persists prices"| node_pg
node_branches -->|"requests through"| node_fetch
node_reportui -->|"requests through"| node_fetch
node_performanceui -->|"requests through"| node_fetch

click node_app "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/App.jsx"
click node_login "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Login.jsx"
click node_dashboard "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Dashboard.jsx"
click node_branches "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Branches.jsx"
click node_syncui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/SyncMaster.jsx"
click node_sawui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/CheckSawWood.jsx"
click node_priceui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/WoodPriceManager.jsx"
click node_reportui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/ProductionCoverReport.jsx"
click node_performanceui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/SawerPerformanceReport.jsx"
click node_coverui "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/WetWoodCoverReport.jsx"
click node_fetch "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/services/apiFetch.js"
click node_server "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/server.js"
click node_auth "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/middlewares/authMiddleware.js"
click node_masterroutes "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/masterRoutes.js"
click node_reportroutes "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/reportRoutes.js"
click node_transactionroutes "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/transactionRoutes.js"
click node_master "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/masterController.js"
click node_transactions "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/transactionController.js"
click node_woodprice "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/woodPriceController.js"
click node_branchesmodel "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/branchModel.js"
click node_reportcontroller "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/reportController.js"
click node_reportmodel "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/reportModel.js"
click node_transactionmodel "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/transactionModel.js"
click node_pg "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/config/db.js"
click node_mysql "https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/config/mysqlDb.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_login,node_dashboard,node_branches,node_syncui,node_sawui,node_priceui,node_reportui,node_performanceui,node_coverui,node_fetch,node_staff toneBlue
class node_server,node_auth,node_masterroutes,node_reportroutes,node_transactionroutes toneAmber
class node_master,node_transactions,node_woodprice,node_branchesmodel,node_transactionmodel,node_pg,node_mysql toneMint
class node_reportcontroller,node_reportmodel toneRose
```

## Components

### Staff web app

- [App routing](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/App.jsx): `ww-frontend/src/App.jsx`
- [Login](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Login.jsx): `ww-frontend/src/pages/Login.jsx`
- [Dashboard](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Dashboard.jsx): `ww-frontend/src/pages/Dashboard.jsx`
- [Branches](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/Branches.jsx): `ww-frontend/src/pages/Branches.jsx`
- [Wood sync screens](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/SyncMaster.jsx): `ww-frontend/src/pages/SyncMaster.jsx`
- [Saw wood screens](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/CheckSawWood.jsx): `ww-frontend/src/pages/CheckSawWood.jsx`
- [Wood price manager](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/WoodPriceManager.jsx): `ww-frontend/src/pages/WoodPriceManager.jsx`
- [Production reports](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/ProductionCoverReport.jsx): `ww-frontend/src/pages/ProductionCoverReport.jsx`
- [Performance reports](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/SawerPerformanceReport.jsx): `ww-frontend/src/pages/SawerPerformanceReport.jsx`
- [Wet/dry cover reports](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/pages/WetWoodCoverReport.jsx): `ww-frontend/src/pages/WetWoodCoverReport.jsx`
- [API request helper](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-frontend/src/services/apiFetch.js): `ww-frontend/src/services/apiFetch.js`

### Backend API

- [Express server](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/server.js): `ww-backend/src/server.js`
- [Token verification](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/middlewares/authMiddleware.js): `ww-backend/src/middlewares/authMiddleware.js`
- [Master routes](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/masterRoutes.js): `ww-backend/src/routes/masterRoutes.js`
- [Report routes](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/reportRoutes.js): `ww-backend/src/routes/reportRoutes.js`
- [Transaction routes](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/routes/transactionRoutes.js): `ww-backend/src/routes/transactionRoutes.js`

### Operational data

- [Master data and sync](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/masterController.js): `ww-backend/src/controllers/masterController.js`
- [Transaction sync](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/transactionController.js): `ww-backend/src/controllers/transactionController.js`
- [Wood price operations](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/woodPriceController.js): `ww-backend/src/controllers/woodPriceController.js`
- [Branch data](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/branchModel.js): `ww-backend/src/models/branchModel.js`
- [Transaction queries](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/transactionModel.js): `ww-backend/src/models/transactionModel.js`
- [PostgreSQL](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/config/db.js): `ww-backend/src/config/db.js`
- [Branch MySQL](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/config/mysqlDb.js): `ww-backend/src/config/mysqlDb.js`

### Reports

- [Report generation](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/controllers/reportController.js): `ww-backend/src/controllers/reportController.js`
- [Report queries](https://github.com/pasakorn-dev/ww_sys/blob/main/ww-backend/src/models/reportModel.js): `ww-backend/src/models/reportModel.js`

### Other components

- **Staff user**

## Connections

- Staff user → App routing: opens (evidence: `ww-frontend/src/App.jsx`)
- App routing → Login: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Dashboard: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Branches: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Wood sync screens: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Saw wood screens: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Wood price manager: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Production reports: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Performance reports: routes to (evidence: `ww-frontend/src/App.jsx`)
- App routing → Wet/dry cover reports: routes to (evidence: `ww-frontend/src/App.jsx`)
- Wood price manager → API request helper: requests through (evidence: `ww-frontend/src/pages/WoodPriceManager.jsx`)
- API request helper → Staff user: clears expired session (evidence: `ww-frontend/src/services/apiFetch.js`)
- Express server → Master routes: mounts (evidence: `ww-backend/src/server.js`)
- Express server → Report routes: mounts (evidence: `ww-backend/src/server.js`)
- Express server → Transaction routes: mounts (evidence: `ww-backend/src/server.js`)
- Master routes → Token verification: guards routes (evidence: `ww-backend/src/routes/masterRoutes.js`)
- Report routes → Token verification: guards routes (evidence: `ww-backend/src/routes/reportRoutes.js`)
- Transaction routes → Token verification: guards routes (evidence: `ww-backend/src/routes/transactionRoutes.js`)
- Master routes → Master data and sync: dispatches (evidence: `ww-backend/src/routes/masterRoutes.js`)
- Master routes → Wood price operations: dispatches (evidence: `ww-backend/src/routes/masterRoutes.js`)
- Report routes → Report generation: dispatches (evidence: `ww-backend/src/routes/reportRoutes.js`)
- Transaction routes → Transaction sync: dispatches (evidence: `ww-backend/src/routes/transactionRoutes.js`)
- Master data and sync → Branch MySQL: reads legacy data (evidence: `ww-backend/src/controllers/masterController.js`)
- Master data and sync → PostgreSQL: writes synced data (evidence: `ww-backend/src/controllers/masterController.js`)
- Transaction sync → Branch MySQL: reads legacy records (evidence: `ww-backend/src/controllers/transactionController.js`)
- Transaction sync → Transaction queries: loads and upserts (evidence: `ww-backend/src/controllers/transactionController.js`)
- Transaction queries → PostgreSQL: queries (evidence: `ww-backend/src/models/transactionModel.js`)
- Report generation → Report queries: queries (evidence: `ww-backend/src/controllers/reportController.js`)
- Report queries → PostgreSQL: queries (evidence: `ww-backend/src/models/reportModel.js`)
- Wood price operations → PostgreSQL: persists prices
- Branches → API request helper: requests through (evidence: `ww-frontend/src/pages/Branches.jsx`)
- Production reports → API request helper: requests through
- Performance reports → API request helper: requests through (evidence: `ww-frontend/src/pages/SawerPerformanceReport.jsx`)
