Skip to content

Shubh-Raj/CRM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

Mini CRM Backend

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.


🚀 Features

🔐 Authentication & Security

  • JWT Authentication: Secure stateless authentication using JSON Web Tokens.
  • Role-Based Access Control (RBAC): Distinct permissions for ADMIN and EMPLOYEE roles.
  • Password Hashing: Industry-standard bcrypt hashing for user passwords.
  • Guards: JwtAuthGuard and RolesGuard to protect endpoints.

👤 User Management (Admin)

  • Admin-only routes to view system users.
  • Capability to upgrade/downgrade user roles.

🏢 Customer Management

  • CRUD Operations: Complete Create, Read, Update, Delete functionality.
  • Pagination: Optimized list retrieval with page and limit parameters.
  • Search: Fuzzy search capability across name, email, and company fields.
  • Duplicate Prevention: Validation to prevent duplicate emails/phones.

📋 Task Management

  • 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.

🛠️ Technical Highlights

  • 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.

🛠️ Tech Stack

  • Framework: NestJS (Node.js/TypeScript)
  • Database: PostgreSQL
  • ORM: Prisma
  • Documentation: Swagger / OpenAPI
  • Containerization: Docker & Docker Compose

📋 Prerequisites

  • Node.js (v18+)
  • PostgreSQL (v12+)
  • Git

🔧 Installation & Setup

  1. Clone the repository

    git clone https://github.com/Shubh-Raj/CRM.git
    cd CRM
    cd mini-crm-backend
  2. Install dependencies

    npm install
  3. Configure Environment Create a .env file in the root directory:

    DATABASE_URL="postgresql://postgres:YOUR_PASSWORD@localhost:5432/mini_crm?schema=public"
    JWT_SECRET="your-secure-secret-key"
  4. Setup Database

    # Create database (if not exists)
    # Run migrations
    npx prisma migrate dev
  5. Start the Server

    npm run start:dev

    The server will start at http://localhost:3000.


🧪 Testing the Application

Option 1: Automated Test Script (Recommended)

We have included a PowerShell script that automatically tests the entire flow (Register -> Login -> Create Customer -> List Customers).

Run in terminal:

.\test_api.ps1

Option 2: Interactive Swagger UI

Visit http://localhost:3000/api to see the interactive documentation.

  1. Register: POST /auth/register (Role: ADMIN)
  2. Login: POST /auth/login -> Copy accessToken
  3. Authorize: Click green "Authorize" button -> Paste Token
  4. Test Endpoints: Try GET /customers or POST /tasks

🐳 Docker Deployment

To run the entire stack (App + Postgres) using Docker:

docker-compose up --build

📂 Project Structure

src/
├── 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

👤 Author

Shubh Raj

About

A mini CRM backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published