A production-ready REST API backend for a mini Customer Relationship Management (CRM) system built with NestJS, PostgreSQL, and Prisma. This project demonstrates scalable architecture, role-based access control, and efficient database management.
- JWT Authentication: Secure stateless authentication using JSON Web Tokens.
- Role-Based Access Control (RBAC): Distinct permissions for
ADMINandEMPLOYEEroles. - Password Hashing: Industry-standard
bcrypthashing for user passwords. - Guards:
JwtAuthGuardandRolesGuardto protect endpoints.
- Admin-only routes to view system users.
- Capability to upgrade/downgrade user roles.
- CRUD Operations: Complete Create, Read, Update, Delete functionality.
- Pagination: Optimized list retrieval with
pageandlimitparameters. - Search: Fuzzy search capability across name, email, and company fields.
- Duplicate Prevention: Validation to prevent duplicate emails/phones.
- Workflow: Task lifecycle management (
PENDING->IN_PROGRESS->DONE). - Assignment: Tasks assigned to specific Employees for specific Customers.
- Visibility Rules: Employees can only view and update their own assigned tasks.
- Swagger Documentation: Automated, interactive API documentation.
- Input Validation: Robust DTO validation using
class-validator. - Global Error Handling: Standardized error responses via strict Exception Filters.
- Logging: Request duration tracking via Interceptors.
- Docker Support: Containerized setup for easy deployment.
- Framework: NestJS (Node.js/TypeScript)
- Database: PostgreSQL
- ORM: Prisma
- Documentation: Swagger / OpenAPI
- Containerization: Docker & Docker Compose
- Node.js (v18+)
- PostgreSQL (v12+)
- Git
-
Clone the repository
git clone https://github.com/Shubh-Raj/CRM.git cd CRM cd mini-crm-backend
-
Install dependencies
npm install
-
Configure Environment Create a
.envfile in the root directory:DATABASE_URL="postgresql://postgres:YOUR_PASSWORD@localhost:5432/mini_crm?schema=public" JWT_SECRET="your-secure-secret-key"
-
Setup Database
# Create database (if not exists) # Run migrations npx prisma migrate dev
-
Start the Server
npm run start:dev
The server will start at
http://localhost:3000.
We have included a PowerShell script that automatically tests the entire flow (Register -> Login -> Create Customer -> List Customers).
Run in terminal:
.\test_api.ps1Visit http://localhost:3000/api to see the interactive documentation.
- Register: POST
/auth/register(Role: ADMIN) - Login: POST
/auth/login-> CopyaccessToken - Authorize: Click green "Authorize" button -> Paste Token
- Test Endpoints: Try
GET /customersorPOST /tasks
To run the entire stack (App + Postgres) using Docker:
docker-compose up --buildsrc/
├── auth/ # Authentication logic (Guards, Strategies)
├── common/ # Shared resources (Filters, Interceptors, Constants)
├── customers/ # Customer management domain
├── tasks/ # Task management domain
├── users/ # User management domain
├── prisma/ # Database connection service
└── main.ts # Entry point
Shubh Raj