How durgesh-0001/retailflow works
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: Product.js Domain models · server.js Resource controllers · App.jsx App and router · orderController.js Order controller
Components 19
Browser App
- React entry
frontend/src/main.jsx - App and router · Selects authentication and operational pages.
frontend/src/App.jsx - Operational pages · Dashboard, inventory, ordering, finance, and workforce UI.
frontend/src/pages/Dashboard.jsx - Voice assistant
frontend/src/components/VoiceAssistant.jsx - Axios API client · Centralizes API access and JWT-bearing requests.
frontend/src/api/axios.js
Backend API
- Express server · Composes middleware, routers, database, and Kafka setup.
backend/server.js - JWT auth middleware
backend/middleware/auth.js - Error middleware · Normalizes API failures.
backend/middleware/errorHandler.js - Resource controllers · Own auth, product, order, sales, employee, and AI workflows.
backend/server.js - Order controller · Creates and updates order state and emits order events.
backend/controllers/orderController.js - Sales analytics · Provides finance and dashboard analytics over operational data.
backend/controllers/salesController.js - AI decision support · Decision support layered over core operational data.
backend/controllers/aiController.js - Demand predictor
backend/utils/demandPredictor.js
Async Processing
- Kafka client
backend/config/kafka.js - Order consumer · Applies downstream order effects outside the request path.
backend/workers/orderConsumer.js
Data Layer
- MongoDB connection
backend/config/db.js - Domain models · Users, products, orders, sales, employees, and attendance are system-of-record entities.
backend/models/Product.js - MongoDB
Other components
- Docker Compose · Infrastructure entry point.
docker-compose.yaml
Connections 23
- 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