Go to file
2026-01-30 19:47:38 +05:30
docs email emplate added fo opportunity and non opportunity and new enums added for the application status 2026-01-29 20:25:59 +05:30
scripts from backend areaa manger table alterd made it redy to recive the dealer application form and alo now api serving aplications list and application detail 2026-01-28 21:38:32 +05:30
seeders seeded data for the state districts andseeded default zones create login api with username password later oka will be added 2026-01-27 19:08:24 +05:30
src questinnaire modified similar to the google form ample given with mcq and weightage . opportunity and non -opportunity mapped 2026-01-30 19:47:38 +05:30
utils tables added based on the frontend ui and backend is up need to test thouroughly 2026-01-20 19:42:37 +05:30
.gitignore tables added based on the frontend ui and backend is up need to test thouroughly 2026-01-20 19:42:37 +05:30
AI-ASSISTANT-INSTRUCTIONS.md tables added based on the frontend ui and backend is up need to test thouroughly 2026-01-20 19:42:37 +05:30
back.md tables added based on the frontend ui and backend is up need to test thouroughly 2026-01-20 19:42:37 +05:30
debug_opp_bijapur.js email emplate added fo opportunity and non opportunity and new enums added for the application status 2026-01-29 20:25:59 +05:30
package-lock.json changed to typescript and added missed tables 2026-01-21 19:05:16 +05:30
package.json seeded data for the state districts andseeded default zones create login api with username password later oka will be added 2026-01-27 19:08:24 +05:30
README.md tables added based on the frontend ui and backend is up need to test thouroughly 2026-01-20 19:42:37 +05:30
tsconfig.json seeded data for the state districts andseeded default zones create login api with username password later oka will be added 2026-01-27 19:08:24 +05:30
update_enums_raw.js email emplate added fo opportunity and non opportunity and new enums added for the application status 2026-01-29 20:25:59 +05:30
verification_result.txt questinnaire modified similar to the google form ample given with mcq and weightage . opportunity and non -opportunity mapped 2026-01-30 19:47:38 +05:30

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:

  1. Read the back.md file for complete architecture understanding
  2. Create all remaining model files based on the database schema in back.md
  3. Create all controller files with business logic as described in API endpoints
  4. Create all route files mapping HTTP requests to controllers
  5. Create middleware files for authentication, authorization, and validation
  6. Create utility files for email, logging, and helpers
  7. 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:

  1. Have your AI assistant read back.md
  2. Ask it to create all remaining files following the patterns above
  3. Test API endpoints
  4. Connect frontend to backend
  5. Deploy to production

Good luck! 🚀