Billcraft Server
Business Billing Suite - ServerNirman Bahi Khata Pro - Server A production-ready Node.js backend for billing and inventory management with JWT authentication, role-based access con...
Technical Architecture & Engineering Overview
Detailed system design and core implementation
Core Architecture
The server follows a classic micro‑service style, with a single Express application exposing a set of RESTful routes grouped by domain: auth, products, customers, shops, and bills. Each route file delegates business logic to a dedicated controller, keeping the routing layer thin and the controllers focused on orchestrating data access via Mongoose models.
Data Ingestion & Persistence
All domain entities are persisted in a MongoDB Atlas cluster named construction_billing. Mongoose schemas enforce field types, required constraints, and custom validation logic. The application uses a soft delete strategy for products, customers, shops, and bills, marking records with an isActive flag instead of physically removing them, which preserves historical data for audit and reporting.
Execution Flow
A typical request follows this pipeline: the request hits an Express route, passes through AuthMiddleware (token verification, role checks, and rate limiting), then ValidationMiddleware (schema validation via validator), and finally the controller performs the requested CRUD operation. Responses are sent with standardized JSON payloads, and errors are caught by a global error‑handling middleware that logs details via morgan and returns a sanitized error message.
Security Guardrails & Build Topology
Security is layered: helmet sets secure HTTP headers, cors restricts origins, express‑rate‑limit throttles authentication endpoints, and JWTs are signed with a secret stored in environment variables. The build topology is simple: the start script runs node index.js, while dev uses nodemon for hot reloading. Deployment instructions in DEPLOYMENT.md outline a CI‑CD pipeline that builds the Docker image, pushes to a registry, and deploys to a cloud provider, with the frontend served from Vercel, Netlify, or Render.
System Diagrams & Flow Visualizations
Interactive Mermaid architecture & execution flows
Core System Features
Key capabilities & architectural features
JWT authentication with role‑based access control
JWT authentication with role‑based access control
Rate limiting on authentication endpoints
Rate limiting on authentication endpoints
Soft delete strategy for all domain entities
Soft delete strategy for all domain entities
Meta endpoints for product categories and brands
Meta endpoints for product categories and brands
Shop analytics and shop‑wise analysis endpoints
Shop analytics and shop‑wise analysis endpoints
Pagination and filtering for shop listings
Pagination and filtering for shop listings
Structured logging with Morgan
Structured logging with Morgan
Security headers via Helmet and CORS protection
Security headers via Helmet and CORS protection
Environment‑based configuration with dotenv
Environment‑based configuration with dotenv
CLI scripts for creating admin and shop users
CLI scripts for creating admin and shop users
Engineering Challenges & Solutions
Problem statements & resolution strategies
Balancing security and usability while implementing rate limiting on login routes
Balancing security and usability while implementing rate limiting on login routes
Designing a soft delete mechanism that preserves historical data without cluttering queries
Designing a soft delete mechanism that preserves historical data without cluttering queries
Ensuring consistent error handling across all controllers and middleware
Ensuring consistent error handling across all controllers and middleware
Managing environment variables securely for JWT secrets and DB connection strings
Managing environment variables securely for JWT secrets and DB connection strings
Optimizing shop analytics queries to aggregate data efficiently
Optimizing shop analytics queries to aggregate data efficiently
API Reference & Endpoints
REST API surface & route documentation
| METHOD | ENDPOINT PATH | DESCRIPTION | COPY |
|---|---|---|---|
| GET | / | Endpoint defined in index.js | |
| GET | /health | Endpoint defined in index.js | |
| POST | /admin/register | Endpoint defined in routes/auth.js | |
| POST | /admin/login | Endpoint defined in routes/auth.js | |
| POST | /shop/login | Endpoint defined in routes/auth.js | |
| POST | /refresh | Endpoint defined in routes/auth.js | |
| POST | /logout | Endpoint defined in routes/auth.js | |
| GET | /profile | Endpoint defined in routes/auth.js | |
| PUT | /change-password | Endpoint defined in routes/auth.js | |
| GET | /verify | Endpoint defined in routes/auth.js | |
| GET | /number/:billNumber | Endpoint defined in routes/bills.js | |
| GET | /:id | Endpoint defined in routes/bills.js | |
| POST | / | Endpoint defined in routes/bills.js | |
| PUT | /:id | Endpoint defined in routes/bills.js | |
| DELETE | /:id | Endpoint defined in routes/bills.js | |
| POST | /update-pending-amounts | Endpoint defined in routes/customers.js | |
| GET | /analytics | Endpoint defined in routes/dashboard.js | |
| GET | /shop-wise-analysis | Endpoint defined in routes/dashboard.js | |
| GET | /shop-analytics/:shopId | Endpoint defined in routes/dashboard.js | |
| GET | /meta/categories | Endpoint defined in routes/products.js | |
| GET | /meta/brands | Endpoint defined in routes/products.js | |
| GET | /:shopId | Endpoint defined in routes/shops.js | |
| PUT | /:shopId | Endpoint defined in routes/shops.js | |
| DELETE | /:shopId | Endpoint defined in routes/shops.js |
Key Code Modules & Architecture
Core file entrypoints and service responsibilities
configModule component managing config source logic
controllersModule component managing controllers source logic
middlewareModule component managing middleware source logic
modelsModule component managing models source logic
routesModule component managing routes source logic
scriptsModule component managing scripts source logic
servicesModule component managing services source logic
utilsModule component managing utils source logic
User Journey Pipeline
- 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
- 2Client Payload Dispatch: Front-end components (React) serialize input objects and send HTTP/WebSocket requests to `/`.
- 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
- 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
- 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.
Execution Code Flow
- 1Client or caller initiates request to application entrypoint
- 2Backend router validates request parameters and applies middleware
- 3Database ORM/client executes storage query
- 4Application serializes JSON/audio/data response back to client
System FAQ & Technical Specifications
Frequently asked questions and core architecture details
Q: What technologies are used in Billcraft Server?
Billcraft Server is engineered using modern full-stack frameworks.
Q: What core engineering problem does Billcraft Server solve?
Business Billing Suite - ServerNirman Bahi Khata Pro - Server A production-ready Node.js backend for billing and inventory management with JWT authentication, role-based access con...
Q: How is 'Balancing security and usability while implementing rate limiting on login routes' resolved in Billcraft Server?
Resolved through specialized system architecture and resilient state handling.
Related Systems & Case Studies
Explore similar technical architectures and projects