# valynt/valueos architecture

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

- Interactive diagram: https://gitdiagram.com/valynt/valueos
- Repository: https://github.com/valynt/valueos

## Overview

1. **Repository shape**
   - This is a pnpm monorepo for **ValueOS**, a modular-monolith SaaS platform.
   - The main production runtimes are:
     - `apps/ValyntApp` — customer-facing web app
     - `packages/backend` — Express API/runtime
     - `apps/mcp-dashboard` — internal observability UI for MCP, not a customer product
   - Shared libraries live under `packages/*`, while deploy/runtime definitions live under `infra/`, `ops/`, `supabase/`, and `scripts/`.

2. **Primary user-facing flow**
   - Browser traffic lands in `apps/ValyntApp`, which is a React + Vite frontend.
   - The frontend uses feature modules, route guards, and context providers to render customer workflows such as onboarding, value modeling, deal assembly, billing, settings, and executive outputs.
   - It calls the backend API for authenticated reads/writes, then renders persisted state and generated artifacts back to the user.

3. **Backend as the system hub**
   - `packages/backend` is the central application boundary.
   - It exposes REST/route handlers plus tRPC-style APIs, and it owns:
     - authentication/authorization enforcement
     - tenant context resolution
     - business workflows
     - agent orchestration
     - persistence and integrations
     - billing/metering
     - security and observability hooks
   - The backend is organized into clear layers: `api/`, `services/`, `runtime/`, `repositories/`, `middleware/`, `workers/`, and `lib/`.

4. **Domain and workflow core**
   - The core business domain is “value engineering” and is centered on value cases, value trees, ROI models, opportunities, hypotheses, evidence, and realization plans.
   - The backend’s `services/value`, `services/workflow`, `services/value-graph`, `services/trust`, and `services/integrity` modules form the main business pipeline.
   - Typical progression is: capture context → model value → run agents/workflows → validate trust/integrity → generate artifacts → persist results.

5. **Agent fabric**
   - A major subsystem is the agent layer in `packages/backend/src/lib/agent-fabric` and related `services/agents` / `services/value`.
   - The repo references an 11-agent fabric, including agents for opportunity, target, financial modeling, integrity, realization, expansion, narrative, compliance, discovery, context extraction, and deal assembly.
   - Agent execution is not free-form: it is gated by `secureInvoke`, circuit breakers, Zod/schema validation, prompt registries, redaction, and policy checks.
   - The agent system consumes structured domain state rather than relying on keyword-based prompting.

6. **Data/storage boundary**
   - **Supabase/Postgres** is the primary system of record.
   - The schema and security model are defined in `infra/supabase/` with extensive migrations and rollback scripts.
   - Row-level security is a first-class boundary: tenant isolation is enforced in the database, then reinforced in backend middleware and tests.
   - **Redis** is used for cache, rate limiting, session/state support, queues/streams, and some distributed coordination.
   - The backend’s repositories wrap all direct persistence access, keeping service code separated from table-level concerns.

7. **Multi-tenancy and security model**
   - Tenant scope is a core architectural boundary across UI, API, and database layers.
   - The platform uses Supabase Auth, JWT claims, RBAC, MFA/WebAuthn support, session controls, CSRF/CORS protections, and request auditing.
   - Security logic appears in both `packages/backend/src/security` and `packages/backend/src/middleware`, plus Supabase RLS policies in the database layer.
   - Many tests explicitly target cross-tenant leakage, spoofed headers, privilege escalation, and policy regressions.

8. **Asynchronous and event-driven work**
   - The backend includes worker processes under `packages/backend/src/workers` for jobs such as billing aggregation, CRM sync, research ingestion, webhook retry, artifact generation, and workflow watchdog tasks.
   - Messaging/queue abstractions exist in `services/messaging`, `services/realtime`, `services/metering`, and related runtime adapters.
   - This means the architecture is not purely request/response; several business functions are completed asynchronously and then surfaced back to the UI through polling, realtime updates, or persisted workflow state.

9. **Server-driven UI and shared presentation**
   - `packages/sdui` is a separate engine for server-driven UI rendering, component registry, schema validation, state hydration, and partial patching.
   - The backend has matching SDUI services/adapters that generate schemas and action payloads for the frontend.
   - This creates a boundary where backend can shape UI behavior and layout, while the client renders from a constrained component model.
   - Shared UI primitives live in `packages/components`, which supports both the main app and reusable design-system surfaces.

10. **MCP and external protocol layers**
   - `packages/mcp` and backend MCP services implement Model Context Protocol modules, especially CRM and ground-truth capabilities.
   - These packages act as integration/protocol adapters rather than core product UI.
   - The internal `apps/mcp-dashboard` is an operational surface for observing and managing this layer.
   - These pieces matter to the architecture because they separate external tool/protocol access from the main customer workflow path.

11. **Integrations and external systems**
   - Third-party systems are handled through dedicated adapters in `packages/integrations` and backend service modules.
   - The repo includes CRM support such as HubSpot and Salesforce, plus webhooks, OAuth callbacks, and connection management.
   - External data sources also appear in the “ground-truth” and “memory” subsystems, where SEC/market/benchmark style inputs are ingested, cached, and reused for agent reasoning.

12. **Platform and deployment**
   - The deployment model is Kubernetes-first with blue/green support, HPA, network policies, and zero-trust security controls.
   - Infrastructure code lives in `infra/k8s`, `infra/terraform`, and `infra/observability`, with Supabase schema management under `infra/supabase`.
   - Observability is production-grade: OpenTelemetry, Prometheus, Grafana, Loki/Tempo-style tracing/logging, plus extensive CI gates and policy checks.
   - `ops/` and top-level `scripts/` provide local/dev/staging/production orchestration, validation, migrations, and release automation.

13. **How to draw the architecture**
   - A good diagram should show:
     - browser clients → `ValyntApp`
     - `ValyntApp` → backend API
     - backend API → domain services/runtime/agents
     - backend → Supabase/Postgres, Redis, and external services
     - backend → workers/queues for async jobs
     - backend ↔ SDUI engine for schema-driven UI
     - backend ↔ MCP/integration adapters for CRM and ground-truth tools
     - infrastructure/observability/security as cross-cutting platform layers
   - Keep the main conceptual boundary as: **presentation in `apps/ValyntApp`, orchestration and business logic in `packages/backend`, state in Supabase/Redis, and execution/integration in workers, agents, and adapters**.

Main entry points: [`packages/backend`](https://github.com/valynt/valueos/tree/main/packages/backend) (Backend), [`packages/backend/src/services`](https://github.com/valynt/valueos/tree/main/packages/backend/src/services) (Domain Services), [`packages/backend/src/workers`](https://github.com/valynt/valueos/tree/main/packages/backend/src/workers) (Workers), [`infra/supabase/supabase/migrations`](https://github.com/valynt/valueos/tree/main/infra/supabase/supabase/migrations) (Supabase DB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Applications"]
  node_valyntapp["ValyntApp<br/>react-vite frontend"]
  node_mcpdashboard["MCP Dashboard<br/>internal ops UI"]
end

subgraph group_packages["Shared Packages"]
  node_backend["Backend<br/>express runtime"]
  node_sdui["SDUI Engine<br/>rendering engine"]
  node_components["Design System<br/>ui primitives"]
  node_shared["Shared Domain<br/>common models"]
  node_integrations["Integrations<br/>external adapters"]
  node_mcp["MCP Packages<br/>protocol adapters"]
  node_memory["Memory<br/>context store"]
  node_workers["Workers<br/>async jobs"]
  node_api["API Layer<br/>routes+trpc"]
  node_services["Domain Services<br/>business orchestration"]
  node_runtime["Runtime Core<br/>workflow runtime"]
  node_agentfabric["Agent Fabric<br/>11-agent system"]
  node_valuegraph["Value Graph<br/>domain pipeline"]
end

subgraph group_platform["Platform"]
  node_supabase[("Supabase DB<br/>postgres+auth")]
  node_redis[("Redis<br/>cache+queues<br/>[redis-streams.yaml]")]
  node_k8s["K8s Runtime<br/>deployment platform"]
  node_observability["Observability<br/>otel+metrics"]
end

node_valyntapp -->|"authenticated API calls"| node_backend
node_valyntapp -->|"renders schemas"| node_sdui
node_valyntapp -->|"shared UI"| node_components
node_mcpdashboard -->|"ops API"| node_backend
node_backend -->|"exposes"| node_api
node_backend -->|"orchestrates"| node_services
node_backend -->|"executes"| node_runtime
node_backend -->|"runs agents"| node_agentfabric
node_backend -->|"value pipeline"| node_valuegraph
node_backend -->|"async jobs"| node_workers
node_backend -->|"persists state"| node_supabase
node_backend -->|"cache and queues"| node_redis
node_services -->|"domain flow"| node_valuegraph
node_services -->|"connectors"| node_integrations
node_services -->|"protocol bridge"| node_mcp
node_services -->|"shared context"| node_memory
node_runtime -->|"RLS-backed state"| node_supabase
node_runtime -->|"coordination"| node_redis
node_agentfabric -->|"context store"| node_memory
node_agentfabric -->|"durable facts"| node_supabase
node_workers -->|"consumes queues"| node_redis
node_workers -->|"job output"| node_supabase
node_supabase -.->|"audit signals"| node_observability
node_k8s -->|"deploys"| node_backend
node_k8s -->|"deploys"| node_workers
node_k8s -->|"deploys"| node_mcpdashboard
node_observability -.->|"watches"| node_backend
node_observability -.->|"watches"| node_workers

click node_valyntapp "https://github.com/valynt/valueos/tree/main/apps/ValyntApp"
click node_mcpdashboard "https://github.com/valynt/valueos/tree/main/apps/mcp-dashboard"
click node_backend "https://github.com/valynt/valueos/tree/main/packages/backend"
click node_sdui "https://github.com/valynt/valueos/tree/main/packages/sdui"
click node_components "https://github.com/valynt/valueos/tree/main/packages/components/design-system/src"
click node_shared "https://github.com/valynt/valueos/tree/main/packages/shared/src"
click node_integrations "https://github.com/valynt/valueos/tree/main/packages/integrations"
click node_mcp "https://github.com/valynt/valueos/tree/main/packages/mcp"
click node_memory "https://github.com/valynt/valueos/tree/main/packages/memory"
click node_supabase "https://github.com/valynt/valueos/tree/main/infra/supabase/supabase/migrations"
click node_redis "https://github.com/valynt/valueos/blob/main/infra/k8s/base/redis-streams.yaml"
click node_k8s "https://github.com/valynt/valueos/tree/main/infra/k8s"
click node_observability "https://github.com/valynt/valueos/tree/main/infra/observability"
click node_workers "https://github.com/valynt/valueos/tree/main/packages/backend/src/workers"
click node_api "https://github.com/valynt/valueos/tree/main/packages/backend/src/api"
click node_services "https://github.com/valynt/valueos/tree/main/packages/backend/src/services"
click node_runtime "https://github.com/valynt/valueos/tree/main/packages/backend/src/runtime"
click node_agentfabric "https://github.com/valynt/valueos/tree/main/packages/backend/src/lib/agent-fabric"
click node_valuegraph "https://github.com/valynt/valueos/tree/main/packages/backend/src/services/value-graph"

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_valyntapp,node_mcpdashboard toneBlue
class node_backend,node_sdui,node_components,node_shared,node_integrations,node_mcp,node_memory,node_workers,node_api,node_services,node_runtime,node_agentfabric,node_valuegraph toneAmber
class node_supabase,node_redis,node_k8s,node_observability toneMint
```

## Components

### Applications

Customer-facing and internal runtimes

- [ValyntApp](https://github.com/valynt/valueos/tree/main/apps/ValyntApp): react-vite frontend · Primary customer web app for value-engineering workflows · `apps/ValyntApp`
- [MCP Dashboard](https://github.com/valynt/valueos/tree/main/apps/mcp-dashboard): internal ops UI · Internal observability surface for MCP and protocol workflows · `apps/mcp-dashboard`

### Shared Packages

Reusable platform, UI, protocol, and domain packages

- [Backend](https://github.com/valynt/valueos/tree/main/packages/backend): express runtime · Central API and orchestration boundary · `packages/backend`
- [SDUI Engine](https://github.com/valynt/valueos/tree/main/packages/sdui): rendering engine · Server-driven UI schema, registry, hydration, and patching · `packages/sdui`
- [Design System](https://github.com/valynt/valueos/tree/main/packages/components/design-system/src): ui primitives · Shared presentation primitives used across apps · `packages/components/design-system/src`
- [Shared Domain](https://github.com/valynt/valueos/tree/main/packages/shared/src): common models · Cross-package domain types, contracts, and utilities · `packages/shared/src`
- [Integrations](https://github.com/valynt/valueos/tree/main/packages/integrations): external adapters · CRM and third-party system adapters · `packages/integrations`
- [MCP Packages](https://github.com/valynt/valueos/tree/main/packages/mcp): protocol adapters · Model Context Protocol CRM and ground-truth packages · `packages/mcp`
- [Memory](https://github.com/valynt/valueos/tree/main/packages/memory): context store · Shared memory, provenance, semantic, and lifecycle primitives · `packages/memory`
- [Workers](https://github.com/valynt/valueos/tree/main/packages/backend/src/workers): async jobs · Background job runtime for billing, CRM sync, artifacts, and watchdog tasks · `packages/backend/src/workers`
- [API Layer](https://github.com/valynt/valueos/tree/main/packages/backend/src/api): routes+trpc · REST, route handlers, and typed API entrypoints · `packages/backend/src/api`
- [Domain Services](https://github.com/valynt/valueos/tree/main/packages/backend/src/services): business orchestration · Value, workflow, trust, integrity, billing, auth, and integrations services · `packages/backend/src/services`
- [Runtime Core](https://github.com/valynt/valueos/tree/main/packages/backend/src/runtime): workflow runtime · Execution runtime, policy engine, adapters, and decision routing · `packages/backend/src/runtime`
- [Agent Fabric](https://github.com/valynt/valueos/tree/main/packages/backend/src/lib/agent-fabric): 11-agent system · Secure agent execution, prompt registry, routing, redaction, and circuit breakers · `packages/backend/src/lib/agent-fabric`
- [Value Graph](https://github.com/valynt/valueos/tree/main/packages/backend/src/services/value-graph): domain pipeline · Value-case, ROI, trust, integrity, and artifact pipeline · `packages/backend/src/services/value-graph`

### Platform

Infrastructure, database, observability, and operations

- [Supabase DB](https://github.com/valynt/valueos/tree/main/infra/supabase/supabase/migrations): postgres+auth · System of record with auth, RLS, and migrations · `infra/supabase/supabase/migrations`
- [Redis](https://github.com/valynt/valueos/blob/main/infra/k8s/base/redis-streams.yaml): cache+queues · Cache, rate limiting, sessions, and queue coordination · `infra/k8s/base/redis-streams.yaml`
- [K8s Runtime](https://github.com/valynt/valueos/tree/main/infra/k8s): deployment platform · Blue/green, HPA, network policy, and service orchestration · `infra/k8s`
- [Observability](https://github.com/valynt/valueos/tree/main/infra/observability): otel+metrics · Tracing, logging, alerting, and dashboards · `infra/observability`

## Connections

- ValyntApp → Backend: authenticated API calls · Customer UI reads and writes domain state through backend APIs
- ValyntApp → SDUI Engine: renders schemas · Client renders constrained server-driven UI output
- ValyntApp → Design System: shared UI · Uses shared design-system primitives and reusable surfaces
- MCP Dashboard → Backend: ops API · Internal dashboard consumes backend and MCP operational data
- Backend → API Layer: exposes · REST and typed entrypoints are surfaced through the API layer
- Backend → Domain Services: orchestrates · Business workflows and integrations are implemented in domain services
- Backend → Runtime Core: executes · Workflow execution and policy enforcement use runtime components
- Backend → Agent Fabric: runs agents · Agent invocation is mediated through the secure agent fabric
- Backend → Value Graph: value pipeline · Core value-case and graph workflows are handled here
- Backend → Workers: async jobs · Long-running and retryable jobs are offloaded to workers
- Backend → Supabase DB: persists state · Postgres/Supabase is the system of record
- Backend → Redis: cache and queues · Redis backs caching, sessions, rate limiting, and queues
- Domain Services → Value Graph: domain flow · Value modeling, trust, integrity, and artifacts are composed into the main pipeline
- Domain Services → Integrations: connectors · CRM and external systems are accessed through adapter packages
- Domain Services → MCP Packages: protocol bridge · MCP capabilities are exposed via dedicated protocol adapters
- Domain Services → Memory: shared context · Semantic and provenance memory support service reasoning
- Runtime Core → Supabase DB: RLS-backed state · Runtime reads and writes are validated against the database boundary
- Runtime Core → Redis: coordination · Execution coordination and transient workflow state use Redis
- Agent Fabric → Memory: context store · Agents consume and persist structured context and provenance
- Agent Fabric → Supabase DB: durable facts · Agent state and lineage are persisted in Postgres
- Workers → Redis: consumes queues · Workers process queued and streamed background tasks
- Workers → Supabase DB: job output · Completed jobs persist artifacts and workflow state to the database
- Supabase DB → Observability: audit signals · Database, auth, and RLS events surface into monitoring and audit flows
- K8s Runtime → Backend: deploys · Kubernetes runs the backend service and its replicas
- K8s Runtime → Workers: deploys · Worker processes are scheduled separately in the cluster
- K8s Runtime → MCP Dashboard: deploys · Internal dashboard is also hosted in the Kubernetes runtime
- Observability → Backend: watches · Tracing, metrics, and alerts cover API and service behavior
- Observability → Workers: watches · Background jobs are monitored through the same platform telemetry
