Re_Backend/README.md
2025-10-29 19:31:40 +05:30

177 lines
4.1 KiB
Markdown

# 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
1. **Clone the repository**
```bash
git clone <repository-url>
cd re-workflow-backend
```
2. **Install dependencies**
```bash
npm install
```
3. **Setup environment**
```bash
cp env.example .env
# Edit .env with your configuration
```
4. **Setup database**
```bash
# Create database
createdb re_workflow_db
# Run schema
psql -U postgres -d re_workflow_db -f database/schema/schema.sql
```
5. **Start development server**
```bash
npm run dev
```
The API will be available at `http://localhost:5000`
### Docker Setup
```bash
# 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 frontend
- `GET /api/v1/auth/me` - Get current user profile
- `POST /api/v1/auth/refresh` - Refresh access token
- `POST /api/v1/auth/logout` - Logout user
- `GET /api/v1/auth/validate` - Validate token
### Health Check
- `GET /health` - API health status
- `GET /api/v1/health` - Detailed health check
## Environment Variables
See `env.example` for all required environment variables.
## Development
```bash
# 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 information
- `workflow_requests` - Main workflow requests
- `approval_levels` - Approval hierarchy
- `participants` - Workflow participants
- `documents` - Document metadata
- `work_notes` - Communication within workflow
- `activities` - Activity log
- `notifications` - User notifications
- `tat_tracking` - TAT monitoring
- And more...
## Authentication Flow
1. Frontend handles SSO authentication
2. Frontend sends user data to `/api/v1/auth/sso-callback`
3. Backend creates/updates user record
4. Backend generates JWT tokens
5. Frontend uses tokens for subsequent API calls
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests and linting
5. Submit a pull request
## License
This project is proprietary to Royal Enfield.
## Support
For support and questions, please contact the development team.