codenuk_backend_mine/services/unison/WORKFLOW_DIAGRAM.md
2025-09-26 17:04:14 +05:30

500 lines
16 KiB
Markdown

# Unison Service - Visual Workflow Diagram
## 🏗️ Complete System Architecture
```
┌─────────────────────────────────────────────────────────────────────────────────┐
│ UNISON SERVICE ARCHITECTURE │
└─────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Client App │───▶│ Unison Service │───▶│ Claude AI API │
│ │ │ (Port 8014) │ │ │
└─────────────────┘ └─────────┬────────┘ └─────────────────┘
┌────────────┼────────────┐
│ │ │
┌───────▼──────┐ ┌───▼────┐ ┌────▼──────┐
│ Tech Stack │ │Template│ │Template │
│ Selector │ │Manager │ │Manager AI │
│ (Port 8002) │ │(8009) │ │(Port 8013)│
└──────────────┘ └────────┘ └───────────┘
```
## 🔄 Detailed Workflow Flow
### 1. Request Processing Pipeline
```
┌─────────────────┐
│ Client Request │
└─────────┬───────┘
┌─────────────────┐
│ Express Server │
│ (Port 8014) │
└─────────┬───────┘
┌─────────────────┐
│ Security Stack │
│ • Helmet │
│ • CORS │
│ • Rate Limiting │
└─────────┬───────┘
┌─────────────────┐
│ Request Parser │
│ • JSON Parser │
│ • URL Encoded │
└─────────┬───────┘
┌─────────────────┐
│ Validation │
│ • Joi Schema │
│ • Input Check │
└─────────┬───────┘
┌─────────────────┐
│ Route Handler │
│ • Unified │
│ • Tech Stack │
│ • Template │
└─────────┬───────┘
```
### 2. Unified Recommendation Workflow
```
┌─────────────────┐
│ POST /unified │
└─────────┬───────┘
┌─────────────────┐
│ Input Validation│
│ • Domain │
│ • Budget │
│ • Technologies │
│ • Template ID │
└─────────┬───────┘
┌─────────────────┐
│ Parallel Calls │
│ ┌─────────────┐ │
│ │Tech Stack │ │
│ │Selector │ │
│ └─────────────┘ │
│ ┌─────────────┐ │
│ │Template │ │
│ │Manager │ │
│ └─────────────┘ │
└─────────┬───────┘
┌─────────────────┐
│ Decision Logic │
│ • Both Success │
│ • One Success │
│ • Both Failed │
└─────────┬───────┘
┌─────────────────┐
│ Claude AI │
│ Unification │
│ (if both OK) │
└─────────┬───────┘
┌─────────────────┐
│ Schema │
│ Validation │
└─────────┬───────┘
┌─────────────────┐
│ Response │
│ Generation │
└─────────┬───────┘
┌─────────────────┐
│ Client Response │
└─────────────────┘
```
### 3. Service Integration Details
#### Tech Stack Selector Integration
```
┌─────────────────┐
│ Unison Service │
└─────────┬───────┘
│ POST /recommend/best
┌─────────────────┐
│ Tech Stack │
│ Selector │
│ (Port 8002) │
└─────────┬───────┘
┌─────────────────┐
│ Data Sources │
│ • PostgreSQL │
│ • Neo4j │
│ • Price Data │
└─────────┬───────┘
┌─────────────────┐
│ Claude AI │
│ Analysis │
└─────────┬───────┘
┌─────────────────┐
│ Recommendations │
│ • Cost Analysis │
│ • Team Sizes │
│ • Tech Stacks │
└─────────────────┘
```
#### Template Manager Integration
```
┌─────────────────┐
│ Unison Service │
└─────────┬───────┘
│ GET /api/templates/{id}/ai-recommendations
┌─────────────────┐
│ Template │
│ Manager │
│ (Port 8009) │
└─────────┬───────┘
┌─────────────────┐
│ Template │
│ Database │
│ • Features │
│ • Usage Data │
└─────────┬───────┘
┌─────────────────┐
│ Template AI │
│ Service │
│ (Port 8013) │
└─────────┬───────┘
┌─────────────────┐
│ AI Analysis │
│ • Feature Match │
│ • Optimization │
└─────────────────┘
```
### 4. Claude AI Unification Process
```
┌─────────────────┐
│ Tech Stack │
│ Recommendation │
└─────────┬───────┘
┌─────────────────┐
│ Claude AI │
│ Analysis │
│ • Cost Balance │
│ • Domain Match │
│ • Tech Merge │
└─────────┬───────┘
┌─────────────────┐
│ Template │
│ Recommendation │
└─────────┬───────┘
┌─────────────────┐
│ Unified │
│ Recommendation │
│ • Optimized │
│ • Balanced │
│ • Validated │
└─────────────────┘
```
### 5. Error Handling & Fallback Strategy
```
┌─────────────────┐
│ Service Call │
└─────────┬───────┘
┌─────────────────┐
│ Success? │
└─────────┬───────┘
┌─────┴─────┐
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ Success │ │ Failure │
└────┬────┘ └────┬────┘
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ Process │ │ Log │
│ Result │ │ Error │
└────┬────┘ └────┬────┘
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ Return │ │ Fallback│
│ Data │ │ Strategy│
└─────────┘ └─────────┘
```
### 6. Health Monitoring Flow
```
┌─────────────────┐
│ Health Check │
│ Request │
└─────────┬───────┘
┌─────────────────┐
│ Check Internal │
│ • Memory │
│ • CPU │
│ • Uptime │
└─────────┬───────┘
┌─────────────────┐
│ Check External │
│ Services │
│ • Tech Stack │
│ • Template │
└─────────┬───────┘
┌─────────────────┐
│ Aggregate │
│ Health Status │
└─────────┬───────┘
┌─────────────────┐
│ Return Health │
│ Response │
└─────────────────┘
```
## 🔧 Data Flow Architecture
### Request Data Flow
```
Client Request
┌─────────────────┐
│ Input Validation│
│ • Joi Schema │
│ • Type Check │
│ • Range Check │
└─────────┬───────┘
┌─────────────────┐
│ Service Calls │
│ • Parallel │
│ • Async │
│ • Timeout │
└─────────┬───────┘
┌─────────────────┐
│ Data Processing │
│ • Merge │
│ • Optimize │
│ • Validate │
└─────────┬───────┘
┌─────────────────┐
│ Response │
│ • JSON Format │
│ • Error Handling│
│ • Logging │
└─────────────────┘
```
### Response Data Flow
```
Service Response
┌─────────────────┐
│ Schema │
│ Validation │
│ • Ajv Validator │
│ • Field Check │
│ • Type Check │
└─────────┬───────┘
┌─────────────────┐
│ Error Handling │
│ • Validation │
│ • Service │
│ • Network │
└─────────┬───────┘
┌─────────────────┐
│ Response │
│ Formatting │
│ • JSON │
│ • Metadata │
│ • Status Codes │
└─────────┬───────┘
┌─────────────────┐
│ Client Response │
└─────────────────┘
```
## 📊 Performance Flow
### Response Time Breakdown
```
Total Request Time: ~50ms
├── Input Validation: ~2ms
├── Service Calls: ~30ms
│ ├── Tech Stack: ~15ms
│ └── Template: ~15ms
├── Claude AI: ~2-5s (if used)
├── Schema Validation: ~3ms
└── Response Formatting: ~1ms
```
### Memory Usage Flow
```
Memory Allocation
├── Base Service: ~16MB
├── Request Processing: ~2MB
├── External Calls: ~1MB
└── Response Generation: ~1MB
```
## 🛡️ Security Flow
### Security Pipeline
```
Incoming Request
┌─────────────────┐
│ Helmet │
│ • Security │
│ Headers │
└─────────┬───────┘
┌─────────────────┐
│ CORS │
│ • Origin Check │
│ • Method Check │
└─────────┬───────┘
┌─────────────────┐
│ Rate Limiting │
│ • IP Tracking │
│ • Request Count │
└─────────┬───────┘
┌─────────────────┐
│ Input │
│ Validation │
│ • XSS Prevent │
│ • Injection │
└─────────┬───────┘
┌─────────────────┐
│ Processed │
│ Request │
└─────────────────┘
```
## 🚀 Deployment Flow
### Docker Deployment
```
Docker Build
├── Node.js 18 Alpine
├── Dependencies Install
├── Source Code Copy
├── Permissions Set
└── Health Check Config
Docker Run
├── Port Mapping: 8014:8010
├── Environment Variables
├── Volume Mounts
└── Network Configuration
Service Running
├── Health Checks
├── Log Monitoring
├── Error Tracking
└── Performance Metrics
```
---
## 🎯 Key Workflow Characteristics
1. **Asynchronous Processing**: Parallel service calls for performance
2. **Fault Tolerance**: Multiple fallback strategies
3. **Data Validation**: Strict input/output validation
4. **AI Integration**: Intelligent recommendation unification
5. **Comprehensive Logging**: Full request/response tracking
6. **Health Monitoring**: Proactive service monitoring
7. **Security First**: Multiple security layers
8. **Performance Optimized**: Fast response times
9. **Scalable Architecture**: Containerized deployment
10. **Observable System**: Detailed metrics and logging
This workflow ensures that the Unison service provides **reliable, intelligent, and high-performance** tech stack recommendations while maintaining excellent security and observability standards.
---
*Generated on: 2025-09-22T05:01:45.120Z*
*Service Version: 1.0.0*
*Status: OPERATIONAL*