| config | ||
| controllers | ||
| docs | ||
| middleware | ||
| models | ||
| routes | ||
| scripts | ||
| services | ||
| src | ||
| utils | ||
| .gitignore | ||
| AI-ASSISTANT-INSTRUCTIONS.md | ||
| back.md | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| server.js | ||
Royal Enfield Dealership Onboarding System - Backend
🚀 Quick Start
1. Install Dependencies
npm install
2. Setup Database
Create PostgreSQL database:
createdb royal_enfield_onboarding
3. Configure Environment
cp .env.example .env
# Edit .env with your database credentials and other settings
4. Run Migrations
npm run migrate
5. Start Server
# Development
npm run dev
# Production
npm start
📁 Complete File Structure
This backend requires the following files to be fully functional. Files marked with ✅ are already created. Files marked with ⚠️ need to be created by your AI assistant:
Root Files
- ✅
package.json - ✅
.env.example - ✅
server.js - ✅
README.md - ✅
back.md(Comprehensive documentation) - ⚠️
.gitignore
Config Files (/config)
- ✅
database.js - ✅
email.js - ✅
constants.js
Models (/models)
- ✅
index.js - ✅
User.js - ✅
Outlet.js - ⚠️
Application.js- Dealer application model - ⚠️
Resignation.js- Resignation request model - ⚠️
ConstitutionalChange.js- Constitutional change model - ⚠️
RelocationRequest.js- Relocation request model - ⚠️
Worknote.js- Discussion worknotes model - ⚠️
Document.js- Document uploads model - ⚠️
AuditLog.js- Audit trail model - ⚠️
FinancePayment.js- Finance payment tracking - ⚠️
FnF.js- Full & Final settlement - ⚠️
Region.js- Regional hierarchy - ⚠️
Zone.js- Zone model
Controllers (/controllers)
- ⚠️
authController.js- Login, logout, token refresh - ⚠️
userController.js- User management - ⚠️
applicationController.js- Dealer applications - ⚠️
resignationController.js- Resignation workflow - ⚠️
constitutionalController.js- Constitutional changes - ⚠️
relocationController.js- Relocation requests - ⚠️
outletController.js- Outlet management - ⚠️
worknoteController.js- Discussion platform - ⚠️
financeController.js- Finance operations - ⚠️
masterController.js- Master configuration - ⚠️
dashboardController.js- Dashboard statistics
Routes (/routes)
- ⚠️
auth.js- Authentication routes - ⚠️
users.js- User routes - ⚠️
applications.js- Application routes - ⚠️
resignations.js- Resignation routes - ⚠️
constitutional.js- Constitutional change routes - ⚠️
relocations.js- Relocation routes - ⚠️
outlets.js- Outlet routes - ⚠️
worknotes.js- Worknote routes - ⚠️
finance.js- Finance routes - ⚠️
master.js- Master configuration routes - ⚠️
dashboard.js- Dashboard routes
Middleware (/middleware)
- ⚠️
auth.js- JWT verification middleware - ⚠️
roleCheck.js- Role-based access control - ⚠️
upload.js- File upload middleware - ⚠️
validation.js- Input validation - ⚠️
errorHandler.js- Global error handler
Utilities (/utils)
- ⚠️
emailTemplates.js- Email HTML templates - ⚠️
emailService.js- Email sending utilities - ⚠️
logger.js- Winston logger - ⚠️
helpers.js- Helper functions
Migrations (/migrations)
- ⚠️
initial-setup.js- Initial database schema and seed data
📝 Instructions for AI Assistant
To complete this backend, your AI IDE should:
- Read the
back.mdfile for complete architecture understanding - Create all remaining model files based on the database schema in
back.md - Create all controller files with business logic as described in API endpoints
- Create all route files mapping HTTP requests to controllers
- Create middleware files for authentication, authorization, and validation
- Create utility files for email, logging, and helpers
- Create migration file to set up initial database schema and seed data
Each file should follow these patterns:
Model Pattern:
const { CONSTANTS } = require('../config/constants');
module.exports = (sequelize, DataTypes) => {
const ModelName = sequelize.define('ModelName', {
// Fields defined in back.md schema
});
ModelName.associate = (models) => {
// Relationships defined in back.md
};
return ModelName;
};
Controller Pattern:
const db = require('../models');
const logger = require('../utils/logger');
exports.functionName = async (req, res, next) => {
try {
// Business logic
res.json({ success: true, data: result });
} catch (error) {
logger.error('Error:', error);
next(error);
}
};
Route Pattern:
const express = require('express');
const router = express.Router();
const controller = require('../controllers/controllerName');
const auth = require('../middleware/auth');
const roleCheck = require('../middleware/roleCheck');
router.get('/', auth, roleCheck(['Role1', 'Role2']), controller.list);
router.post('/', auth, roleCheck(['Role1']), controller.create);
module.exports = router;
🔌 API Documentation
Full API documentation is available in back.md including:
- All endpoint URLs
- Request/Response formats
- Authentication requirements
- Role permissions
- Example payloads
🗄️ Database Schema
Complete database schema with all tables, columns, relationships, and indexes is documented in back.md.
🔐 Security
The backend implements:
- JWT authentication
- Role-based access control
- Password hashing with bcrypt
- Input validation
- SQL injection prevention
- Rate limiting
- CORS protection
- Security headers (Helmet)
📧 Email Notifications
Email templates and triggers are defined in utils/emailTemplates.js and utils/emailService.js.
📊 Logging
Winston logger is configured in utils/logger.js with multiple transports.
🧪 Testing
Run tests with:
npm test
npm run test:coverage
🚢 Deployment
See back.md for detailed deployment instructions for:
- Railway
- Render
- AWS/DigitalOcean
- Docker
📞 Support
Refer to back.md for:
- Troubleshooting common issues
- Database backup/restore
- Maintenance tasks
- Complete architecture documentation
Next Steps:
- Have your AI assistant read
back.md - Ask it to create all remaining files following the patterns above
- Test API endpoints
- Connect frontend to backend
- Deploy to production
Good luck! 🚀