A production-ready NestJS backend for managing multiple restaurants
Features • Getting Started • API Documentation • Architecture • Contributing
Multi-Restaurant Manager is a comprehensive backend solution designed for restaurant chains and food service businesses. Built with NestJS and following industry best practices, it provides a robust foundation for managing restaurants, orders, payments, and staff across multiple locations.
- Restaurant Management — Create and manage multiple restaurants with detailed profiles
- Menu Management — Dynamic menu items with categories, pricing, and availability
- Table Management — Visual table layouts with real-time status tracking
- Order Processing — Full order lifecycle from draft to completion
- Payment Integration — Cash and QR code payment methods
- Staff Management — Role-based staff assignment with shift tracking
- JWT Authentication — Access/Refresh token pattern with automatic rotation
- Two-Factor Authentication — Email-based OTP for enhanced security
- Session Management — Multi-device support with session tracking
- OAuth2 Integration — Google authentication support
- Rate Limiting — Configurable throttling per endpoint
- Role-Based Access — Granular permission system (
admin,owner,manager,cashier,waiter,kitchen)
- Real-Time Updates — Server-Sent Events (SSE) for live order notifications
- Background Jobs — BullMQ for async tasks (emails, notifications)
- Structured Logging — Winston with daily log rotation
- API Documentation — Auto-generated Swagger/OpenAPI docs
- Request Validation — Class-validator with custom pipes
| Category | Technology |
|---|---|
| Framework | NestJS 11 (Express) |
| Language | TypeScript 5.7 |
| Database | MongoDB + Mongoose ODM |
| Cache/Queue | Redis + ioredis |
| Job Queue | BullMQ |
| Authentication | JWT, Passport, bcrypt |
| Nodemailer | |
| Documentation | Swagger/OpenAPI |
| Logging | Winston |
- Node.js >= 20.x
- pnpm >= 8.x (recommended) or npm
- MongoDB >= 6.x
- Redis >= 7.x
# Clone the repository
git clone https://github.com/dinhdev-nu/multi-restaurant-manager-nestjs.git
cd multi-restaurant-manager-nestjs
# Install dependencies
pnpm install
# Copy environment file
cp .env.example .envEdit the .env file with your settings:
# Server
NODE_ENV=development
HOST=localhost
PORT=3000
# Database
MONGO_URI=mongodb://localhost:27017/restaurant-manager
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# JWT
JWT_ACCESS_SECRET=your-access-secret
JWT_ACCESS_TTL=15m
JWT_REFRESH_SECRET=your-refresh-secret
JWT_REFRESH_TTL=7d
# Email (SMTP)
SMTP_SERVICE=gmail
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
# OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/auths/oauth/google/callback
# Client
CLIENT_URL=http://localhost:3001# Development
pnpm run start:dev
# Production build
pnpm run build
pnpm run start:prod
# Debug mode
pnpm run start:debugThe API will be available at http://localhost:3000
Once the server is running, access the interactive API documentation:
- Swagger UI: http://localhost:3000/docs
- OpenAPI JSON: http://localhost:3000/docs-json
| Module | Base Path | Description |
|---|---|---|
| Auth | /auths |
Authentication, registration, 2FA, sessions |
| Restaurant | /restaurants |
Restaurant CRUD, menu, tables, staff |
| Order | /orders |
Order management and status tracking |
| Payment | /payments |
Payment processing |
| Events | /events |
Real-time SSE subscriptions |
Authentication Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST |
/auths/register |
Register new account |
POST |
/auths/login |
Login with email/phone |
POST |
/auths/verify-otp |
Verify email OTP |
POST |
/auths/refresh-token |
Refresh access token |
POST |
/auths/logout |
Logout current session |
POST |
/auths/logout-all |
Logout all sessions |
POST |
/auths/forgot-password |
Request password reset |
POST |
/auths/reset-password |
Set new password |
POST |
/auths/2fa/enable |
Enable two-factor auth |
POST |
/auths/2fa/send-otp |
Send 2FA OTP |
GET |
/auths/sessions |
List active sessions |
DELETE |
/auths/sessions |
Revoke session |
Restaurant Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST |
/restaurants |
Create restaurant |
PUT |
/restaurants/:id |
Update restaurant |
GET |
/restaurants/my-restaurants |
Get user's restaurants |
GET |
/restaurants/detail/:id |
Get restaurant details |
POST |
/restaurants/:id/open |
Open restaurant |
POST |
/restaurants/:id/close |
Close restaurant |
POST |
/restaurants/item |
Create menu item |
GET |
/restaurants/:id/items |
Get menu items |
POST |
/restaurants/table |
Create table |
GET |
/restaurants/:id/tables |
Get tables |
POST |
/restaurants/staff |
Add staff member |
GET |
/restaurants/:id/staffs |
Get staff list |
Order Endpoints
| Method | Endpoint | Description |
|---|---|---|
POST |
/orders |
Create order |
POST |
/orders/draft |
Create draft order |
GET |
/orders/drafts/:restaurantId |
Get draft orders |
POST |
/orders/change-status |
Update order status |
GET |
/orders/:restaurantId |
Get orders (paginated) |
GET |
/orders/checkout/:orderId |
Get checkout details |
src/
├── main.ts # Application entry point
├── app.module.ts # Root module
├── common/ # Shared utilities
│ ├── configs/ # Validation pipes
│ ├── constants/ # Error codes, roles, tokens
│ ├── decorators/ # Custom decorators
│ ├── dto/ # Shared DTOs
│ ├── exceptions/ # Custom exceptions
│ ├── filters/ # Exception filters
│ ├── guards/ # Auth guards
│ ├── interceptors/ # Logging, transform
│ ├── interfaces/ # Type definitions
│ ├── middlewares/ # Request middlewares
│ ├── pipes/ # Validation pipes
│ ├── repositories/ # Base repository
│ ├── swagger/ # Swagger utilities
│ └── utils/ # Helper functions
├── config/ # Configuration module
├── databases/ # Database connections
│ ├── mongo/ # MongoDB setup
│ └── redis/ # Redis setup
├── logger/ # Winston logging
├── queue/ # BullMQ jobs
├── shared/ # Shared services
│ ├── mail/ # Email service
│ └── throttler/ # Rate limiting
└── modules/ # Feature modules
├── auth/ # Authentication
├── restaurant/ # Restaurants
├── order/ # Orders
├── payment/ # Payments
└── sse/ # Server-Sent Events
| Command | Description |
|---|---|
pnpm start |
Start the application |
pnpm start:dev |
Start in watch mode |
pnpm start:debug |
Start with debugger |
pnpm start:prod |
Start production build |
pnpm build |
Build the application |
pnpm lint |
Run ESLint |
pnpm test |
Run unit tests |
pnpm test:e2e |
Run E2E tests |
pnpm test:cov |
Run tests with coverage |
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment mode | development |
PORT |
Server port | 3000 |
MONGO_URI |
MongoDB connection string | — |
REDIS_HOST |
Redis host | localhost |
REDIS_PORT |
Redis port | 6379 |
JWT_ACCESS_SECRET |
Access token secret | — |
JWT_ACCESS_TTL |
Access token TTL | 15m |
JWT_REFRESH_SECRET |
Refresh token secret | — |
JWT_REFRESH_TTL |
Refresh token TTL | 7d |
THROTTLE_TTL |
Rate limit window (sec) | 60 |
THROTTLE_LIMIT |
Max requests per window | 10 |
See .env.example for the complete list.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style and conventions
- Write meaningful commit messages
- Add tests for new features
- Update documentation as needed
This project is licensed under the MIT License — see the LICENSE file for details.
Built with NestJS


