A comprehensive Customer Relationship Management (CRM) system built with NestJS, Prisma, and PostgreSQL. This API provides robust features for managing users, customers, and tasks with role-based access control and JWT authentication.
- User Authentication: JWT-based authentication with bcrypt password hashing
- Role-Based Access Control: Admin and Employee roles with different permissions
- User Management: Create, read, and update user information
- Customer Management: Full CRUD operations for customer data with pagination
- Task Management: Assign and track tasks with status updates
- API Documentation: Interactive Swagger/OpenAPI documentation
- Database Migrations: Prisma ORM for type-safe database operations
Before running this application, ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- PostgreSQL (v12 or higher)
git clone <your-repository-url>
cd Mini-CRMnpm installCreate a .env file in the root directory by copying the example file:
cp .env.example .envEdit the .env file with your configuration:
DATABASE_URL="postgresql://username:password@localhost:5432/crm_db?schema=public"
PORT=3000
JWT_SECRET=your_jwt_secret_key_change_in_productionEnvironment Variables:
| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://postgres:password@localhost:5432/crm_db?schema=public |
PORT |
Server port | 3000 |
JWT_SECRET |
Secret key for JWT token generation | your_secure_secret_key |
Run Prisma migrations to set up your database schema:
# Generate Prisma Client
npx prisma generate
# Run database migrations
npx prisma migrate dev --name init
# (Optional) Open Prisma Studio to view your database
npx prisma studioNote: The migration will create the following tables:
users- User accounts with authenticationcustomers- Customer informationtasks- Task assignments and tracking
npm run start:dev# Build the application
npm run build
# Start the production server
npm run start:prodnpm run startThe server will start on http://localhost:3000 (or your configured PORT).
Once the server is running, access the interactive API documentation at:
http://localhost:3000/api-docs
The Swagger UI provides:
- Complete API endpoint documentation
- Request/response schemas
- Interactive API testing
- JWT authentication integration
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auths/register |
Register a new user | No |
| POST | /auths/login |
Login and receive JWT token | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /users |
Get all users | Yes (Admin) |
| GET | /users/:id |
Get user by ID | Yes (Admin) |
| PATCH | /users/:id |
Update user role | Yes (Admin) |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /customers?page=1&limit=10 |
Get customers (paginated) | Yes |
| POST | /customers/create |
Create a new customer | Yes (Admin) |
| GET | /customers/:id |
Get customer by ID | Yes |
| PATCH | /customers/:id |
Update customer | Yes (Admin) |
| DELETE | /customers/delete/:id |
Delete customer | Yes (Admin) |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /tasks |
Create a new task | Yes (Admin) |
| GET | /tasks |
Get tasks (Admin: all, Employee: own) | Yes |
| PATCH | /tasks/:id/status |
Update task status | Yes |
user_id(Primary Key)nameemail(Unique)password(Hashed with bcrypt)role(ADMIN | EMPLOYEE)createdAt,updatedAt
customer_id(Primary Key)nameemail(Unique)phone(Unique)companycreatedAt,updatedAt
id(Primary Key)titledescriptionstatus(PENDING | IN_PROGRESS | DONE)assignedToId(Foreign Key to User)customerId(Foreign Key to Customer)createdAt,updatedAt
- All User operations (view, update roles)
- Create, update, and delete customers
- Create tasks
- View all tasks
- Update any task status
- View customers
- View own tasks
- Update own task status
src/
βββ auth/ # Authentication module (JWT, guards, strategies)
βββ users/ # User management module
βββ customers/ # Customer management module
βββ tasks/ # Task management module
βββ prisma/ # Prisma service
βββ app.module.ts # Root module
βββ main.ts # Application entry point
# Format code
npm run format
# Lint code
npm run lint- Framework: NestJS v11
- ORM: Prisma v7
- Database: PostgreSQL
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
- Validation: class-validator, class-transformer
- API Documentation: Swagger/OpenAPI
- Language: TypeScript
This project is UNLICENSED and is for educational/demonstration purposes.
For questions or issues, please open an issue on the GitHub repository.
Happy Coding! π