# durgesh-0001/retailflow architecture

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

- Interactive diagram: https://gitdiagram.com/durgesh-0001/retailflow
- Repository: https://github.com/durgesh-0001/retailflow

## Overview

#### Purpose and Runtime Topology
RetailFlow is a retail-operations system: inventory, orders, sales analytics, employees/attendance, authentication, and AI/orchestration capabilities. It is a React/Vite single-page frontend backed by a Node.js/Express REST API. Persistent domain state is modeled for MongoDB; Kafka supports asynchronous order processing. Docker Compose is the infrastructure entry point.  
Paths: `backend/server.js`, `frontend/src/main.jsx`, `docker-compose.yaml`

#### Frontend Application Shell
The browser entry mounts the React application, whose app/router layer selects login/register and operational pages. Shared layout/sidebar components form the authenticated dashboard shell. Axios centralizes API access, while React contexts carry authentication and voice-assistant state across pages.  
Paths: `frontend/src/main.jsx`, `frontend/src/App.jsx`, `frontend/src/api/axios.js`

#### Operational UI Domains
Pages map directly to the primary business domains: dashboard aggregation, stock/catalog management, ordering, finance, and workforce management. The voice assistant is a cross-cutting UI feature, likely backed by the AI API surface rather than embedded page logic.  
Paths: `frontend/src/pages/Dashboard.jsx`, `frontend/src/pages/Inventory.jsx`, `frontend/src/components/VoiceAssistant.jsx`

#### API Composition and Security Boundary
`server.js` composes Express, database/Kafka configuration, middleware, and resource routers. Controllers own HTTP-facing business workflows; route modules expose auth, product, order, sales, employee, and AI endpoints. JWT middleware establishes the protected API boundary and global error middleware normalizes failures.  
Paths: `backend/server.js`, `backend/middleware/auth.js`, `backend/middleware/errorHandler.js`

#### Domain Persistence Layer
Mongoose-style domain models represent the system of record: users, products, orders, sales, employees, and attendance. Controllers coordinate these entities—for example, orders affect inventory and sales-related records—rather than the frontend writing storage directly.  
Paths: `backend/models/Product.js`, `backend/models/Order.js`, `backend/models/Sale.js`

#### Order and Event-Driven Processing
Order requests flow through the order route/controller to create and update order state, then Kafka is used for decoupled asynchronous processing. The order consumer is the explicit worker boundary for handling order events, allowing downstream inventory, completion, or sales effects outside the synchronous request path.  
Paths: `backend/controllers/orderController.js`, `backend/config/kafka.js`, `backend/workers/orderConsumer.js`

#### Analytics, AI, and Decision Support
Sales endpoints provide finance/dashboard analytics over persisted sales and order data. AI and orchestration controllers expose a separate decision-support boundary, with demand prediction and employee/order pairing utilities supplying specialized logic. These should be treated as services layered over core operational data, not as source-of-record owners.  
Paths: `backend/controllers/salesController.js`, `backend/controllers/aiController.js`, `backend/utils/demandPredictor.js`

#### External Dependencies and Control Flow
Primary flow is browser → Axios/JWT → Express routes/controllers → MongoDB models, with Kafka for order-event consumption. MongoDB connection setup and Kafka client setup are explicit. The README declares Redis for caching/session use, but the supplied tree has no Redis configuration/service file; validate actual implementation before planning Redis-dependent work.  
Paths: `backend/config/db.js`, `backend/config/kafka.js`, `backend/package.json`

Main entry points: [`backend/models/Product.js`](https://github.com/durgesh-0001/retailflow/blob/main/backend/models/Product.js) (Domain models), [`backend/server.js`](https://github.com/durgesh-0001/retailflow/blob/main/backend/server.js) (Resource controllers), [`frontend/src/App.jsx`](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/App.jsx) (App and router), [`backend/controllers/orderController.js`](https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/orderController.js) (Order controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser App"]
  node_browser_entry["React entry<br/>React bootstrap<br/>[main.jsx]"]
  node_app_router["App and router<br/>application shell<br/>[App.jsx]"]
  node_operations_ui["Operational pages<br/>React pages<br/>[Dashboard.jsx]"]
  node_voice_assistant["Voice assistant<br/>cross-cutting UI<br/>[VoiceAssistant.jsx]"]
  node_api_client["Axios API client<br/>HTTP client<br/>[axios.js]"]
end

subgraph group_api["Backend API"]
  node_express_server["Express server<br/>REST composition<br/>[server.js]"]
  node_auth_boundary["JWT auth middleware<br/>security boundary<br/>[auth.js]"]
  node_error_handler["Error middleware<br/>failure boundary<br/>[errorHandler.js]"]
  node_resource_controllers["Resource controllers<br/>HTTP workflows<br/>[server.js]"]
  node_order_controller["Order controller<br/>order workflow<br/>[orderController.js]"]
  node_sales_analytics["Sales analytics<br/>analytics controller<br/>[salesController.js]"]
  node_ai_decision_support["AI decision support<br/>AI controller<br/>[aiController.js]"]
  node_demand_predictor["Demand predictor<br/>AI utility<br/>[demandPredictor.js]"]
end

subgraph group_processing["Async Processing"]
  node_kafka_client["Kafka client<br/>event transport<br/>[kafka.js]"]
  node_order_consumer["Order consumer<br/>async worker<br/>[orderConsumer.js]"]
end

subgraph group_data["Data Layer"]
  node_mongo_connection["MongoDB connection<br/>database setup<br/>[db.js]"]
  node_domain_models[("Domain models<br/>Mongoose models<br/>[Product.js]")]
  node_mongodb[("MongoDB<br/>persistent store")]
end

node_compose{{"Docker Compose<br/>infrastructure"}}

node_compose -->|"runs"| node_express_server
node_browser_entry -->|"mounts"| node_app_router
node_app_router -->|"renders"| node_operations_ui
node_app_router -->|"hosts"| node_voice_assistant
node_operations_ui -->|"uses"| node_api_client
node_voice_assistant -->|"uses"| node_api_client
node_api_client -->|"REST requests"| node_express_server
node_express_server -->|"protects routes with"| node_auth_boundary
node_auth_boundary -->|"authorizes"| node_resource_controllers
node_express_server -->|"normalizes failures via"| node_error_handler
node_resource_controllers -->|"dispatches orders to"| node_order_controller
node_resource_controllers -->|"dispatches sales to"| node_sales_analytics
node_resource_controllers -->|"dispatches AI requests to"| node_ai_decision_support
node_resource_controllers -->|"reads and writes"| node_domain_models
node_order_controller -->|"updates order state"| node_domain_models
node_order_controller -->|"publishes order events"| node_kafka_client
node_kafka_client -->|"delivers events"| node_order_consumer
node_order_consumer -->|"applies downstream effects"| node_domain_models
node_sales_analytics -->|"aggregates"| node_domain_models
node_ai_decision_support -->|"uses"| node_demand_predictor
node_ai_decision_support -->|"uses operational data"| node_domain_models
node_mongo_connection -->|"connects to"| node_mongodb
node_domain_models -->|"persists to"| node_mongodb

click node_compose "https://github.com/durgesh-0001/retailflow/blob/main/docker-compose.yaml"
click node_browser_entry "https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/main.jsx"
click node_app_router "https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/App.jsx"
click node_operations_ui "https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/pages/Dashboard.jsx"
click node_voice_assistant "https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/components/VoiceAssistant.jsx"
click node_api_client "https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/api/axios.js"
click node_express_server "https://github.com/durgesh-0001/retailflow/blob/main/backend/server.js"
click node_auth_boundary "https://github.com/durgesh-0001/retailflow/blob/main/backend/middleware/auth.js"
click node_error_handler "https://github.com/durgesh-0001/retailflow/blob/main/backend/middleware/errorHandler.js"
click node_resource_controllers "https://github.com/durgesh-0001/retailflow/blob/main/backend/server.js"
click node_order_controller "https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/orderController.js"
click node_sales_analytics "https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/salesController.js"
click node_ai_decision_support "https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/aiController.js"
click node_demand_predictor "https://github.com/durgesh-0001/retailflow/blob/main/backend/utils/demandPredictor.js"
click node_kafka_client "https://github.com/durgesh-0001/retailflow/blob/main/backend/config/kafka.js"
click node_order_consumer "https://github.com/durgesh-0001/retailflow/blob/main/backend/workers/orderConsumer.js"
click node_mongo_connection "https://github.com/durgesh-0001/retailflow/blob/main/backend/config/db.js"
click node_domain_models "https://github.com/durgesh-0001/retailflow/blob/main/backend/models/Product.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_browser_entry,node_app_router,node_operations_ui,node_voice_assistant,node_api_client toneBlue
class node_express_server,node_auth_boundary,node_error_handler,node_resource_controllers,node_order_controller,node_sales_analytics,node_ai_decision_support,node_demand_predictor toneAmber
class node_kafka_client,node_order_consumer toneMint
class node_mongo_connection,node_domain_models,node_mongodb toneRose
class node_compose toneNeutral
```

## Components

### Browser App

- [React entry](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/main.jsx): React bootstrap · `frontend/src/main.jsx`
- [App and router](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/App.jsx): application shell · Selects authentication and operational pages. · `frontend/src/App.jsx`
- [Operational pages](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/pages/Dashboard.jsx): React pages · Dashboard, inventory, ordering, finance, and workforce UI. · `frontend/src/pages/Dashboard.jsx`
- [Voice assistant](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/components/VoiceAssistant.jsx): cross-cutting UI · `frontend/src/components/VoiceAssistant.jsx`
- [Axios API client](https://github.com/durgesh-0001/retailflow/blob/main/frontend/src/api/axios.js): HTTP client · Centralizes API access and JWT-bearing requests. · `frontend/src/api/axios.js`

### Backend API

- [Express server](https://github.com/durgesh-0001/retailflow/blob/main/backend/server.js): REST composition · Composes middleware, routers, database, and Kafka setup. · `backend/server.js`
- [JWT auth middleware](https://github.com/durgesh-0001/retailflow/blob/main/backend/middleware/auth.js): security boundary · `backend/middleware/auth.js`
- [Error middleware](https://github.com/durgesh-0001/retailflow/blob/main/backend/middleware/errorHandler.js): failure boundary · Normalizes API failures. · `backend/middleware/errorHandler.js`
- [Resource controllers](https://github.com/durgesh-0001/retailflow/blob/main/backend/server.js): HTTP workflows · Own auth, product, order, sales, employee, and AI workflows. · `backend/server.js`
- [Order controller](https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/orderController.js): order workflow · Creates and updates order state and emits order events. · `backend/controllers/orderController.js`
- [Sales analytics](https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/salesController.js): analytics controller · Provides finance and dashboard analytics over operational data. · `backend/controllers/salesController.js`
- [AI decision support](https://github.com/durgesh-0001/retailflow/blob/main/backend/controllers/aiController.js): AI controller · Decision support layered over core operational data. · `backend/controllers/aiController.js`
- [Demand predictor](https://github.com/durgesh-0001/retailflow/blob/main/backend/utils/demandPredictor.js): AI utility · `backend/utils/demandPredictor.js`

### Async Processing

- [Kafka client](https://github.com/durgesh-0001/retailflow/blob/main/backend/config/kafka.js): event transport · `backend/config/kafka.js`
- [Order consumer](https://github.com/durgesh-0001/retailflow/blob/main/backend/workers/orderConsumer.js): async worker · Applies downstream order effects outside the request path. · `backend/workers/orderConsumer.js`

### Data Layer

- [MongoDB connection](https://github.com/durgesh-0001/retailflow/blob/main/backend/config/db.js): database setup · `backend/config/db.js`
- [Domain models](https://github.com/durgesh-0001/retailflow/blob/main/backend/models/Product.js): Mongoose models · Users, products, orders, sales, employees, and attendance are system-of-record entities. · `backend/models/Product.js`
- **MongoDB**: persistent store

### Other components

- [Docker Compose](https://github.com/durgesh-0001/retailflow/blob/main/docker-compose.yaml): infrastructure · Infrastructure entry point. · `docker-compose.yaml`

## Connections

- Docker Compose → Express server: runs
- React entry → App and router: mounts
- App and router → Operational pages: renders
- App and router → Voice assistant: hosts
- Operational pages → Axios API client: uses
- Voice assistant → Axios API client: uses
- Axios API client → Express server: REST requests
- Express server → JWT auth middleware: protects routes with
- JWT auth middleware → Resource controllers: authorizes
- Express server → Error middleware: normalizes failures via
- Resource controllers → Order controller: dispatches orders to
- Resource controllers → Sales analytics: dispatches sales to
- Resource controllers → AI decision support: dispatches AI requests to
- Resource controllers → Domain models: reads and writes
- Order controller → Domain models: updates order state
- Order controller → Kafka client: publishes order events
- Kafka client → Order consumer: delivers events
- Order consumer → Domain models: applies downstream effects
- Sales analytics → Domain models: aggregates
- AI decision support → Demand predictor: uses
- AI decision support → Domain models: uses operational data
- MongoDB connection → MongoDB: connects to
- Domain models → MongoDB: persists to
