# rahul80010/billing-saas-backend architecture

> Architecture diagram of the GitHub repository rahul80010/billing-saas-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahul80010/billing-saas-backend
- Repository: https://github.com/rahul80010/billing-saas-backend

## Overview

MOHURI is a multi-tenant billing and business-management API for retail, restaurant, and hotel operations. A merchant request enters through the Express server and a domain route, then a controller performs the work against MongoDB-backed models; authentication protects many routes. Core workflows include catalog and billing, reporting, customer stock orders, restaurant and hotel operations, and media/AI features. The excerpts establish several controller-to-model and service calls; unsampled controller behavior is represented only where the source index or mounted routes identifies the subsystem.

Main entry points: [`server.js`](https://github.com/rahul80010/billing-saas-backend/blob/main/server.js) (Express API), [`controllers/billController.js`](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/billController.js) (Billing and invoices), [`models/Product.js`](https://github.com/rahul80010/billing-saas-backend/blob/main/models/Product.js) (Product records), [`controllers/stockSharingController.js`](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/stockSharingController.js) (Customer stock orders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_server["Express API<br/>[server.js]"]
  node_auth_routes["Authentication routes<br/>[authRoutes.js]"]
  node_auth_controller["Authentication<br/>[authController.js]"]
  node_auth_middleware["Token protection<br/>[authMiddleware.js]"]
  node_admin["Admin controls<br/>[adminController.js]"]
end

subgraph group_commerce["Catalog and billing"]
  node_catalog_routes["Catalog routes<br/>[productRoutes.js]"]
  node_catalog["Products and variants"]
  node_billing_routes["Billing routes<br/>[billRoutes.js]"]
  node_billing["Billing and invoices<br/>[billController.js]"]
  node_crm["Customer and CRM<br/>[crmController.js]"]
end

subgraph group_operations["Business operations"]
  node_stock_sharing["Customer stock orders"]
  node_restaurant["Restaurant operations"]
  node_hotel_routes["Hotel booking routes"]
  node_hotel["Hotel bookings"]
end

subgraph group_insights["Insights and media"]
  node_reports["Sales and expense reports"]
  node_gallery["Product image gallery"]
  node_ai["AI assistance<br/>[aiController.js]"]
end

subgraph group_platform["Persistence and services"]
  node_product_store[("Product records<br/>[Product.js]")]
  node_variant_store[("Variant records<br/>[ProductVariant.js]")]
  node_bill_store[("Bill records<br/>[Bill.js]")]
  node_pdf["Invoice PDFs<br/>[pdfService.js]"]
  node_whatsapp["WhatsApp messaging<br/>[whatsappService.js]"]
  node_customer_store[("Customer records<br/>[Customer.js]")]
  node_stock_order_store[("Stock orders<br/>[StockOrder.js]")]
  node_hotel_store[("Booking records<br/>[HotelBooking.js]")]
  node_image_search["Image search"]
  node_storage["Image storage<br/>[storageService.js]"]
  node_socket["Live updates<br/>[socketService.js]"]
  node_database[("MongoDB connection<br/>[db.js]")]
  node_user_store[("User records<br/>[User.js]")]
end

node_merchant(("Merchant"))

node_merchant -->|"sends requests"| node_server
node_server -->|"mounts routes"| node_auth_routes
node_server -->|"mounts routes"| node_catalog_routes
node_server -->|"mounts routes"| node_billing_routes
node_server -->|"mounts routes"| node_hotel_routes
node_server -->|"connects to"| node_database
node_server -->|"initializes"| node_socket
node_auth_routes -->|"dispatches to"| node_auth_controller
node_auth_routes -->|"protects routes"| node_auth_middleware
node_auth_middleware -->|"loads user"| node_user_store
node_auth_controller -->|"uses records"| node_user_store
node_catalog_routes -->|"dispatches to"| node_catalog
node_catalog -->|"uses records"| node_product_store
node_catalog -->|"uses records"| node_variant_store
node_billing_routes -->|"dispatches to"| node_billing
node_billing -->|"reads and writes"| node_bill_store
node_billing -->|"uses products"| node_product_store
node_billing -->|"uses variants"| node_variant_store
node_billing -->|"generates invoices"| node_pdf
node_billing -->|"sends messages"| node_whatsapp
node_crm -.->|"uses records"| node_customer_store
node_reports -->|"reads sales"| node_bill_store
node_reports -->|"reads products"| node_product_store
node_reports -->|"reads customers"| node_customer_store
node_stock_sharing -->|"creates orders"| node_stock_order_store
node_stock_sharing -->|"checks products"| node_product_store
node_stock_sharing -->|"checks variants"| node_variant_store
node_stock_sharing -->|"saves customers"| node_customer_store
node_hotel_routes -->|"dispatches to"| node_hotel
node_hotel -->|"reads and writes"| node_hotel_store
node_hotel -->|"emits updates"| node_socket
node_hotel -->|"uses products"| node_product_store
node_gallery -->|"searches images"| node_image_search
node_gallery -->|"uploads assets"| node_storage
node_gallery -->|"searches products"| node_product_store
node_ai -->|"uses products"| node_product_store
node_ai -->|"uses bills"| node_bill_store
node_reports -.->|"requests insights"| node_ai

click node_server "https://github.com/rahul80010/billing-saas-backend/blob/main/server.js"
click node_auth_routes "https://github.com/rahul80010/billing-saas-backend/blob/main/routes/authRoutes.js"
click node_auth_controller "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/authController.js"
click node_auth_middleware "https://github.com/rahul80010/billing-saas-backend/blob/main/middleware/authMiddleware.js"
click node_admin "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/adminController.js"
click node_catalog_routes "https://github.com/rahul80010/billing-saas-backend/blob/main/routes/productRoutes.js"
click node_catalog "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/productController.js"
click node_product_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/Product.js"
click node_variant_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/ProductVariant.js"
click node_billing_routes "https://github.com/rahul80010/billing-saas-backend/blob/main/routes/billRoutes.js"
click node_billing "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/billController.js"
click node_bill_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/Bill.js"
click node_pdf "https://github.com/rahul80010/billing-saas-backend/blob/main/services/pdfService.js"
click node_whatsapp "https://github.com/rahul80010/billing-saas-backend/blob/main/services/whatsappService.js"
click node_crm "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/crmController.js"
click node_customer_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/Customer.js"
click node_reports "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/reportController.js"
click node_stock_sharing "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/stockSharingController.js"
click node_stock_order_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/StockOrder.js"
click node_restaurant "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/restaurantController.js"
click node_hotel_routes "https://github.com/rahul80010/billing-saas-backend/blob/main/routes/hotelBookingRoutes.js"
click node_hotel "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/hotelBookingController.js"
click node_hotel_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/HotelBooking.js"
click node_gallery "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/galleryController.js"
click node_image_search "https://github.com/rahul80010/billing-saas-backend/blob/main/services/productImageSearchService.js"
click node_storage "https://github.com/rahul80010/billing-saas-backend/blob/main/services/storageService.js"
click node_ai "https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/aiController.js"
click node_socket "https://github.com/rahul80010/billing-saas-backend/blob/main/services/socketService.js"
click node_database "https://github.com/rahul80010/billing-saas-backend/blob/main/config/db.js"
click node_user_store "https://github.com/rahul80010/billing-saas-backend/blob/main/models/User.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_server,node_auth_routes,node_auth_controller,node_auth_middleware,node_admin toneBlue
class node_catalog_routes,node_catalog,node_billing_routes,node_billing,node_crm toneAmber
class node_stock_sharing,node_restaurant,node_hotel_routes,node_hotel toneMint
class node_reports,node_gallery,node_ai toneRose
class node_product_store,node_variant_store,node_bill_store,node_pdf,node_whatsapp,node_customer_store,node_stock_order_store,node_hotel_store,node_image_search,node_storage,node_socket,node_database,node_user_store,node_merchant toneIndigo
```

## Components

### API and identity

- [Express API](https://github.com/rahul80010/billing-saas-backend/blob/main/server.js): `server.js`
- [Authentication routes](https://github.com/rahul80010/billing-saas-backend/blob/main/routes/authRoutes.js): `routes/authRoutes.js`
- [Authentication](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/authController.js): `controllers/authController.js`
- [Token protection](https://github.com/rahul80010/billing-saas-backend/blob/main/middleware/authMiddleware.js): `middleware/authMiddleware.js`
- [Admin controls](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/adminController.js): `controllers/adminController.js`

### Catalog and billing

- [Catalog routes](https://github.com/rahul80010/billing-saas-backend/blob/main/routes/productRoutes.js): `routes/productRoutes.js`
- [Products and variants](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/productController.js): `controllers/productController.js`
- [Billing routes](https://github.com/rahul80010/billing-saas-backend/blob/main/routes/billRoutes.js): `routes/billRoutes.js`
- [Billing and invoices](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/billController.js): `controllers/billController.js`
- [Customer and CRM](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/crmController.js): `controllers/crmController.js`

### Business operations

- [Customer stock orders](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/stockSharingController.js): `controllers/stockSharingController.js`
- [Restaurant operations](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/restaurantController.js): `controllers/restaurantController.js`
- [Hotel booking routes](https://github.com/rahul80010/billing-saas-backend/blob/main/routes/hotelBookingRoutes.js): `routes/hotelBookingRoutes.js`
- [Hotel bookings](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/hotelBookingController.js): `controllers/hotelBookingController.js`

### Insights and media

- [Sales and expense reports](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/reportController.js): `controllers/reportController.js`
- [Product image gallery](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/galleryController.js): `controllers/galleryController.js`
- [AI assistance](https://github.com/rahul80010/billing-saas-backend/blob/main/controllers/aiController.js): `controllers/aiController.js`

### Persistence and services

- [Product records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/Product.js): `models/Product.js`
- [Variant records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/ProductVariant.js): `models/ProductVariant.js`
- [Bill records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/Bill.js): `models/Bill.js`
- [Invoice PDFs](https://github.com/rahul80010/billing-saas-backend/blob/main/services/pdfService.js): `services/pdfService.js`
- [WhatsApp messaging](https://github.com/rahul80010/billing-saas-backend/blob/main/services/whatsappService.js): `services/whatsappService.js`
- [Customer records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/Customer.js): `models/Customer.js`
- [Stock orders](https://github.com/rahul80010/billing-saas-backend/blob/main/models/StockOrder.js): `models/StockOrder.js`
- [Booking records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/HotelBooking.js): `models/HotelBooking.js`
- [Image search](https://github.com/rahul80010/billing-saas-backend/blob/main/services/productImageSearchService.js): `services/productImageSearchService.js`
- [Image storage](https://github.com/rahul80010/billing-saas-backend/blob/main/services/storageService.js): `services/storageService.js`
- [Live updates](https://github.com/rahul80010/billing-saas-backend/blob/main/services/socketService.js): `services/socketService.js`
- [MongoDB connection](https://github.com/rahul80010/billing-saas-backend/blob/main/config/db.js): `config/db.js`
- [User records](https://github.com/rahul80010/billing-saas-backend/blob/main/models/User.js): `models/User.js`

### Other components

- **Merchant**

## Connections

- Merchant → Express API: sends requests (evidence: `server.js`)
- Express API → Authentication routes: mounts routes (evidence: `server.js`)
- Express API → Catalog routes: mounts routes (evidence: `server.js`)
- Express API → Billing routes: mounts routes (evidence: `server.js`)
- Express API → Hotel booking routes: mounts routes (evidence: `server.js`)
- Express API → MongoDB connection: connects to (evidence: `server.js`)
- Express API → Live updates: initializes (evidence: `server.js`)
- Authentication routes → Authentication: dispatches to (evidence: `routes/authRoutes.js`)
- Authentication routes → Token protection: protects routes (evidence: `routes/authRoutes.js`)
- Token protection → User records: loads user (evidence: `middleware/authMiddleware.js`)
- Authentication → User records: uses records (evidence: `controllers/authController.js`)
- Catalog routes → Products and variants: dispatches to
- Products and variants → Product records: uses records
- Products and variants → Variant records: uses records
- Billing routes → Billing and invoices: dispatches to (evidence: `routes/billRoutes.js`)
- Billing and invoices → Bill records: reads and writes (evidence: `controllers/billController.js`)
- Billing and invoices → Product records: uses products (evidence: `controllers/billController.js`)
- Billing and invoices → Variant records: uses variants (evidence: `controllers/billController.js`)
- Billing and invoices → Invoice PDFs: generates invoices (evidence: `controllers/billController.js`)
- Billing and invoices → WhatsApp messaging: sends messages (evidence: `controllers/billController.js`)
- Customer and CRM → Customer records: uses records
- Sales and expense reports → Bill records: reads sales (evidence: `controllers/reportController.js`)
- Sales and expense reports → Product records: reads products (evidence: `controllers/reportController.js`)
- Sales and expense reports → Customer records: reads customers (evidence: `controllers/reportController.js`)
- Customer stock orders → Stock orders: creates orders (evidence: `controllers/stockSharingController.js`)
- Customer stock orders → Product records: checks products (evidence: `controllers/stockSharingController.js`)
- Customer stock orders → Variant records: checks variants (evidence: `controllers/stockSharingController.js`)
- Customer stock orders → Customer records: saves customers (evidence: `controllers/stockSharingController.js`)
- Hotel booking routes → Hotel bookings: dispatches to (evidence: `routes/hotelBookingRoutes.js`)
- Hotel bookings → Booking records: reads and writes (evidence: `controllers/hotelBookingController.js`)
- Hotel bookings → Live updates: emits updates (evidence: `controllers/hotelBookingController.js`)
- Hotel bookings → Product records: uses products (evidence: `controllers/hotelBookingController.js`)
- Product image gallery → Image search: searches images (evidence: `controllers/galleryController.js`)
- Product image gallery → Image storage: uploads assets (evidence: `controllers/galleryController.js`)
- Product image gallery → Product records: searches products (evidence: `controllers/galleryController.js`)
- AI assistance → Product records: uses products (evidence: `controllers/aiController.js`)
- AI assistance → Bill records: uses bills (evidence: `controllers/aiController.js`)
- Sales and expense reports → AI assistance: requests insights
