364 lines
8.2 KiB
Markdown
364 lines
8.2 KiB
Markdown
# Royal Enfield Workflow Management System - Configuration Guide
|
|
|
|
## 📋 Overview
|
|
|
|
All system configurations are centralized in `src/config/system.config.ts` and can be customized via environment variables.
|
|
|
|
## ⚙️ Configuration Structure
|
|
|
|
### 1. **Working Hours**
|
|
Controls when TAT tracking is active.
|
|
|
|
```env
|
|
WORK_START_HOUR=9 # 9 AM (default)
|
|
WORK_END_HOUR=18 # 6 PM (default)
|
|
TZ=Asia/Kolkata # Timezone
|
|
```
|
|
|
|
**Working Days:** Monday - Friday (hardcoded)
|
|
|
|
---
|
|
|
|
### 2. **TAT (Turnaround Time) Settings**
|
|
|
|
```env
|
|
TAT_TEST_MODE=false # Enable for testing (1 hour = 1 minute)
|
|
DEFAULT_EXPRESS_TAT=24 # Express priority default TAT (hours)
|
|
DEFAULT_STANDARD_TAT=72 # Standard priority default TAT (hours)
|
|
```
|
|
|
|
**TAT Thresholds** (hardcoded):
|
|
- 50% - Warning notification
|
|
- 75% - Critical notification
|
|
- 100% - Breach notification
|
|
|
|
---
|
|
|
|
### 3. **File Upload Limits**
|
|
|
|
```env
|
|
MAX_FILE_SIZE_MB=10 # Max file size per upload
|
|
MAX_FILES_PER_REQUEST=10 # Max files per request
|
|
ALLOWED_FILE_TYPES=pdf,doc,docx,xls,xlsx,ppt,pptx,jpg,jpeg,png,gif,txt
|
|
```
|
|
|
|
---
|
|
|
|
### 4. **Workflow Limits**
|
|
|
|
```env
|
|
MAX_APPROVAL_LEVELS=10 # Max approval stages
|
|
MAX_PARTICIPANTS_PER_REQUEST=50 # Max total participants
|
|
MAX_SPECTATORS=20 # Max spectators
|
|
```
|
|
|
|
---
|
|
|
|
### 5. **Work Notes Configuration**
|
|
|
|
```env
|
|
MAX_MESSAGE_LENGTH=2000 # Max characters per message
|
|
MAX_ATTACHMENTS_PER_NOTE=5 # Max files per work note
|
|
ENABLE_REACTIONS=true # Allow emoji reactions
|
|
ENABLE_MENTIONS=true # Allow @mentions
|
|
```
|
|
|
|
---
|
|
|
|
### 6. **Redis & Queue**
|
|
|
|
```env
|
|
REDIS_URL=redis://localhost:6379 # Redis connection string
|
|
QUEUE_CONCURRENCY=5 # Concurrent job processing
|
|
RATE_LIMIT_MAX=10 # Max requests per duration
|
|
RATE_LIMIT_DURATION=1000 # Rate limit window (ms)
|
|
```
|
|
|
|
---
|
|
|
|
### 7. **Security & Session**
|
|
|
|
```env
|
|
JWT_SECRET=your_secret_min_32_characters # JWT signing key
|
|
JWT_EXPIRY=8h # Token expiration
|
|
SESSION_TIMEOUT_MINUTES=480 # 8 hours
|
|
ENABLE_2FA=false # Two-factor authentication
|
|
```
|
|
|
|
---
|
|
|
|
### 8. **Notifications**
|
|
|
|
```env
|
|
ENABLE_EMAIL_NOTIFICATIONS=true # Email alerts
|
|
ENABLE_PUSH_NOTIFICATIONS=true # Browser push
|
|
NOTIFICATION_BATCH_DELAY=5000 # Batch delay (ms)
|
|
```
|
|
|
|
**Email SMTP** (if email enabled):
|
|
```env
|
|
SMTP_HOST=smtp.gmail.com
|
|
SMTP_PORT=587
|
|
SMTP_USER=your_email@royalenfield.com
|
|
SMTP_PASSWORD=your_password
|
|
SMTP_FROM=noreply@royalenfield.com
|
|
```
|
|
|
|
---
|
|
|
|
### 9. **Feature Flags**
|
|
|
|
```env
|
|
ENABLE_AI_CONCLUSION=true # AI-generated conclusion remarks
|
|
ENABLE_TEMPLATES=false # Template-based workflows (future)
|
|
ENABLE_ANALYTICS=true # Dashboard analytics
|
|
ENABLE_EXPORT=true # Export to CSV/PDF
|
|
```
|
|
|
|
---
|
|
|
|
### 10. **Database**
|
|
|
|
```env
|
|
DB_HOST=localhost
|
|
DB_PORT=5432
|
|
DB_NAME=re_workflow
|
|
DB_USER=postgres
|
|
DB_PASSWORD=your_password
|
|
DB_SSL=false
|
|
```
|
|
|
|
---
|
|
|
|
### 11. **Storage**
|
|
|
|
```env
|
|
STORAGE_TYPE=local # Options: local, s3, gcs
|
|
STORAGE_PATH=./uploads # Local storage path
|
|
```
|
|
|
|
**For S3 (if using cloud storage):**
|
|
```env
|
|
AWS_ACCESS_KEY_ID=your_access_key
|
|
AWS_SECRET_ACCESS_KEY=your_secret
|
|
AWS_REGION=ap-south-1
|
|
AWS_S3_BUCKET=re-workflow-documents
|
|
```
|
|
|
|
---
|
|
|
|
## 🚀 Quick Setup
|
|
|
|
### Development Environment
|
|
|
|
1. Copy example configuration:
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
2. Update critical values:
|
|
```env
|
|
DB_PASSWORD=your_local_postgres_password
|
|
JWT_SECRET=generate_random_32_char_string
|
|
REDIS_URL=redis://localhost:6379
|
|
```
|
|
|
|
3. Enable test mode for faster TAT testing:
|
|
```env
|
|
TAT_TEST_MODE=true # 1 hour = 1 minute
|
|
```
|
|
|
|
---
|
|
|
|
### Production Environment
|
|
|
|
1. Set environment to production:
|
|
```env
|
|
NODE_ENV=production
|
|
```
|
|
|
|
2. Configure secure secrets:
|
|
```env
|
|
JWT_SECRET=use_very_strong_secret_here
|
|
DB_PASSWORD=strong_database_password
|
|
```
|
|
|
|
3. Disable test mode:
|
|
```env
|
|
TAT_TEST_MODE=false
|
|
```
|
|
|
|
4. Enable SSL:
|
|
```env
|
|
DB_SSL=true
|
|
```
|
|
|
|
5. Configure email/push notifications with real credentials
|
|
|
|
---
|
|
|
|
## 📊 Configuration API
|
|
|
|
### GET `/api/v1/config`
|
|
Returns public (non-sensitive) configuration for frontend.
|
|
|
|
**Response:**
|
|
```json
|
|
{
|
|
"success": true,
|
|
"data": {
|
|
"appName": "Royal Enfield Workflow Management",
|
|
"appVersion": "1.2.0",
|
|
"workingHours": {
|
|
"START_HOUR": 9,
|
|
"END_HOUR": 18,
|
|
"START_DAY": 1,
|
|
"END_DAY": 5,
|
|
"TIMEZONE": "Asia/Kolkata"
|
|
},
|
|
"tat": {
|
|
"thresholds": {
|
|
"warning": 50,
|
|
"critical": 75,
|
|
"breach": 100
|
|
},
|
|
"testMode": false
|
|
},
|
|
"upload": {
|
|
"maxFileSizeMB": 10,
|
|
"allowedFileTypes": ["pdf", "doc", "docx", ...],
|
|
"maxFilesPerRequest": 10
|
|
},
|
|
"workflow": {
|
|
"maxApprovalLevels": 10,
|
|
"maxParticipants": 50,
|
|
"maxSpectators": 20
|
|
},
|
|
"workNotes": {
|
|
"maxMessageLength": 2000,
|
|
"maxAttachmentsPerNote": 5,
|
|
"enableReactions": true,
|
|
"enableMentions": true
|
|
},
|
|
"features": {
|
|
"ENABLE_AI_CONCLUSION": true,
|
|
"ENABLE_TEMPLATES": false,
|
|
"ENABLE_ANALYTICS": true,
|
|
"ENABLE_EXPORT": true
|
|
},
|
|
"ui": {
|
|
"DEFAULT_THEME": "light",
|
|
"DEFAULT_LANGUAGE": "en",
|
|
"DATE_FORMAT": "DD/MM/YYYY",
|
|
"TIME_FORMAT": "12h",
|
|
"CURRENCY": "INR",
|
|
"CURRENCY_SYMBOL": "₹"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 Usage in Code
|
|
|
|
### Backend
|
|
```typescript
|
|
import { SYSTEM_CONFIG } from '@config/system.config';
|
|
|
|
// Access configuration
|
|
const maxLevels = SYSTEM_CONFIG.WORKFLOW.MAX_APPROVAL_LEVELS;
|
|
const workStart = SYSTEM_CONFIG.WORKING_HOURS.START_HOUR;
|
|
```
|
|
|
|
### Frontend
|
|
```typescript
|
|
import { configService } from '@/services/configService';
|
|
|
|
// Async usage
|
|
const config = await configService.getConfig();
|
|
const maxFileSize = config.upload.maxFileSizeMB;
|
|
|
|
// Helper functions
|
|
import { getWorkingHours, getTATThresholds } from '@/services/configService';
|
|
const workingHours = await getWorkingHours();
|
|
```
|
|
|
|
---
|
|
|
|
## 🔐 Security Best Practices
|
|
|
|
1. **Never commit `.env`** with real credentials
|
|
2. **Use strong JWT secrets** (min 32 characters)
|
|
3. **Rotate secrets regularly** in production
|
|
4. **Use environment-specific configs** for dev/staging/prod
|
|
5. **Store secrets in secure vaults** (AWS Secrets Manager, Azure Key Vault)
|
|
|
|
---
|
|
|
|
## 📝 Configuration Checklist
|
|
|
|
### Before Deployment
|
|
|
|
- [ ] Set `NODE_ENV=production`
|
|
- [ ] Configure database with SSL
|
|
- [ ] Set strong JWT secret
|
|
- [ ] Disable TAT test mode
|
|
- [ ] Configure email SMTP
|
|
- [ ] Set up Redis connection
|
|
- [ ] Configure file storage (local/S3/GCS)
|
|
- [ ] Test working hours match business hours
|
|
- [ ] Verify TAT thresholds are correct
|
|
- [ ] Enable/disable feature flags as needed
|
|
|
|
---
|
|
|
|
## 🛠️ Adding New Configuration
|
|
|
|
1. Add to `system.config.ts`:
|
|
```typescript
|
|
export const SYSTEM_CONFIG = {
|
|
// ...existing config
|
|
MY_NEW_SETTING: {
|
|
VALUE: process.env.MY_VALUE || 'default',
|
|
},
|
|
};
|
|
```
|
|
|
|
2. Add to `getPublicConfig()` if needed on frontend:
|
|
```typescript
|
|
export function getPublicConfig() {
|
|
return {
|
|
// ...existing
|
|
myNewSetting: SYSTEM_CONFIG.MY_NEW_SETTING,
|
|
};
|
|
}
|
|
```
|
|
|
|
3. Access in code:
|
|
```typescript
|
|
const value = SYSTEM_CONFIG.MY_NEW_SETTING.VALUE;
|
|
```
|
|
|
|
---
|
|
|
|
## 📚 Related Files
|
|
|
|
- `src/config/system.config.ts` - Central configuration
|
|
- `src/config/tat.config.ts` - TAT-specific (re-exports from system.config)
|
|
- `src/config/constants.ts` - Legacy constants (being migrated)
|
|
- `src/routes/config.routes.ts` - Configuration API endpoint
|
|
- Frontend: `src/services/configService.ts` - Configuration fetching service
|
|
|
|
---
|
|
|
|
## ✅ Benefits of Centralized Configuration
|
|
|
|
✅ **Single Source of Truth** - All settings in one place
|
|
✅ **Environment-based** - Different configs for dev/staging/prod
|
|
✅ **Frontend Sync** - Frontend fetches config from backend
|
|
✅ **No Hardcoding** - All values configurable via .env
|
|
✅ **Type-Safe** - TypeScript interfaces ensure correctness
|
|
✅ **Easy Updates** - Change .env without code changes
|
|
|