// CRM Backend Starter for Clothing & Electronics Shops
// Using [Link] + Express + MongoDB + JWT (enterprise-structured, clean)
1️⃣ 1 Project Structure:
1//
// - /src
// - /config (db, jwt)
// - /controllers (business logic)
// - /models (Mongoose schemas)
// - /routes (API endpoints)
// - /middlewares (auth, error handler)
// - /utils (helpers)
// - [Link] (entry point)
2️⃣ Dependencies:
//
// npm install express mongoose dotenv bcryptjs jsonwebtoken cors morgan express-
validator
3️⃣ [Link]
//
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const morgan = require('morgan');
require('dotenv').config();
const app = express();
[Link]([Link]());
[Link](cors());
[Link](morgan('dev'));
// Import routes
const authRoutes = require('./routes/authRoutes');
const customerRoutes = require('./routes/customerRoutes');
const productRoutes = require('./routes/productRoutes');
const purchaseRoutes = require('./routes/purchaseRoutes');
const leadRoutes = require('./routes/leadRoutes');
const reportRoutes = require('./routes/reportRoutes');
// Use routes
[Link]('/api/auth', authRoutes);
[Link]('/api/customers', customerRoutes);
[Link]('/api/products', productRoutes);
[Link]('/api/purchases', purchaseRoutes);
[Link]('/api/leads', leadRoutes);
[Link]('/api/reports', reportRoutes);
// DB Connection
[Link]([Link].MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => [Link]('MongoDB connected'))
.catch(err => [Link](err));
const PORT = [Link] || 5000;
[Link](PORT, () => [Link](`Server running on port ${PORT}`));
4️⃣ Example Model (models/[Link])
//
const mongoose = require('mongoose');
const customerSchema = new [Link]({
name: { type: String, required: true },
phone: { type: String, required: true, unique: true },
email: { type: String },
address: { type: String },
birthday: { type: Date },
customerType: { type: String, enum: ['Walk-in', 'Regular', 'VIP'], default:
'Walk-in' },
notes: { type: String }
}, { timestamps: true });
[Link] = [Link]('Customer', customerSchema);
5️⃣ Example Controller (controllers/[Link])
//
const Customer = require('../models/Customer');
[Link] = async (req, res) => {
try {
const customer = new Customer([Link]);
await [Link]();
[Link](201).json(customer);
} catch (err) {
[Link](400).json({ error: [Link] });
}
};
[Link] = async (req, res) => {
try {
const customers = await [Link]().sort({ createdAt: -1 });
[Link](customers);
} catch (err) {
[Link](500).json({ error: [Link] });
}
};
6️⃣ Example Route (routes/[Link])
//
const express = require('express');
const router = [Link]();
const customerController = require('../controllers/customerController');
const { protect } = require('../middlewares/authMiddleware');
[Link]('/', protect, [Link]);
[Link]('/', protect, [Link]);
[Link] = router;
7️⃣ Authentication (middlewares/[Link])
//
const jwt = require('jsonwebtoken');
const User = require('../models/User');
[Link] = async (req, res, next) => {
let token;
if ([Link] &&
[Link]('Bearer')) {
try {
token = [Link](' ')[1];
const decoded = [Link](token, [Link].JWT_SECRET);
[Link] = await [Link]([Link]).select('-password');
next();
} catch (err) {
[Link](401).json({ error: 'Not authorized' });
}
} else {
[Link](401).json({ error: 'No token provided' });
}
};
// Repeat similar structure for Product, Purchase, Lead, Reports with CRUD
operations.
// Integrate sales tracking, lead stages, purchase logging, and reporting APIs
aligned with your UI flows.
// This backend structure will align cleanly with your attractive React frontend,
ensuring enterprise readiness, scalability, and clear API separation for CRM
deployment and sales.