Go to file
2026-04-29 16:37:45 +05:30
build stage transition issue resolved 2026-04-28 13:12:20 +05:30
docs stage transition issue resolved 2026-04-28 13:12:20 +05:30
scratch DD Lead treated as natiolwide user and in app notification enhanced 2026-04-20 01:51:09 +05:30
scripts stage transition issue resolved 2026-04-28 13:12:20 +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 added joint approval in resignation for RBM DD-ZM approval stage 2026-04-29 16:37:45 +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
.env.example hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +05:30
.gitignore nomenclature changed for the requests and the changes asked in the demo Active / Inactive Opportunity will be labeled as Opportunity with value as Yes or No auto assign to DD_AM , auto assignment configuration and kt matrix configuration added 2026-04-24 19:29:51 +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
all_ids.txt participants mappig done for other modules 2026-04-10 09:20:04 +05:30
all_perms.json hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +05:30
audit_db.mjs hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +05:30
audit_db.ts hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +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
check_app.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_audit.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_bug_app.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
check_db_roles.ts hirarchchy changed 2026-03-23 20:12:10 +05:30
check_db_users.ts hirarchchy changed 2026-03-23 20:12:10 +05:30
check_db.js nomenclature changed for the requests and the changes asked in the demo Active / Inactive Opportunity will be labeled as Opportunity with value as Yes or No auto assign to DD_AM , auto assignment configuration and kt matrix configuration added 2026-04-24 19:29:51 +05:30
check_db.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
check_final.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
check_history.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_json_size.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_loa.js auditlogs enhanced end to end flow checked for the onboarding , cursor used for major file chnages 2026-04-14 20:12:30 +05:30
check_logs.ts module wise audit tables added 2026-04-13 20:41:27 +05:30
check_loi.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
check_new_app.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
check_participants.ts end to end flow testing for all modules paralley enhancing profile schema to gather all info 2026-04-10 20:54:59 +05:30
check_policies.ts dealer onboarding dashboard flow changes made 2026-04-08 19:01:25 +05:30
check_progress.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_questions.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_size.ts multi iteration on approval flow 2026-04-01 18:04:19 +05:30
check_stuck.js auditlogs enhanced end to end flow checked for the onboarding , cursor used for major file chnages 2026-04-14 20:12:30 +05:30
check_zms_v2.ts hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +05:30
db_audit.json hirrachy enhanced nd creatded distric as centric and added dealer location stable ui made for the hirarchy 2026-03-30 02:59:34 +05:30
debug_app.ts multi iteration on approval flow 2026-04-01 18:04:19 +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
debug-state.cjs module wise audit tables added 2026-04-13 20:41:27 +05:30
docker-compose.yml new mail templates added dealer table enhanced add bank details added 2026-04-13 09:26:44 +05:30
drop_constraint.ts participants mappig done for other modules 2026-04-10 09:20:04 +05:30
heal_one.js auditlogs enhanced end to end flow checked for the onboarding , cursor used for major file chnages 2026-04-14 20:12:30 +05:30
heal_two.js auditlogs enhanced end to end flow checked for the onboarding , cursor used for major file chnages 2026-04-14 20:12:30 +05:30
package-lock.json major code refactotoring is done all modules coverd also added the email 20+ email tamplates with rich text editor edit code is almost stable 2026-04-19 23:21:12 +05:30
package.json after the 3rd demo fe points covered like templates improvd ui enahanced to match original theme check revokemiddlware added stagwe transistion even after one rejection flow added 2026-04-27 19:10:04 +05:30
quick_query.ts participants mappig done for other modules 2026-04-10 09:20:04 +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
repair_all_progress.ts dealer onboarding dashboard flow changes made 2026-04-08 19:01:25 +05:30
repair_fdd_policy.ts dealer onboarding dashboard flow changes made 2026-04-08 19:01:25 +05:30
repair_fdd_stage.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
repair_loi.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
reset_apps.ts delaer onboarding end to end fleo checked and also made some new changes in the progress trck now after the LOI approvl finance and securaty details kept separate for approval also LOI issue is differnt approval 2026-04-06 19:11:46 +05:30
reset_db.ts major code refactotoring is done all modules coverd also added the email 20+ email tamplates with rich text editor edit code is almost stable 2026-04-19 23:21:12 +05:30
restore-full-questionnaire.ts district mpping isue resolved after table changes 2026-03-30 20:09:40 +05:30
simulate-clearances.js new mail templates added dealer table enhanced add bank details added 2026-04-13 09:26:44 +05:30
sla-governance-postman-collection.json sla feature addd and templates also included in the sed file user deacticated changed to in active 2026-04-21 19:07:59 +05:30
sync_audit.ts module wise audit tables added 2026-04-13 20:41:27 +05:30
sync_participants.ts end to end flow testing for all modules paralley enhancing profile schema to gather all info 2026-04-10 20:54:59 +05:30
trigger-constitutional.js after the 3rd demo fe points covered like templates improvd ui enahanced to match original theme check revokemiddlware added stagwe transistion even after one rejection flow added 2026-04-27 19:10:04 +05:30
trigger-relocation.js after the 3rd demo fe points covered like templates improvd ui enahanced to match original theme check revokemiddlware added stagwe transistion even after one rejection flow added 2026-04-27 19:10:04 +05:30
trigger-resignation.js added joint approval in resignation for RBM DD-ZM approval stage 2026-04-29 16:37:45 +05:30
trigger-termination.js sla feature addd and templates also included in the sed file user deacticated changed to in active 2026-04-21 19:07:59 +05:30
trigger-workflow.js stage transition issue resolved 2026-04-28 13:12:20 +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
verify_approval_sync.ts hirarchchy changed 2026-03-23 20:12:10 +05:30
verify_db_logic.ts hirarchchy changed 2026-03-23 20:12:10 +05:30
verify_output.txt participants mappig done for other modules 2026-04-10 09:20:04 +05:30
verify_participants_logic.ts participants mappig done for other modules 2026-04-10 09:20:04 +05:30
verify_relocation_auth.ts relocatin 2026-04-03 02:32:54 +05:30
verify_relocation_workflow.ts relocatin 2026-04-03 02:32:54 +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! 🚀