How bhanusunrise/hms-backend works
1. This is a NestJS backend application in TypeScript. The architecture is module-based: AppModule composes a set of feature modules, and each feature typically exposes a controller, service, DTOs, and tests.
2. The request path is conventional NestJS: HTTP request enters a controller, DTOs define and validate input shape, the service contains business logic, and shared infrastructure is injected through modules/providers. There is no frontend in this repo; this is the server-side domain layer.
3. The core domain is a retail/inventory management system. The major business modules are items, inventory, stock-batches, billing, returns, supplier_orders, supplier-returns, suppliers, transactions, accounts, locations, units, and users. These look like the system’s operational backbone for catalog, stock, sales, purchasing, and returns.
4. Master/reference data is separated into its own modules: items, units, locations, suppliers, accounts, and users. These are likely used by the transactional modules as shared entities, so the diagram should treat them as foundational services rather than one-off endpoints.
5. Transactional flows are centered on sales and procurement. billing manages sales creation, returns handles customer return processing, supplier_orders covers inbound purchasing, and supplier-returns likely handles reverse logistics to suppliers. transactions appears to be a ledger or event record layer that other workflows may write to for financial tracking.
6. Stock management is split into inventory and stock-batches. That suggests inventory is the aggregate stock view, while stock batches capture lot-level or batch-level movement/history. barcode is a separate module, likely used to generate or resolve product identifiers for scanning workflows.
7. Analytics and operational visibility are handled by dashboard and reports. The reports module has distinct query DTOs for financial, sales, and inventory reports, so reporting is not just a generic endpoint; it is a dedicated read path over domain data with query-driven filtering.
8. Authentication and authorization are a clear cross-cutting subsystem. auth includes JWT utilities, jwt.guard, roles.guard, and decorators such as public and roles. This implies route-level access control with protected endpoints and role-based authorization layered on top of authentication.
9. Notifications and generated content are isolated in mail and common/utils. The mail module includes templates for OTP, password, and welcome messages, while shared utilities generate OTPs and passwords. That means account lifecycle flows probably trigger email-based onboarding and verification.
10. External/infrastructure integration is abstracted behind supabase, storage, and mail. supabase likely provides the backend data connection/provider, storage handles file/object storage concerns, and mail encapsulates outbound email delivery. These are the main non-domain boundaries in the system.
11. DTOs are used extensively, including nested DTO folders for complex payloads like sales, returns, and supplier returns. That indicates the API is designed around structured command objects rather than leaking persistence models directly into controllers.
12. Tests are present at both unit/service level and end-to-end level. The repo includes *.spec.ts files beside most modules plus a test/app.e2e-spec.ts, so architecture should show both isolated service behavior and full application wiring under Nest’s test harness.
13. In diagram terms, the most important boundaries are: HTTP/API layer, auth/guard layer, domain service layer, infrastructure adapters, and external systems. The runtime is Node.js with NestJS, and the application is organized as a cohesive monolith rather than microservices.
Main entry points: app.module.ts AppModule · auth Auth · billing Billing · inventory Inventory
Components 22
Runtime & bootstrap
NestJS application bootstrap and top-level composition.
Domain modules
Core retail, inventory, purchasing, and reference-data modules.
- Users · User account management and identity data.
src/users - Items · Product/item master data.
src/items - Units · Measurement units for catalog and inventory.
src/units - Locations · Physical or logical stock locations.
src/locations - Suppliers · Supplier master data.
src/suppliers - Inventory · Current stock and availability view.
src/inventory - Stock batches · Lot/batch-level stock tracking and movement history.
src/stock-batches - Billing · Sales creation and billing workflow.
src/billing - Returns · Customer return processing.
src/returns - Supplier orders · Inbound purchasing and supplier order processing.
src/supplier_orders - Supplier returns · Returns sent back to suppliers.
src/supplier-returns - Transactions · Financial or event record layer shared by workflows.
src/transactions - Barcode · Barcode generation or lookup for scanning workflows.
src/barcode
Infrastructure
Cross-cutting auth, persistence, storage, email, and shared utilities.
- Auth · JWT auth, guards, and role decorators.
src/auth - Supabase · Backend data connection/provider layer.
src/supabase - Storage · File/object storage integration.
src/storage - Mail · Outbound email delivery and templates.
src/mail - Common utils · OTP and password generation utilities.
src/common/utils
Connections 48
- main.ts → AppModule: boots · Application bootstrap loads the root module.
- AppModule → Auth: imports · Root module composes authentication.
- AppModule → Supabase: imports · Root module wires the data provider.
- AppModule → Storage: imports · Root module wires storage services.
- AppModule → Mail: imports · Root module wires email services.
- AppModule → Users: imports · Root module composes identity management.
- AppModule → Items: imports · Root module composes catalog management.
- AppModule → Units: imports · Root module composes unit reference data.
- AppModule → Locations: imports · Root module composes location reference data.
- AppModule → Suppliers: imports · Root module composes supplier reference data.
- AppModule → Inventory: imports · Root module composes inventory management.
- AppModule → Stock batches: imports · Root module composes batch tracking.
- AppModule → Billing: imports · Root module composes sales flow.
- AppModule → Returns: imports · Root module composes customer returns.
- AppModule → Supplier orders: imports · Root module composes purchasing flow.
- AppModule → Supplier returns: imports · Root module composes supplier returns.
- AppModule → Transactions: imports · Root module composes the transaction ledger.
- AppModule → Barcode: imports · Root module composes barcode services.
- AppModule → Dashboard: imports · Root module composes operational dashboard.
- AppModule → Reports: imports · Root module composes reporting.
- Auth → Users: protects · Authentication and roles gate user-facing routes.
- Auth → Billing: guards · Sales actions are protected by auth.
- Auth → Returns: guards · Return actions are protected by auth.
- Auth → Supplier orders: guards · Purchasing actions are protected by auth.
- Auth → Supplier returns: guards · Supplier return actions are protected by auth.
- Auth → Reports: guards · Reporting access is protected by auth.
- Mail → Common utils: uses · Mail flows use generated OTP/password content.
- Users → Mail: triggers · User lifecycle flows can send onboarding and verification email.
- Billing → Items: reads · Sales need catalog item data.
- Billing → Inventory: updates · Sales reduce available stock.
- Billing → Transactions: writes · Sales are recorded in the ledger.
- Returns → Billing: references · Returns are tied back to sales.
- Returns → Inventory: updates · Customer returns restore stock.
- Returns → Transactions: writes · Return events are written to the ledger.
- Supplier orders → Suppliers: reads · Purchasing uses supplier master data.
- Supplier orders → Inventory: updates · Inbound purchasing increases stock.
- Supplier orders → Transactions: writes · Purchase events are recorded.
- Supplier returns → Suppliers: reads · Reverse logistics uses supplier data.
- Supplier returns → Inventory: updates · Supplier returns adjust stock.
- Supplier returns → Transactions: writes · Supplier return events are recorded.
- Inventory → Stock batches: tracks · Inventory is backed by batch-level movement.
- Stock batches → Items: references · Batches are associated with items.
- Stock batches → Locations: references · Batch movements are tied to locations.
- Barcode → Items: encodes · Barcodes resolve product identifiers.
- Dashboard → Reports: summarizes · Dashboard surfaces report-like metrics.
- Reports → Billing: queries · Sales reports read billing data.
- Reports → Inventory: queries · Inventory reports read stock data.
- Reports → Transactions: queries · Financial reports read ledger data.