How shivakumart67/inventory-management works
Purpose and entry points
This is a TypeScript business-operations system for managing users, purchases, sales, expenses, inventory, activity logs, dashboards, and reports. It has separate backend API and frontend SPA applications.
• Backend process entry: backend/src/server.ts
• Frontend browser entry and application composition: frontend/src/main.tsx, frontend/src/App.tsx
• API surface is centrally registered in backend/src/routes/api.ts
Backend API and request boundary
The backend is a Node/TypeScript HTTP service organized as routes → middleware → controllers → models/services. Controllers expose domain endpoints for authentication, users, stock, transactions, reporting, dashboard metrics, activities, and site configuration.
• Routing: backend/src/routes/api.ts
• Request protection: backend/src/middleware/auth.ts
• Global failure boundary: backend/src/middleware/errorHandler.ts
• Representative endpoint handlers: backend/src/controllers/authController.ts, backend/src/controllers/transactionController.ts, backend/src/controllers/reportController.ts
Identity, roles, and application access
Authentication is enforced at the API boundary and reflected in the frontend’s protected-page flow. User administration and role-specific dashboards imply distinct operational access levels, including admin and manager views.
• Backend identity model and controller: backend/src/models/User.ts, backend/src/controllers/userController.ts
• Frontend auth state and route guard: frontend/src/context/AuthContext.tsx, frontend/src/components/Protected.tsx
• Role-oriented views: frontend/src/pages/Dashboard/AdminDashboard.tsx, frontend/src/pages/Dashboard/ManagerDashboard.tsx
Transaction-to-inventory flow
Purchases and sales are primary operational inputs. Stock is represented both as a movement ledger and an aggregated summary, with a dedicated stock service likely serving as the consistency boundary between transaction recording and inventory state.
• Transaction persistence: backend/src/models/Purchase.ts, backend/src/models/Sale.ts
• Inventory representations: backend/src/models/StockLedger.ts, backend/src/models/StockSummary.ts
• Inventory orchestration and API: backend/src/services/stockService.ts, backend/src/controllers/stockController.ts
• Corresponding workflows: frontend/src/pages/Purchases/AddPurchase.tsx, frontend/src/pages/Sales/AddSale.tsx, frontend/src/pages/Stock/StockSummary.tsx
Financial, reporting, and export flow
Expense capture, transaction data, and stock data feed dashboard and MIS/reporting endpoints. Reporting is separated from export/PDF generation, creating a boundary where operational data becomes downloadable or printable output.
• Expense domain: backend/src/models/Expense.ts, backend/src/models/ExpenseCategory.ts
• Dashboard/report APIs: backend/src/controllers/dashboardController.ts, backend/src/controllers/reportController.ts
• Output services: backend/src/services/exportService.ts, backend/src/services/pdfService.ts
• Reporting UI: frontend/src/pages/Reports/ReportsDashboard.tsx, frontend/src/pages/Reports/MISDashboard.tsx
Audit, configuration, and state management
Activity logging captures operational events as a cross-cutting audit capability. Site configuration is managed through its own API and frontend context. The backend has database configuration and a lightweight cache utility; persistence infrastructure details are not documented in the supplied README.
• Audit layer: backend/src/models/ActivityLog.ts, backend/src/services/activityService.ts
• Site settings: backend/src/models/SiteConfig.ts, backend/src/controllers/siteConfigController.ts, frontend/src/context/SiteConfigContext.tsx
• Infrastructure utilities: backend/src/config/db.ts, backend/src/utils/simpleCache.ts
Frontend integration boundary
The frontend is a Vite-based TypeScript SPA that uses a centralized API client, shared layout, contexts, and page-level domain workflows. It communicates with the backend rather than directly with persistence or report-generation services.
• API client: frontend/src/services/api.ts
• Shared shell and loading behavior: frontend/src/components/Layout/AppLayout.tsx, frontend/src/components/GlobalLoader.tsx
• Build/deployment indicators: frontend/vite.config.ts, frontend/vercel.json
Main entry points: services/api.ts Central API client · routes/api.ts API route registry · server.ts Backend process · auth.ts Authentication middleware
Components 22
Frontend SPA
- SPA entry & composition
- Auth state & page guard
- Purchase & sale workflows
- Stock summary view
frontend/src/pages/Stock/StockSummary.tsx - Reports & MIS views
- Admin & manager dashboards
- Site configuration state
frontend/src/context/SiteConfigContext.tsx - Central API client
frontend/src/services/api.ts
Backend API
- Backend process
backend/src/server.ts - API route registry
backend/src/routes/api.ts - Authentication middleware
backend/src/middleware/auth.ts - Domain controllers · Auth, user, transaction, stock, dashboard, report, and configuration endpoints.
- Global error handler
backend/src/middleware/errorHandler.ts
Operations & Reporting
- Stock consistency service · Maintains inventory from transaction activity.
backend/src/services/stockService.ts - Purchases & sales
- Stock ledger & summary · Movement ledger plus aggregated stock state.
- Expenses
- Export & PDF generation
Persistence & Support
- Users & roles
- Activity audit log
- Site configuration
- Database & cache
Connections 26
- SPA entry & composition → Auth state & page guard: applies access flow
- SPA entry & composition → Central API client: uses
- Purchase & sale workflows → Central API client: submits transactions
- Stock summary view → Central API client: reads stock
- Reports & MIS views → Central API client: requests reports
- Admin & manager dashboards → Central API client: requests metrics
- Site configuration state → Central API client: manages settings
- Central API client → Backend process: HTTP requests
- Backend process → API route registry: registers
- API route registry → Authentication middleware: protects requests
- Authentication middleware → Domain controllers: authorizes
- API route registry → Global error handler: routes failures to
- Domain controllers → Users & roles: authenticates and manages users
- Domain controllers → Purchases & sales: records purchases and sales
- Domain controllers → Stock consistency service: invokes inventory updates
- Stock consistency service → Stock ledger & summary: writes movements and summaries
- Domain controllers → Expenses: captures expenses
- Domain controllers → Export & PDF generation: generates exports
- Domain controllers → Site configuration: manages settings
- Domain controllers → Activity audit log: records activity
- Purchases & sales → Database & cache: persists through
- Stock ledger & summary → Database & cache: persists through
- Expenses → Database & cache: persists through
- Users & roles → Database & cache: persists through
- Activity audit log → Database & cache: persists through
- Site configuration → Database & cache: persists through