| .cursor | ||
| database | ||
| scripts | ||
| src | ||
| tests | ||
| .dockerignore | ||
| .eslintrc.json | ||
| .gitignore | ||
| .prettierrc | ||
| babel.config.js | ||
| backend_structure.txt | ||
| docker-compose.yml | ||
| Dockerfile | ||
| env.example | ||
| ERD_Mermaid.txt | ||
| jest.config.js | ||
| nodemon.json | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| setup.bat | ||
| tsconfig.json | ||
Royal Enfield Workflow Management System - Backend
A comprehensive backend API for the Royal Enfield Workflow Management System built with Node.js, TypeScript, Express.js, and PostgreSQL.
Features
- Frontend SSO Integration: Handles user authentication via frontend SSO
- JWT Authentication: Secure token-based authentication with refresh tokens
- User Management: Create and update users based on SSO data
- Workflow Management: Complete workflow request lifecycle
- Approval System: Multi-level approval workflow
- Document Management: File upload and management
- Notification System: Real-time notifications
- TAT Tracking: Turnaround time monitoring
- Audit Logging: Comprehensive activity tracking
- RESTful API: Well-structured API endpoints
Technology Stack
- Runtime: Node.js 22 LTS
- Language: TypeScript 5.7
- Framework: Express.js 4.21
- Database: PostgreSQL 16
- ORM: Sequelize 6.37
- Authentication: JWT + Frontend SSO
- Validation: Zod
- Logging: Winston
- Testing: Jest + Supertest
- Process Manager: PM2
Quick Start
Prerequisites
- Node.js 22.x LTS
- PostgreSQL 16.x
- npm 10.x or higher
Installation
-
Clone the repository
git clone <repository-url> cd re-workflow-backend -
Install dependencies
npm install -
Setup environment
cp env.example .env # Edit .env with your configuration -
Setup database
# Create database createdb re_workflow_db # Run schema psql -U postgres -d re_workflow_db -f database/schema/schema.sql -
Start development server
npm run dev
The API will be available at http://localhost:5000
Docker Setup
# Copy environment file
cp env.example .env
# Start services
docker-compose up --build -d
# Check logs
docker-compose logs -f
API Endpoints
Authentication
POST /api/v1/auth/sso-callback- SSO callback from frontendGET /api/v1/auth/me- Get current user profilePOST /api/v1/auth/refresh- Refresh access tokenPOST /api/v1/auth/logout- Logout userGET /api/v1/auth/validate- Validate token
Health Check
GET /health- API health statusGET /api/v1/health- Detailed health check
Environment Variables
See env.example for all required environment variables.
Development
# Run in development mode
npm run dev
# Run tests
npm test
# Run linting
npm run lint
# Run type checking
npm run type-check
# Build for production
npm run build
Project Structure
src/
├── app.ts # Express app configuration
├── server.ts # Server entry point
├── config/ # Configuration files
├── controllers/ # Request handlers
├── services/ # Business logic
├── models/ # Sequelize models
├── routes/ # API routes
├── middlewares/ # Express middlewares
├── validators/ # Request validation schemas
├── utils/ # Utility functions
└── types/ # TypeScript type definitions
Database Schema
The database schema includes all tables from the ERD:
users- User informationworkflow_requests- Main workflow requestsapproval_levels- Approval hierarchyparticipants- Workflow participantsdocuments- Document metadatawork_notes- Communication within workflowactivities- Activity lognotifications- User notificationstat_tracking- TAT monitoring- And more...
Authentication Flow
- Frontend handles SSO authentication
- Frontend sends user data to
/api/v1/auth/sso-callback - Backend creates/updates user record
- Backend generates JWT tokens
- Frontend uses tokens for subsequent API calls
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
License
This project is proprietary to Royal Enfield.
Support
For support and questions, please contact the development team.