# marcelorayzen/rayzen-ai architecture

> Architecture diagram of the GitHub repository marcelorayzen/rayzen-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marcelorayzen/rayzen-ai
- Repository: https://github.com/marcelorayzen/rayzen-ai

## Overview

#### Purpose and topology
Rayzen AI is a TypeScript monorepo for a personal AI platform: semantic project memory, LLM-assisted work, controlled desktop execution, and evolving documentation. V1 is the active stack: Next.js UI, NestJS API, and local PC Agent. V2 is a separate mission-oriented backend with `/v2` routes and an isolated Prisma schema.
- `apps/web/app/page.tsx`
- `apps/api/src/main.ts`
- `apps/api-v2/src/main.ts`

#### User/API entry boundary
The Next.js App Router client provides chat, project, graph, discovery, mission, and settings surfaces. Its API client and streaming/event hooks connect browser state to the V1 API over HTTP/SSE. V1 Nest bootstrap composes domain modules; authentication protects API access.
- `apps/web/lib/api-client.ts`
- `apps/web/app/hooks/useChatStream.ts`
- `apps/api/src/app.module.ts`
- `apps/api/src/modules/auth/jwt-auth.guard.ts`

#### V1 orchestration pipeline
The V1 orchestrator is the central control plane for user messages: validation precedes intent handling/routing and streamed responses, then invokes specialized modules. Work modes influence behavior; output/prompt validation forms a security boundary around LLM interaction.
- `apps/api/src/modules/orchestrator/orchestrator.service.ts`
- `apps/api/src/modules/validation/validation.service.ts`
- `apps/api/src/modules/execution/execution.service.ts`

#### Knowledge, memory, and project state
Persistent project context is modeled through memory, Brain ingestion/search, graph/knowledge-graph, project state, events, and wiki synthesis. Documents and conversations are embedded through Jina and stored/queryable in PostgreSQL with pgvector; this context feeds LLM requests and UI panels.
- `apps/api/src/modules/memory/memory.service.ts`
- `apps/api/src/modules/brain/brain.service.ts`
- `apps/api/src/modules/graph/knowledge-graph.service.ts`
- `apps/api/prisma/schema.prisma`

#### LLM and content-service boundary
Backend modules call provider-agnostic LLM services through LiteLLM. Specialized capabilities include document generation, content/diagram output, voice via Groq, and Notion synchronization. API modules own domain prompts and validation rather than exposing providers directly to the browser.
- `apps/api/src/modules/orchestrator/orchestrator.service.ts`
- `apps/api/src/modules/document-processing/document-processing.service.ts`
- `apps/api/src/modules/voice/voice.service.ts`
- `infra/litellm/config.yaml`

#### Remote execution and safety boundary
Execution creates queued work for the Node.js PC Agent; the agent polls Redis and dispatches only typed, allowlisted actions. Path guards, role policy, and dry-run behavior constrain filesystem, shell-adjacent, Docker, Git, and desktop actions. Agent results return through the API bridge/session model for presentation and auditability.
- `apps/api/src/modules/agent-bridge/agent-bridge.service.ts`
- `apps/agent/src/poller.ts`
- `apps/agent/src/executor.ts`
- `apps/agent/src/security/whitelist.ts`

#### V2 mission-engine track
V2 introduces missions composed of executable steps, routing, approval gates, policies, specialists/skills, knowledge governance, workflow scheduling, quality benchmarking, and observability. It is architecturally distinct from V1 but shares the platform’s PostgreSQL-based operational model.
- `apps/api-v2/src/mission/mission.service.ts`
- `apps/api-v2/src/mission/step-executor.service.ts`
- `apps/api-v2/src/approval-gates/approval-gates.service.ts`
- `apps/api-v2/prisma/schema.prisma`

#### Runtime and infrastructure
Primary runtimes are Node.js/TypeScript, Next.js, NestJS/Fastify, Docker Compose, PostgreSQL 16 + pgvector, Redis 7/BullMQ, and Prisma. LiteLLM fronts OpenAI/Groq/Anthropic-compatible LLM access; Jina supplies embeddings; optional integrations include Notion and Groq voice. Deployment is containerized behind Caddy/Cloudflare Tunnel infrastructure.
- `docker-compose.yml`
- `infra/caddy/Caddyfile`
- `apps/api/Dockerfile`
- `apps/agent/Dockerfile.server`

Main entry points: [`apps/api/src/modules/orchestrator/orchestrator.service.ts`](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/orchestrator/orchestrator.service.ts) (Orchestrator), [`apps/api/src/main.ts`](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/main.ts) (V1 Nest API), [`apps/agent/src/poller.ts`](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/agent/src/poller.ts) (PC Agent poller), [`apps/web/lib/api-client.ts`](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/web/lib/api-client.ts) (API client & streams)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_web["Next.js UI<br/>App Router client<br/>[page.tsx]"]
  node_web_api["API client &amp; streams<br/>HTTP/SSE client<br/>[api-client.ts]"]
end

subgraph group_v1["V1 control plane"]
  node_api["V1 Nest API<br/>NestJS/Fastify runtime<br/>[main.ts]"]
  node_auth["JWT auth<br/>access guard<br/>[jwt-auth.guard.ts]"]
  node_orchestrator{{"Orchestrator<br/>message control plane"}}
  node_validation["Prompt/output validation<br/>security boundary"]
end

subgraph group_knowledge["Knowledge services"]
  node_memory["Memory &amp; Brain<br/>context ingestion/search<br/>[brain.service.ts]"]
  node_knowledge_graph["Knowledge graph<br/>project context graph"]
  node_postgres[("PostgreSQL + pgvector<br/>persistent store<br/>[schema.prisma]")]
end

subgraph group_execution["Controlled execution"]
  node_execution_service["Execution service<br/>queued work producer"]
  node_agent_bridge["Agent bridge<br/>session/result bridge"]
  node_redis["Redis / BullMQ<br/>work queue"]
  node_pc_agent["PC Agent poller<br/>Node.js worker<br/>[poller.ts]"]
  node_agent_security{{"Allowlist &amp; guards<br/>agent safety policy<br/>[whitelist.ts]"}}
end

subgraph group_v2["V2 mission engine"]
  node_v2_api["V2 Nest API<br/>mission backend<br/>[main.ts]"]
  node_missions{{"Mission service<br/>mission control plane<br/>[mission.service.ts]"}}
  node_step_executor["Step executor<br/>workflow execution"]
  node_approval_gates["Approval gates<br/>policy checkpoint"]
  node_v2_postgres[("V2 PostgreSQL schema<br/>mission persistence<br/>[schema.prisma]")]
end

node_litellm{{"LiteLLM<br/>provider gateway<br/>[config.yaml]"}}
node_jina["Jina<br/>embedding provider"]

node_web -->|"uses"| node_web_api
node_web_api -->|"HTTP/SSE"| node_api
node_api -->|"protects access"| node_auth
node_api -->|"user messages"| node_orchestrator
node_orchestrator -->|"validate input/output"| node_validation
node_orchestrator -->|"retrieves context"| node_memory
node_orchestrator -->|"project context"| node_knowledge_graph
node_orchestrator -->|"LLM requests"| node_litellm
node_orchestrator -->|"execution work"| node_execution_service
node_memory -->|"embeddings"| node_jina
node_memory -->|"stores/searches vectors"| node_postgres
node_knowledge_graph -->|"persists graph"| node_postgres
node_execution_service -->|"enqueue"| node_redis
node_pc_agent -->|"polls"| node_redis
node_pc_agent -->|"authorizes actions"| node_agent_security
node_pc_agent -->|"reports results"| node_agent_bridge
node_agent_bridge -->|"sessions/results"| node_api
node_web_api -->|"/v2 HTTP"| node_v2_api
node_v2_api -->|"mission requests"| node_missions
node_missions -->|"plans steps"| node_step_executor
node_step_executor -->|"requires approval"| node_approval_gates
node_missions -->|"persists missions"| node_v2_postgres

click node_web "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/web/app/page.tsx"
click node_web_api "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/web/lib/api-client.ts"
click node_api "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/main.ts"
click node_auth "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/auth/jwt-auth.guard.ts"
click node_orchestrator "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/orchestrator/orchestrator.service.ts"
click node_validation "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/validation/validation.service.ts"
click node_memory "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/brain/brain.service.ts"
click node_knowledge_graph "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/graph/knowledge-graph.service.ts"
click node_postgres "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/prisma/schema.prisma"
click node_litellm "https://github.com/marcelorayzen/rayzen-ai/blob/main/infra/litellm/config.yaml"
click node_execution_service "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/execution/execution.service.ts"
click node_agent_bridge "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/agent-bridge/agent-bridge.service.ts"
click node_pc_agent "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/agent/src/poller.ts"
click node_agent_security "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/agent/src/security/whitelist.ts"
click node_v2_api "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/main.ts"
click node_missions "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/mission/mission.service.ts"
click node_step_executor "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/mission/step-executor.service.ts"
click node_approval_gates "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/approval-gates/approval-gates.service.ts"
click node_v2_postgres "https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/prisma/schema.prisma"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_web_api toneBlue
class node_api,node_auth,node_orchestrator,node_validation toneAmber
class node_memory,node_knowledge_graph,node_postgres toneMint
class node_execution_service,node_agent_bridge,node_redis,node_pc_agent,node_agent_security toneRose
class node_v2_api,node_missions,node_step_executor,node_approval_gates,node_v2_postgres toneIndigo
class node_litellm,node_jina toneNeutral
```

## Components

### Client

- [Next.js UI](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/web/app/page.tsx): App Router client · Chat, project, graph, discovery, mission, and settings surfaces. · `apps/web/app/page.tsx`
- [API client & streams](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/web/lib/api-client.ts): HTTP/SSE client · `apps/web/lib/api-client.ts`

### V1 control plane

- [V1 Nest API](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/main.ts): NestJS/Fastify runtime · Authenticated composition root for V1 domain modules. · `apps/api/src/main.ts`
- [JWT auth](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/auth/jwt-auth.guard.ts): access guard · `apps/api/src/modules/auth/jwt-auth.guard.ts`
- [Orchestrator](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/orchestrator/orchestrator.service.ts): message control plane · Validates, routes, streams, and coordinates specialized work. · `apps/api/src/modules/orchestrator/orchestrator.service.ts`
- [Prompt/output validation](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/validation/validation.service.ts): security boundary · `apps/api/src/modules/validation/validation.service.ts`

### Knowledge services

- [Memory & Brain](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/brain/brain.service.ts): context ingestion/search · Embeds and retrieves documents and conversations. · `apps/api/src/modules/brain/brain.service.ts`
- [Knowledge graph](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/graph/knowledge-graph.service.ts): project context graph · `apps/api/src/modules/graph/knowledge-graph.service.ts`
- [PostgreSQL + pgvector](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/prisma/schema.prisma): persistent store · Prisma-backed project, memory, graph, and conversation data. · `apps/api/prisma/schema.prisma`

### Controlled execution

- [Execution service](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/execution/execution.service.ts): queued work producer · `apps/api/src/modules/execution/execution.service.ts`
- [Agent bridge](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api/src/modules/agent-bridge/agent-bridge.service.ts): session/result bridge · Returns execution results for presentation and auditability. · `apps/api/src/modules/agent-bridge/agent-bridge.service.ts`
- **Redis / BullMQ**: work queue
- [PC Agent poller](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/agent/src/poller.ts): Node.js worker · Polls queued work and dispatches typed actions. · `apps/agent/src/poller.ts`
- [Allowlist & guards](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/agent/src/security/whitelist.ts): agent safety policy · Constrains filesystem, shell, Docker, Git, and desktop actions. · `apps/agent/src/security/whitelist.ts`

### V2 mission engine

- [V2 Nest API](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/main.ts): mission backend · Separate `/v2` runtime and operational model. · `apps/api-v2/src/main.ts`
- [Mission service](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/mission/mission.service.ts): mission control plane · Coordinates missions, routing, specialists, policies, and scheduling. · `apps/api-v2/src/mission/mission.service.ts`
- [Step executor](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/mission/step-executor.service.ts): workflow execution · Runs executable mission steps through approval gates. · `apps/api-v2/src/mission/step-executor.service.ts`
- [Approval gates](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/src/approval-gates/approval-gates.service.ts): policy checkpoint · `apps/api-v2/src/approval-gates/approval-gates.service.ts`
- [V2 PostgreSQL schema](https://github.com/marcelorayzen/rayzen-ai/blob/main/apps/api-v2/prisma/schema.prisma): mission persistence · Isolated Prisma schema for V2 data. · `apps/api-v2/prisma/schema.prisma`

### Other components

- [LiteLLM](https://github.com/marcelorayzen/rayzen-ai/blob/main/infra/litellm/config.yaml): provider gateway · Routes provider-agnostic LLM requests to compatible model providers. · `infra/litellm/config.yaml`
- **Jina**: embedding provider

## Connections

- Next.js UI → API client & streams: uses
- API client & streams → V1 Nest API: HTTP/SSE
- V1 Nest API → JWT auth: protects access
- V1 Nest API → Orchestrator: user messages
- Orchestrator → Prompt/output validation: validate input/output
- Orchestrator → Memory & Brain: retrieves context
- Orchestrator → Knowledge graph: project context
- Orchestrator → LiteLLM: LLM requests
- Orchestrator → Execution service: execution work
- Memory & Brain → Jina: embeddings
- Memory & Brain → PostgreSQL + pgvector: stores/searches vectors
- Knowledge graph → PostgreSQL + pgvector: persists graph
- Execution service → Redis / BullMQ: enqueue
- PC Agent poller → Redis / BullMQ: polls
- PC Agent poller → Allowlist & guards: authorizes actions
- PC Agent poller → Agent bridge: reports results
- Agent bridge → V1 Nest API: sessions/results
- API client & streams → V2 Nest API: /v2 HTTP
- V2 Nest API → Mission service: mission requests
- Mission service → Step executor: plans steps
- Step executor → Approval gates: requires approval
- Mission service → V2 PostgreSQL schema: persists missions
