Skip to content

v-988/NexusCRM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Built with Node.js Β· Express Β· MongoDB Β· JWT

NexusCRM β€” Backend API Server

Production-ready RESTful CRM backend built with Node.js, Express & MongoDB

Node.js Express MongoDB JWT bcrypt License


Overview

NexusCRM is a secure, scalable Customer Relationship Management backend that allows sales teams to manage contacts, track deals through a pipeline, and administer users β€” all through a clean JSON REST API with JWT-based authentication.


Tech Stack

Layer Technology Purpose
Runtime Node.js 18+ JavaScript server environment
Framework Express.js 4.x HTTP routing & middleware pipeline
Database MongoDB Atlas Cloud-hosted document storage
ODM Mongoose 7.x Schema modeling & query builder
Auth JSON Web Tokens Stateless session management
Security bcryptjs Password hashing with salt rounds
Config dotenv Environment variable management
Dev Tool nodemon Hot-reload during development

πŸ—οΈ System Architecture

SystemArchitecture

Request flow: Client β†’ CORS/JWT Middleware β†’ Route Controller β†’ Service Logic β†’ MongoDB β†’ JSON Response


πŸ“ Project Structure

nexuscrm-server/
β”œβ”€β”€ Server.js                  ← Entry point (Express init + DB connect)
β”œβ”€β”€ .env                       ← Secrets (never commit this)
β”œβ”€β”€ package.json
β”‚
β”œβ”€β”€ config/
β”‚   └── db.js                  ← Mongoose connection setup
β”‚
β”œβ”€β”€ middleware/
β”‚   └── authMiddleware.js      ← JWT verification for protected routes
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ User.js                ← User schema (name, email, passwordHash, role)
β”‚   β”œβ”€β”€ Contact.js             ← Contact schema (name, email, phone, company)
β”‚   └── Deal.js                ← Deal schema (title, value, stage, contactRef)
β”‚
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ authRoutes.js          ← POST /register  POST /login
β”‚   β”œβ”€β”€ userRoutes.js          ← GET PUT DELETE /users/:id
β”‚   β”œβ”€β”€ contactRoutes.js       ← Full CRUD /contacts
β”‚   └── dealRoutes.js          ← Full CRUD /deals
β”‚
└── controllers/
    β”œβ”€β”€ authController.js
    β”œβ”€β”€ userController.js
    β”œβ”€β”€ contactController.js
    └── dealController.js

βš™οΈ Getting Started

Prerequisites

  • Node.js v18+
  • npm v9+
  • MongoDB Atlas account (or local MongoDB)

Installation

# 1. Clone the repo
git clone https://github.com/your-username/nexuscrm-server.git
cd nexuscrm-server

# 2. Install dependencies
npm install

# 3. Setup environment
cp .env.example .env
# β†’ Edit .env with your credentials

# 4. Run in development mode
npm run dev

Expected terminal output:

[nodemon] 3.0.0
[nodemon] starting `Server.js`
βœ”  MongoDB Atlas connected successfully
βœ”  Server is running on http://localhost:5000

πŸ” Environment Variables

Create a .env file in the root:

PORT=5000
NODE_ENV=development
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/nexuscrm
JWT_SECRET=your_super_secret_key_minimum_32_characters
JWT_EXPIRES_IN=7d

⚠️ Never commit .env to version control. It is listed in .gitignore.


πŸ“‘ API Reference

All routes are prefixed with /api. Protected routes require:

Authorization: Bearer <your_jwt_token>

πŸ”‘ Auth Endpoints

Method Endpoint Access Description
POST /api/auth/register 🟒 Public Register new user
POST /api/auth/login 🟒 Public Login & get JWT token

πŸ‘€ User Endpoints

Method Endpoint Access Description
GET /api/users πŸ”’ Protected Get all users
GET /api/users/:id πŸ”’ Protected Get user by ID
PUT /api/users/:id πŸ”’ Protected Update user profile
DELETE /api/users/:id πŸ”’ Protected Delete user

πŸ“‹ Contact Endpoints

Method Endpoint Access Description
GET /api/contacts πŸ”’ Protected List all contacts
POST /api/contacts πŸ”’ Protected Create a contact
GET /api/contacts/:id πŸ”’ Protected Get contact by ID
PUT /api/contacts/:id πŸ”’ Protected Update contact
DELETE /api/contacts/:id πŸ”’ Protected Delete contact

πŸ’Ό Deal Endpoints

Method Endpoint Access Description
GET /api/deals πŸ”’ Protected List all deals
POST /api/deals πŸ”’ Protected Create a deal
GET /api/deals/:id πŸ”’ Protected Get deal by ID
PUT /api/deals/:id πŸ”’ Protected Update / move stage
DELETE /api/deals/:id πŸ”’ Protected Delete a deal

Deal pipeline: lead β†’ proposal β†’ negotiation β†’ closed-won / closed-lost


πŸ“Š Sample API Output

POST /api/auth/login β€” 200 OK

{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0ZjFjM2E3ZTJiO...",
  "user": {
    "_id": "64f1c3a7e2b8d90012af3e11",
    "name": "Jane Doe",
    "email": "jane@example.com",
    "role": "admin",
    "createdAt": "2024-08-01T10:30:00.000Z"
  }
}

GET /api/contacts β€” 200 OK

[
  {
    "_id": "64f2a8b1c3e1f70034cd9e21",
    "name": "Acme Corporation",
    "email": "contact@acme.com",
    "phone": "+1-800-555-0100",
    "company": "Acme Corp",
    "deal": {
      "stage": "proposal",
      "value": 24000
    },
    "createdAt": "2024-08-05T08:20:00.000Z"
  }
]

POST /api/contacts β€” 401 Unauthorized (no token)

{
  "success": false,
  "message": "Not authorized, token missing or invalid"
}

POST /api/auth/register β€” 400 Bad Request (duplicate email)

{
  "success": false,
  "message": "User already exists with this email"
}

πŸ”’ Security Implementation

Threat Protection
Plain-text passwords bcryptjs with 10 salt rounds β€” never stored raw
Unauthorized access JWT middleware blocks all protected routes
Cross-origin attacks CORS configured with allowed origins
Invalid data Mongoose schema validation before any DB write
Secret exposure All keys in .env, never hardcoded in source

πŸ”„ Authentication Flow

1. REGISTER  β†’  Password hashed (bcrypt)  β†’  User saved in MongoDB
2. LOGIN     β†’  Hash compared (bcrypt)    β†’  JWT token signed & returned
3. REQUEST   β†’  Bearer token in header    β†’  JWT middleware verifies
4. EXPIRED   β†’  401 Unauthorized          β†’  Client re-authenticates

πŸ“¦ Dependencies

{
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "jsonwebtoken": "^9.0.0",
    "mongoose": "^7.0.0"
  },
  "devDependencies": {
    "nodemon": "^3.0.0"
  }
}

πŸ“œ Scripts

npm start       # Production β€” node Server.js
npm run dev     # Development β€” nodemon Server.js (hot reload)

πŸ“„ License

MIT Β© 2024 NexusCRM


Built with Node.js Β· Express Β· MongoDB Β· JWT Β· bcrypt

About

Secure and scalable CRM backend API built with Node.js, Express.js, MongoDB, and JWT authentication, designed for efficient customer relationship management with RESTful architecture, secure user authentication, database integration, and modular backend services.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages