# devaprasanth1311-lang/stockflow architecture

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

- Interactive diagram: https://gitdiagram.com/devaprasanth1311-lang/stockflow
- Repository: https://github.com/devaprasanth1311-lang/stockflow

## Overview

#### Purpose and topology
StockFlow is a decoupled inventory-management dashboard: a React/Vite client presents inventory operations and analytics, while a Node.js/Express API owns authentication, products, and inventory persistence. MongoDB is the system database through Mongoose; Socket.IO is intended for live dashboard updates.

#### Runtime entry points
- Backend process: `backend/server.js` starts Express, connects infrastructure, and exposes API routes.
- Frontend bootstrap: `frontend/src/main.jsx` mounts the React application; `frontend/src/App.jsx` defines the application-level view/routing composition.
- The two runtimes are installed and started independently from `backend/package.json` and `frontend/package.json`.

#### Client shell and navigation
The client uses a dashboard-oriented shell, with persistent navigation framing page-level operational views.
- Layout boundary: `frontend/src/layouts/DashboardLayout.jsx`
- Navigation components: `frontend/src/components/Sidebar.jsx`, `frontend/src/components/TopNav.jsx`
- Primary functional screens: `frontend/src/pages/Dashboard.jsx`, `frontend/src/pages/Products.jsx`, `frontend/src/pages/Movements.jsx`

#### Dashboard and operational UI
Dashboard views surface KPIs, chart-based analytics, and activity; product and stock views support stock status and editing workflows. Supply-chain-oriented views cover suppliers and warehouse capacity.
- Analytics/dashboard: `frontend/src/pages/Dashboard.jsx`
- Inventory/product view: `frontend/src/pages/Products.jsx`, `frontend/src/pages/Stock.jsx`
- Supply-chain views: `frontend/src/pages/Suppliers.jsx`, `frontend/src/pages/Warehouses.jsx`
Current UI data is explicitly mock-driven, centered in `frontend/src/mockData.js`; API integration is therefore a key boundary rather than an established end-to-end flow.

#### HTTP API and authorization boundary
Express route modules separate public/auth concerns from protected inventory-domain operations.
- Authentication routes and controller: `backend/src/routes/authRoutes.js`, `backend/src/controllers/authController.js`
- Product API: `backend/src/routes/productRoutes.js`, `backend/src/controllers/productController.js`
- Inventory API: `backend/src/routes/inventoryRoutes.js`, `backend/src/controllers/inventoryController.js`
- JWT enforcement: `backend/src/middleware/auth.js`
The intended flow is client request → route → authentication middleware where required → controller → Mongoose model → MongoDB response.

#### Inventory domain and audit model
The persistence model distinguishes catalog entities, on-hand inventory, location/supply-chain entities, users, and transaction history.
- Catalog and stock: `backend/src/models/Product.js`, `backend/src/models/Inventory.js`
- Movement/audit record: `backend/src/models/Transaction.js`
- Organization context: `backend/src/models/Warehouse.js`, `backend/src/models/Supplier.js`
- Identity/roles: `backend/src/models/User.js`
Stock-in, stock-out, adjustments, and transfers should treat inventory mutation plus transaction creation as a consistency-sensitive domain boundary.

#### External services and integration concerns
MongoDB (local or Atlas) is required through `MONGODB_URI`; JWT signing requires `JWT_SECRET`; bcrypt supports credential handling. Socket.IO is the real-time channel intended to publish inventory changes to dashboards. The main implementation gap implied by the repository is connecting React mock-data workflows to authenticated REST endpoints and real-time events while preserving transaction/audit integrity.

Main entry points: [`backend/src/routes/productRoutes.js`](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/routes/productRoutes.js) (Product and inventory API), [`backend/src/controllers/inventoryController.js`](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/controllers/inventoryController.js) (Inventory mutation boundary), [`frontend/src/pages/Dashboard.jsx`](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/pages/Dashboard.jsx) (Dashboard and inventory views), [`backend/server.js`](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/server.js) (Express server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_frontend_main["Vite bootstrap<br/>React entry<br/>[main.jsx]"]
  node_frontend_app["App composition<br/>React app<br/>[App.jsx]"]
  node_dashboard_layout["Dashboard shell<br/>layout"]
  node_navigation["Sidebar and top nav<br/>navigation<br/>[Sidebar.jsx]"]
  node_operational_views["Dashboard and inventory views<br/>React pages<br/>[Dashboard.jsx]"]
  node_mock_data["Mock UI data<br/>client data<br/>[mockData.js]"]
  node_socket_client["Live update client<br/>Socket.IO integration"]
end

subgraph group_api["Node API"]
  node_server["Express server<br/>Node entry<br/>[server.js]"]
  node_auth_api["Authentication API<br/>routes and controller<br/>[authRoutes.js]"]
  node_inventory_api["Product and inventory API<br/>routes and controllers<br/>[productRoutes.js]"]
  node_jwt_auth["JWT middleware<br/>authorization<br/>[auth.js]"]
  node_domain_services["Inventory mutation boundary<br/>domain workflow"]
  node_socket_server["Live update publisher<br/>Socket.IO integration"]
end

subgraph group_data["Persistence"]
  node_identity_model["Users and roles<br/>Mongoose model<br/>[User.js]"]
  node_inventory_models["Catalog and stock<br/>Mongoose models<br/>[Product.js]"]
  node_transaction_model["Movement audit<br/>Mongoose model<br/>[Transaction.js]"]
  node_organization_models["Warehouses and suppliers<br/>Mongoose models<br/>[Warehouse.js]"]
  node_mongodb[("MongoDB<br/>database")]
end

node_frontend_main -->|"mounts"| node_frontend_app
node_frontend_app -->|"composes"| node_dashboard_layout
node_dashboard_layout -->|"frames"| node_navigation
node_dashboard_layout -->|"hosts"| node_operational_views
node_operational_views -->|"currently reads"| node_mock_data
node_operational_views -.->|"intended authenticated REST"| node_inventory_api
node_socket_server -.->|"inventory events"| node_socket_client
node_socket_client -.->|"updates dashboards"| node_operational_views
node_server -->|"registers"| node_auth_api
node_server -->|"registers"| node_inventory_api
node_server -.->|"hosts"| node_socket_server
node_inventory_api -->|"protects routes"| node_jwt_auth
node_jwt_auth -->|"authorizes"| node_domain_services
node_auth_api -->|"credentials and roles"| node_identity_model
node_inventory_api -->|"catalog operations"| node_inventory_models
node_domain_services -->|"mutates stock"| node_inventory_models
node_domain_services -->|"creates audit record"| node_transaction_model
node_inventory_api -->|"location context"| node_organization_models
node_identity_model -->|"persists"| node_mongodb
node_inventory_models -->|"persists"| node_mongodb
node_transaction_model -->|"persists"| node_mongodb
node_organization_models -->|"persists"| node_mongodb
node_domain_services -.->|"publishes changes"| node_socket_server

click node_frontend_main "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/main.jsx"
click node_frontend_app "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/App.jsx"
click node_dashboard_layout "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/layouts/DashboardLayout.jsx"
click node_navigation "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/components/Sidebar.jsx"
click node_operational_views "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/pages/Dashboard.jsx"
click node_mock_data "https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/mockData.js"
click node_server "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/server.js"
click node_auth_api "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/routes/authRoutes.js"
click node_inventory_api "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/routes/productRoutes.js"
click node_jwt_auth "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/middleware/auth.js"
click node_domain_services "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/controllers/inventoryController.js"
click node_identity_model "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/User.js"
click node_inventory_models "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Product.js"
click node_transaction_model "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Transaction.js"
click node_organization_models "https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Warehouse.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_frontend_main,node_frontend_app,node_dashboard_layout,node_navigation,node_operational_views,node_mock_data,node_socket_client toneBlue
class node_server,node_auth_api,node_inventory_api,node_jwt_auth,node_domain_services,node_socket_server toneAmber
class node_identity_model,node_inventory_models,node_transaction_model,node_organization_models,node_mongodb toneMint
```

## Components

### React client

Independently started Vite dashboard.

- [Vite bootstrap](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [App composition](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/App.jsx): React app · `frontend/src/App.jsx`
- [Dashboard shell](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/layouts/DashboardLayout.jsx): layout · Persistent operational navigation frame. · `frontend/src/layouts/DashboardLayout.jsx`
- [Sidebar and top nav](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/components/Sidebar.jsx): navigation · `frontend/src/components/Sidebar.jsx`
- [Dashboard and inventory views](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/pages/Dashboard.jsx): React pages · KPIs, products, stock, movements, suppliers, and warehouses. · `frontend/src/pages/Dashboard.jsx`
- [Mock UI data](https://github.com/devaprasanth1311-lang/stockflow/blob/master/frontend/src/mockData.js): client data · Current UI workflows are mock-driven. · `frontend/src/mockData.js`
- **Live update client**: Socket.IO integration · Intended client-side inventory update channel.

### Node API

Express inventory service.

- [Express server](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/server.js): Node entry · Starts infrastructure and exposes API routes. · `backend/server.js`
- [Authentication API](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/routes/authRoutes.js): routes and controller · `backend/src/routes/authRoutes.js`
- [Product and inventory API](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/routes/productRoutes.js): routes and controllers · Protected inventory-domain operations. · `backend/src/routes/productRoutes.js`
- [JWT middleware](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/middleware/auth.js): authorization · `backend/src/middleware/auth.js`
- [Inventory mutation boundary](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/controllers/inventoryController.js): domain workflow · Stock changes must create matching audit transactions. · `backend/src/controllers/inventoryController.js`
- **Live update publisher**: Socket.IO integration · Intended publisher for inventory changes.

### Persistence

MongoDB-backed domain records.

- [Users and roles](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/User.js): Mongoose model · `backend/src/models/User.js`
- [Catalog and stock](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Product.js): Mongoose models · Product and on-hand inventory records. · `backend/src/models/Product.js`
- [Movement audit](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Transaction.js): Mongoose model · Stock-in, stock-out, adjustment, and transfer history. · `backend/src/models/Transaction.js`
- [Warehouses and suppliers](https://github.com/devaprasanth1311-lang/stockflow/blob/master/backend/src/models/Warehouse.js): Mongoose models · `backend/src/models/Warehouse.js`
- **MongoDB**: database · Configured through MONGODB_URI.

## Connections

- Vite bootstrap → App composition: mounts
- App composition → Dashboard shell: composes
- Dashboard shell → Sidebar and top nav: frames
- Dashboard shell → Dashboard and inventory views: hosts
- Dashboard and inventory views → Mock UI data: currently reads
- Dashboard and inventory views → Product and inventory API: intended authenticated REST
- Live update publisher → Live update client: inventory events
- Live update client → Dashboard and inventory views: updates dashboards
- Express server → Authentication API: registers
- Express server → Product and inventory API: registers
- Express server → Live update publisher: hosts
- Product and inventory API → JWT middleware: protects routes
- JWT middleware → Inventory mutation boundary: authorizes
- Authentication API → Users and roles: credentials and roles
- Product and inventory API → Catalog and stock: catalog operations
- Inventory mutation boundary → Catalog and stock: mutates stock
- Inventory mutation boundary → Movement audit: creates audit record
- Product and inventory API → Warehouses and suppliers: location context
- Users and roles → MongoDB: persists
- Catalog and stock → MongoDB: persists
- Movement audit → MongoDB: persists
- Warehouses and suppliers → MongoDB: persists
- Inventory mutation boundary → Live update publisher: publishes changes
