graph TD
A[User Requests Documentation] --> B[MultiAgentDocumentationService]
B --> C{Phase 1: Orchestrator}
C --> D[Analyze Complete Schema]
D --> E[Identify Domain Groups]
E --> F{Cache Available?}
F -->|Yes| G[Use Cached Groupings]
F -->|No| H[LLM Analysis]
H --> I[Cache Result]
I --> J{Phase 2: Domain Agents}
G --> J
J --> K[Domain Agent 1<br/>User Management]
J --> L[Domain Agent 2<br/>Order Processing]
J --> M[Domain Agent 3<br/>Notifications]
J --> N[Domain Agent 4<br/>Data Pipeline]
J --> O[Domain Agent 5<br/>Audit Logs]
K --> P{Phase 3: Aggregator}
L --> P
M --> P
N --> P
O --> P
P --> Q[Combine Results]
Q --> R[Generate ER Diagram]
R --> S[Create Executive Summary]
S --> T[Build Complete Markdown]
T --> U[Save to Database]
U --> V[Return Documentation]
style C fill:#e1f5ff
style J fill:#fff4e1
style P fill:#e8f5e9
Detailed Phase Breakdown
Phase 1: Orchestrator Agent
sequenceDiagram
participant Client
participant Service
participant Cache
participant LLM
participant DB
Client->>Service: GenerateDocumentationAsync()
Service->>DB: Fetch DataSource & Metadata
DB-->>Service: Tables, Columns, FKs
Service->>Cache: Check for cached groupings
alt Cache Hit
Cache-->>Service: Return OrchestratorResult
else Cache Miss
Service->>LLM: Analyze schema (3000 tokens)
LLM-->>Service: JSON with domain groups
Service->>Service: Validate & adjust groups
Service->>Cache: Store for 60 minutes
end
Service->>Client: Progress: "Analyzing Schema" (10%)
Phase 2: Parallel Domain Agents
sequenceDiagram
participant Service
participant Semaphore
participant Agent1
participant Agent2
participant Agent3
participant LLM
participant Client
Service->>Semaphore: Acquire (max 5 concurrent)
par Domain 1
Service->>Agent1: Document User Management
Agent1->>LLM: Generate docs (2000 tokens)
LLM-->>Agent1: JSON result
Agent1-->>Service: DomainResult
Service->>Client: Progress: "Domain 1/5" (30%)
and Domain 2
Service->>Agent2: Document Order Processing
Agent2->>LLM: Generate docs (2500 tokens)
LLM-->>Agent2: JSON result
Agent2-->>Service: DomainResult
Service->>Client: Progress: "Domain 2/5" (50%)
and Domain 3
Service->>Agent3: Document Notifications
Agent3->>LLM: Generate docs (1800 tokens)
LLM-->>Agent3: JSON result
Agent3-->>Service: DomainResult
Service->>Client: Progress: "Domain 3/5" (70%)
end
Service->>Semaphore: Release all
Phase 3: Aggregator Agent
sequenceDiagram
participant Service
participant Aggregator
participant LLM
participant DB
participant Client
Service->>Client: Progress: "Aggregating Results" (90%)
Service->>Aggregator: Combine all domain results
Aggregator->>LLM: Create unified docs (3000 tokens)
LLM-->>Aggregator: JSON with complete markdown
Aggregator-->>Service: AggregatedDocumentation
Service->>DB: Create DataSourceDocumentation
Service->>DB: Create DocumentationSections
DB-->>Service: Documentation ID
Service->>Client: Progress: "Complete" (100%)
Service->>Client: Return Documentation
Data Flow
graph LR
A[Database Schema] --> B[Metadata Service]
B --> C[FilterTables]
C --> D[Orchestrator Prompt]
D --> E[Orchestrator LLM Call]
E --> F[OrchestratorResult]
F --> G{Split by Domain}
G --> H1[Domain 1 Tables]
G --> H2[Domain 2 Tables]
G --> H3[Domain 3 Tables]
H1 --> I1[Domain 1 Prompt]
H2 --> I2[Domain 2 Prompt]
H3 --> I3[Domain 3 Prompt]
I1 --> J1[Domain Agent 1]
I2 --> J2[Domain Agent 2]
I3 --> J3[Domain Agent 3]
J1 --> K[DomainResult List]
J2 --> K
J3 --> K
F --> L[Aggregator Prompt]
K --> L
L --> M[Aggregator LLM Call]
M --> N[AggregatedDocumentation]
N --> O[Parse into Sections]
O --> P[Save to Database]
style F fill:#e1f5ff
style K fill:#fff4e1
style N fill:#e8f5e9
graph TD
A[Start Documentation] --> B{Orchestrator Success?}
B -->|No| C[Log Error & Throw Exception]
B -->|Yes| D[Start Domain Agents]
D --> E{Domain 1 Success?}
D --> F{Domain 2 Success?}
D --> G{Domain 3 Success?}
E -->|No| H[Create Error Result for Domain 1]
E -->|Yes| I[Add Domain 1 Result]
F -->|No| J[Create Error Result for Domain 2]
F -->|Yes| K[Add Domain 2 Result]
G -->|No| L[Create Error Result for Domain 3]
G -->|Yes| M[Add Domain 3 Result]
H --> N[Continue with Other Domains]
I --> N
J --> N
K --> N
L --> N
M --> N
N --> O{Aggregator Success?}
O -->|No| P[Use Fallback Aggregation]
O -->|Yes| Q[Use LLM Aggregation]
P --> R[Save Documentation]
Q --> R
R --> S[Return Result]
style C fill:#ffebee
style H fill:#fff3e0
style J fill:#fff3e0
style L fill:#fff3e0
style P fill:#fff3e0
Cache Strategy
graph LR
A[Request Documentation] --> B{Cache Enabled?}
B -->|No| C[Skip Cache Check]
B -->|Yes| D{Cache Hit?}
D -->|Yes| E[Check Expiration]
D -->|No| F[Run Orchestrator]
E --> G{Expired?}
G -->|Yes| F
G -->|No| H[Use Cached Result]
F --> I[Store in Cache]
I --> J[Set 60-min TTL]
J --> K[Continue to Domain Agents]
H --> K
C --> F
style H fill:#c8e6c9
style I fill:#fff9c4