System Architecture

DeveloperEvaluator4 min read

2. Architecture Overview

2.1 System Interconnection Map

The following diagram shows how all major subsystems relate to each other. Every arrow represents a data flow or dependency that exists in the codebase.

graph TB subgraph "User Interaction Layer" UI[Dashboard UI<br/>Next.js App Router] SSE[SSE Streaming<br/>/api/v1/events/*] end subgraph "API Layer" tRPC[tRPC v11<br/>8 Routers] REST[REST Endpoints<br/>SSE only] end subgraph "Intelligence Core" WE[Workflow Engine<br/>AsyncGenerator] DS[Discussion Service<br/>Single/Parallel/Consensus] CS[Consolidation Service<br/>Pattern Extraction] PG[Persona Generator<br/>System Prompts] end subgraph "Memory & Insights" IP[Insight Persistence<br/>Review Key Points] IS[Insight Search<br/>Hybrid Vector+Text] WI[Workflow Insights<br/>Memory Loading] ES[Embedding Service<br/>OpenAI 1536-dim] CPS[Cross-Project Scanner<br/>Similarity Detection] end subgraph "Persona System" PS[Persona Stats<br/>XP & Leveling] PA[Persona A/B<br/>Comparison Engine] end subgraph "Code Intelligence" CA[Code Analysis<br/>Pattern Detection] AF[Auto-Fix Pipeline<br/>Security Remediation] RF[Refactor Pipeline<br/>Code Quality] end subgraph "Data Layer" PG16[(PostgreSQL 16<br/>+ pgvector + RLS)] Redis[(Redis 7<br/>Rate Limiting)] LLM[LLM Providers<br/>Anthropic/OpenAI/Google/Ollama] end UI --> tRPC UI --> SSE SSE --> REST REST --> WE REST --> DS tRPC --> WE tRPC --> DS tRPC --> CS WE --> PS WE --> WI WE --> ES WE --> IP DS --> PS IP --> ES IP --> CPS CPS --> ES IS --> ES WE --> LLM DS --> LLM CS --> LLM CA --> LLM AF --> LLM RF --> LLM WE --> PG16 DS --> PG16 IP --> PG16 IS --> PG16 CPS --> PG16 PS --> PG16 CA --> PG16 AF --> PG16 RF --> PG16 tRPC --> Redis REST --> Redis

2.2 Entity-Relationship Diagram

This ER diagram captures the full Prisma schema with all 28 models. Relations shown are actual foreign key constraints from schema.prisma.

erDiagram Tenant ||--o{ TenantMember : "has members" Tenant ||--o{ Persona : "owns" Tenant ||--o{ Workflow : "owns" Tenant ||--o{ Discussion : "owns" Tenant ||--o{ Project : "owns" Tenant ||--o{ WorkflowInsight : "owns" Tenant ||--o{ Consolidation : "owns" Tenant ||--o{ Repository : "owns" Tenant ||--o{ ApiKey : "stores" Tenant ||--o{ AuditLog : "logs" User ||--o{ TenantMember : "belongs to" User ||--o{ Persona : "creates" User ||--o{ Workflow : "runs" User ||--o{ Discussion : "starts" User ||--o{ Project : "owns" User ||--o{ WorkflowInsight : "curates" User ||--o{ ActionPoint : "tracks" Workflow ||--o{ WorkflowStep : "contains" Workflow ||--o{ WorkflowInsight : "produces" Workflow ||--o{ ActionPoint : "generates" Workflow }o--o| Project : "linked to" WorkflowStep }o--o| Persona : "per-step override" Discussion ||--o{ DiscussionMessage : "contains" Discussion }o--o| Persona : "uses" Discussion }o--o| Project : "about" Project ||--o{ BlogPost : "publishes" Project ||--o{ Repository : "links" Project ||--o{ WorkflowInsight : "accumulates" Project ||--o{ ActionPoint : "tracks" Consolidation ||--o{ ConsolidationPattern : "extracts" Repository ||--o{ RepositoryFile : "indexes" Repository ||--o{ CodeAnalysisRun : "analyzed by" Repository ||--o{ CodePattern : "reveals" Repository ||--o{ AutoFixRun : "fixed by" Repository ||--o{ RefactorRun : "refactored by" AutoFixRun ||--o{ AutoFixIssue : "finds" RefactorRun ||--o{ RefactorItem : "identifies" CodeAnalysisRun ||--o{ CodePattern : "detects" CodeAnalysisRun ||--o{ GeneratedDoc : "produces" Persona { uuid id PK string name text systemPrompt int level int xp string[] traits string[] specializations int usageCount float successRate } WorkflowInsight { uuid id PK string title text detail text suggestion string category string insightType string severity uuid pairedInsightId vector embedding tsvector searchVector } ActionPoint { uuid id PK string title text description string category string priority string status boolean isAutoDetected uuid sourceInsightId }

2.3 Request Flow: tRPC

sequenceDiagram participant C as Client (React) participant H as httpBatchLink participant R as /api/trpc/[trpc] participant M as Middleware Chain participant S as Service Layer participant DB as PostgreSQL + RLS C->>H: trpc.router.procedure() H->>R: HTTP POST (batched) R->>M: createContext(session, prisma, requestId) M->>M: withRateLimit (Redis) M->>M: enforceAuth (JWT session) M->>M: enforceTenant (extract tenantId) M->>S: Router procedure S->>DB: Prisma query (RLS enforced) DB-->>S: Result (tenant-scoped) S-->>M: Response M-->>R: JSON R-->>H: HTTP Response H-->>C: Typed result

2.4 Request Flow: SSE (Workflows & Discussions)

sequenceDiagram participant C as Client (useSSE hook) participant E as /api/v1/events/[feature]/[id] participant A as authenticateRequest() participant G as AsyncGenerator participant LLM as LLM Provider (BYOK) participant DB as PostgreSQL C->>E: GET (EventSource) E->>A: Rate limit + auth check A-->>E: { userId, tenantId } E->>G: runWorkflow() / processDiscussion() loop For each step/message G->>LLM: resolveProvider() + complete/stream() LLM-->>G: Response chunks G->>DB: Persist step output G-->>E: yield WorkflowEvent E-->>C: SSE text/event-stream end G-->>E: yield { type: "done" } E-->>C: Final SSE event