Vitruvyan
Docs
Planning

Vitruvyan Docs

VITRUVYAN CORE V1.0 — STATE OF THE ART

Date: 2026-02-15T23:45Z (February 15, 2026 — 23:45 UTC)
Release Readiness Score: 97.5% (target 90%)
Purpose: Canonical reference document for AI analysis of the Vitruvyan Core codebase
Certification: Final Closure Certification PASSED (5/5 sections) — see V1_FINAL_CLOSURE_CERTIFICATION_FEB15_2026.md


1. MISSION

Vitruvyan Core is a domain-agnostic epistemic operating system that provides:

  • A governed cognitive pipeline (LangGraph orchestration, Sacred Orders)
  • Pluggable domain verticals via configuration and runtime plugins
  • A solid, secure, scalable framework that never embeds domain-specific assumptions

The core must remain pure infrastructure — any domain (finance, healthcare, legal, research) plugs in through:

  1. domains/<domain>/ — intent config, prompts, slot definitions
  2. contracts/ — ABCs, protocols, base state (the extensibility surface)
  3. Environment variables — all operational tuning without code changes

2. ARCHITECTURE OVERVIEW

2.1 Repository Layout

vitruvyan_core/
├── core/
│   ├── agents/               # Singleton gateways to external systems
│   │   ├── postgres_agent.py     # PostgreSQL (ThreadedConnectionPool)
│   │   ├── qdrant_agent.py       # Qdrant vector DB
│   │   ├── llm_agent.py          # LLM gateway (OpenAI, pluggable via ILLMProvider)
│   │   └── alchemist_agent.py    # Schema migrations (Alembic)
│   ├── cache/
│   │   └── mnemosyne_cache.py    # Multi-tier vector-aware cache (Redis SCAN)
│   ├── cognitive/                # Perception Sacred Orders
│   │   ├── babel_gardens/            # Language detection, NLU, translation
│   │   └── pattern_weavers/          # Ontology mapping, pattern classification
│   ├── contracts/                # PUBLIC EXTENSIBILITY SURFACE
│   │   ├── __init__.py               # Single import point for all ABCs/protocols
│   │   └── llm_provider.py           # ILLMProvider — runtime_checkable Protocol
│   ├── governance/               # Governance Sacred Orders
│   │   ├── codex_hunters/            # System discovery, maintenance
│   │   ├── memory_orders/            # Coherence analysis, RAG
│   │   ├── orthodoxy_wardens/        # Validation, audit, invariant enforcement
│   │   └── vault_keepers/            # Archival, persistence, snapshots
│   ├── llm/
│   │   ├── cache_api.py              # LLM response caching + cost tracking
│   │   ├── cache_manager.py          # Redis-backed LLM cache (SCAN-only)
│   │   └── prompts/                  # PromptRegistry (domain-aware)
│   ├── logging/
│   │   └── audit.py                  # Structured audit logger (Redis Stream + optional PG)
│   ├── middleware/
│   │   └── auth.py                   # Opt-in AuthMiddleware (Bearer token)
│   ├── neural_engine/            # Computation engine (batch scoring)
│   ├── orchestration/            # LangGraph pipeline + plugin system
│   │   ├── base_state.py             # BaseGraphState (37 fields, extensible)
│   │   ├── execution_guard.py        # Hard timeout enforcement (ThreadPoolExecutor)
│   │   ├── graph_engine.py           # GraphPlugin, NodeContract, GraphEngine
│   │   ├── parser.py                 # Parser ABC, BaseParser, ParsedSlots
│   │   ├── intent_registry.py        # IntentRegistry (domain plugin pattern)
│   │   ├── route_registry.py         # Route definitions
│   │   ├── entity_resolver_registry.py
│   │   ├── execution_registry.py
│   │   └── langgraph/                # Graph nodes, runner, flow
│   │       ├── graph_runner.py           # Entry point (lazy init)
│   │       ├── graph_flow.py             # Pipeline wiring
│   │       └── node/                     # 15+ cognitive nodes
│   ├── synaptic_conclave/        # Cognitive Bus (Redis Streams)
│   │   ├── transport/
│   │   │   ├── streams.py                # StreamBus (TLS, password, env-configured)
│   │   │   └── dlq.py                    # Dead Letter Queue (retry tracking, idempotency)
│   │   ├── events/                   # TransportEvent, CognitiveEvent, EventAdapter
│   │   ├── plasticity/               # Adaptive learning
│   │   └── governance/               # Bus-level governance
│   └── vpar/                     # Vitruvyan Probabilistic Assessment
├── domains/
│   ├── finance/                  # Reference vertical (intent_config, prompts, slots)
│   ├── energy/                   # Test vertical (grid, renewables) — V1.0 certification
│   ├── facility/                 # Test vertical (building mgmt) — V1.0 certification
│   ├── dummy_test/               # Minimal test vertical — V1.0 certification
│   ├── base_domain.py            # Domain ABC
│   ├── aggregation_contract.py
│   ├── explainability_contract.py
│   └── risk_contract.py
services/                         # 12 FastAPI microservices (LIVELLO 2)
├── api_graph/                    # LangGraph orchestration service
├── api_babel_gardens/            # NLU service
├── api_codex_hunters/            # System maintenance service
├── api_memory_orders/            # Coherence + RAG service
├── api_orthodoxy_wardens/        # Governance service
├── api_pattern_weavers/          # Ontology service
├── api_vault_keepers/            # Archival service
├── api_neural_engine/            # Computation service
├── api_embedding/                # Vector embedding service
├── api_conclave/                 # Bus management service
├── api_mcp/                      # Model Context Protocol service
└── redis_streams_exporter/       # Prometheus metrics exporter

2.2 Sacred Orders (Epistemic Hierarchy)

OrderDomainLocationResponsibility
Babel GardensPerceptioncore/cognitive/babel_gardens/Language detection, NLU, translation
Pattern WeaversPerceptioncore/cognitive/pattern_weavers/Ontology mapping, pattern classification
Codex HuntersPerceptioncore/governance/codex_hunters/System discovery, codebase maintenance
Memory OrdersMemorycore/governance/memory_orders/Coherence analysis, RAG, semantic state
Vault KeepersMemorycore/governance/vault_keepers/Archival, persistence, snapshots
Orthodoxy WardensTruthcore/governance/orthodoxy_wardens/Validation, audit, invariant enforcement

Each Sacred Order follows the mandatory two-level pattern:

  • LIVELLO 1 (pure domain): 10 directories, zero I/O, pure Python, testable standalone
  • LIVELLO 2 (service): FastAPI, Docker, adapters, main.py < 100 lines

2.3 LangGraph Pipeline (Cognitive Kernel)

parse → intent_detection → weaver → entity_resolver → babel_emotion
  → semantic_grounding → params_extraction → decide → [route branches]
  → output_normalizer → orthodoxy → vault → compose → can → [advisor] → END

Route branches from decide node:

  • dispatcher_exec → direct execution
  • semantic_fallback → Qdrant vector search
  • llm_soft → conversational LLM (cached)
  • slot_filler → missing parameter negotiation
  • codex_expedition → system maintenance
  • llm_mcp → MCP tools (when USE_MCP=1)

Intent detection is 100% domain-agnostic: domains register via INTENT_DOMAIN env var and domains/<domain>/intent_config.py.


3. EXTENSIBILITY CONTRACTS

3.1 Plugin Surface (contracts/)

from contracts import (
    # Graph state
    BaseGraphState, GraphStateType,
    ESSENTIAL_FIELDS, INTENT_FIELDS, LANGUAGE_FIELDS, EMOTION_FIELDS,
    ORTHODOXY_FIELDS, VAULT_FIELDS, TRACING_FIELDS, WEAVER_FIELDS,
    CAN_FIELDS, ALL_BASE_FIELDS,
    get_base_field_count, is_base_field, get_domain_fields,
    # Engine
    GraphPlugin, NodeContract, GraphEngine,
    # Parser
    Parser, BaseParser, ParsedSlots,
    # LLM
    ILLMProvider,
)

3.2 How a Domain Vertical Plugs In

  1. Intent detection: Create domains/<domain>/intent_config.py with create_<domain>_registry(). Set INTENT_DOMAIN=<domain>.
  2. Prompts: Register domain prompts via PromptRegistry.register_domain() in core/llm/prompts/registry.py.
  3. Graph state: Extend BaseGraphState with domain-specific fields — the core's 37 fields are inherited automatically.
  4. LLM provider: Implement ILLMProvider protocol (5 methods: complete, complete_json, complete_with_messages, complete_with_tools, acomplete) to swap OpenAI for any provider.
  5. Entities: Define domain entities that flow through validated_entities contract.

3.3 Domain-Agnostic Guarantees

  • No finance/trading terms in core code (legacy remnants fully purged from active code paths)
  • Intent detection, emotion detection, entity extraction all delegate to LLM as primary engine (regex fallback only)
  • domains/finance/ exists as reference implementation, zero imports from core into it
  • Multi-vertical proven: 4 domains (finance, energy, facility, dummy_test) load dynamically via importlib, with 0 naming collisions and full config isolation

4. SECURITY POSTURE

4.1 Credentials & Secrets

AspectStatus
No passwords in source code✅ All via ${ENV_VARS}
No production IPs in code✅ Removed from all configs and docs
.env files gitignored.env.example templates provided
docker-compose.yml✅ All secrets from env vars, no defaults
Git history⚠️ BFG purge deferred to pre-public release

4.2 Authentication

  • Middleware: core/middleware/auth.py — opt-in AuthMiddleware
  • Activation: VITRUVYAN_AUTH_ENABLED=true + VITRUVYAN_AUTH_SECRET or VITRUVYAN_KEYCLOAK_URL
  • Coverage: All 11 FastAPI services have middleware integrated
  • Default: Disabled (zero overhead) — enables gradual rollout
  • Features: Bearer token validation, configurable public paths, CORS preflight passthrough, custom validator injection
  • Tests: 14 unit tests in tests/test_auth_middleware.py

4.3 Transport Security

ClientTLS SupportPassword Support
StreamBus (streams.py)REDIS_SSLREDIS_PASSWORD
MnemosyneCache (mnemosyne_cache.py)REDIS_SSLREDIS_PASSWORD
LLMCacheManager (cache_manager.py)REDIS_SSLREDIS_PASSWORD
WorkingMemory (working_memory.py)REDIS_SSLREDIS_PASSWORD

4.4 Audit Logging

  • Module: core/logging/audit.py — structured AuditLogger with mandatory schema
  • Backends: Python logger (always) + Redis Stream (default) + PostgreSQL (optional)
  • Stream: vitruvyan:audit (configurable via AUDIT_STREAM, max length AUDIT_STREAM_MAX_LEN)
  • Schema: AuditEvent dataclass — timestamp, event_id, correlation_id, node_id, plugin_id, execution_time_ms, status, error_code, metadata
  • Control: AUDIT_ENABLED=true (default on), AUDIT_POSTGRES_ENABLED=false (opt-in)
  • Emitted automatically on pipeline timeout by graph_runner.py

4.5 Configuration Hygiene

  • Zero load_dotenv() in all production code — core and services
  • Removed from all service entrypoints during hardening + final certification
  • Prevents .env files from silently overriding production environment variables

4.6 CORS

  • All 11 FastAPI services have CORSMiddleware configured
  • Default: http://localhost:3000 (restrictive)
  • Configurable via CORS_ORIGINS env var (comma-separated)

5. SCALABILITY

5.1 PostgreSQL

FeatureImplementation
Connection poolingpsycopg2.pool.ThreadedConnectionPool (env vars: POSTGRES_POOL_MIN=2, POSTGRES_POOL_MAX=10)
Paginated queriesfetch_paginated(sql, params, page_size=500) — server-side cursor, yields pages
Connection reuseShared pool via _get_pool() singleton — no connection-per-call overhead

5.2 Redis

FeatureImplementation
No blocking KEYS callsAll Redis clients use SCAN/scan_iter() — zero KEYS in production code
Stream retentionSTREAM_MAX_LEN (default 100K), STREAM_MAX_AGE_DAYS (default 7)
Cache prefixMNEMOSYNE_CACHE_PREFIX env var (default vitruvyan:mnemosyne_cache)
Stream prefixSTREAM_PREFIX env var (default vitruvyan)
Dead Letter Queuevitruvyan:dlq stream — failed events isolated, retry-tracked, idempotent

KEYS residual: only scripts/audit_streams_topology.py (CLI tool) and test fixtures — non-production.

5.3 LangGraph

FeatureImplementation
Lazy graph compilation_get_graph() — builds on first call, not at import time
Minimal graph modeENABLE_MINIMAL_GRAPH=true — 4-node graph for lightweight deployments

5.4 LLM Rate Control

ParameterEnv VarDefault
Requests per minuteLLM_RATE_LIMIT_RPM500
Tokens per minuteLLM_RATE_LIMIT_TPM30000
Cost per tokenLLM_COST_PER_TOKEN0.0001
Model selectionVITRUVYAN_LLM_MODELGRAPH_LLM_MODELOPENAI_MODELgpt-4o-mini

5.5 Resilience & Fault Tolerance

FeatureImplementation
Hard timeout enforcementNodeExecutionGuardThreadPoolExecutor with Future.result(timeout=N) kills hanging nodes
Pipeline timeoutgraph_runner.py wraps invoke() with GRAPH_EXEC_TIMEOUT_SECONDS (default 120s)
Dead Letter QueueDeadLetterQueue in transport/dlq.py — failed events tracked with retry count, moved to vitruvyan:dlq after DLQ_MAX_RETRIES exhausted
IdempotencyDLQ uses SHA256-based idempotency keys (7-day TTL) — prevents duplicate DLQ entries
Trace ID collision safetygraph_runner.py uses full UUID4 (36 chars) instead of truncated 8-char prefix
Audit trailAuditLogger emits structured events on timeout/failure to Redis Stream + optional PostgreSQL

6. CONFIGURATION REFERENCE

All operational values are configurable via environment variables. No code changes required for tuning.

6.1 Infrastructure

Env VarPurposeDefault
POSTGRES_HOSTPostgreSQL hostnamecore_postgres
POSTGRES_PORTPostgreSQL port5432
POSTGRES_DBDatabase namevitruvyan
POSTGRES_USERDatabase user(required)
POSTGRES_PASSWORDDatabase password(required)
POSTGRES_POOL_MINMin pool connections2
POSTGRES_POOL_MAXMax pool connections10
REDIS_HOSTRedis hostnamecore_redis
REDIS_PORTRedis port6379
REDIS_SSLEnable TLSfalse
REDIS_PASSWORDRedis password(empty)
QDRANT_HOSTQdrant hostnamecore_qdrant
QDRANT_PORTQdrant port6333
QDRANT_TIMEOUTQdrant timeout seconds30

6.2 LLM & AI

Env VarPurposeDefault
VITRUVYAN_LLM_MODELPrimary model selector(falls through chain)
GRAPH_LLM_MODELGraph-specific model(falls through)
OPENAI_MODELOpenAI modelgpt-4o-mini
OPENAI_API_KEYAPI key(required)
LLM_RATE_LIMIT_RPMRequests/minute limit500
LLM_RATE_LIMIT_TPMTokens/minute limit30000
LLM_COST_PER_TOKENCost tracking rate0.0001

6.3 Cognitive Bus (Synaptic Conclave)

Env VarPurposeDefault
STREAM_MAX_LENMax entries per stream100000
STREAM_MAX_AGE_DAYSStream retention in days7
STREAM_PREFIXStream name prefixvitruvyan
MNEMOSYNE_CACHE_PREFIXCache key prefixvitruvyan:mnemosyne_cache

6.4 Orchestration

Env VarPurposeDefault
INTENT_DOMAINDomain plugin for intent detectiongeneric
QDRANT_FILTER_DOMAINEnable domain-specific Qdrant filtering1
USE_MCPRoute to MCP node0
ENABLE_MINIMAL_GRAPHUse 4-node minimal graphfalse
DISABLE_SLOT_FILLINGSkip slot-filling dialogue(not set = active)

6.5 Security

Env VarPurposeDefault
VITRUVYAN_AUTH_ENABLEDEnable auth middlewarefalse
VITRUVYAN_AUTH_SECRETJWT secret for local validation(required if auth enabled)
VITRUVYAN_KEYCLOAK_URLKeycloak endpoint(optional)
CORS_ORIGINSAllowed CORS origins (comma-separated)http://localhost:3000

6.6 Execution Control

Env VarPurposeDefault
NODE_EXEC_TIMEOUT_SECONDSPer-node hard timeout30
NODE_EXEC_MAX_WORKERSThreadPoolExecutor max workers4
GRAPH_EXEC_TIMEOUT_SECONDSFull pipeline timeout120

6.7 Dead Letter Queue

Env VarPurposeDefault
DLQ_MAX_RETRIESRetries before DLQ routing3
DLQ_STREAM_MAX_LENMax DLQ stream entries50000

6.8 Audit Logging

Env VarPurposeDefault
AUDIT_ENABLEDEnable/disable audit loggingtrue
AUDIT_STREAMRedis audit stream namevitruvyan:audit
AUDIT_STREAM_MAX_LENMax audit stream entries200000
AUDIT_POSTGRES_ENABLEDAlso persist audit to PostgreSQLfalse
AUDIT_LOG_LEVELPython log level for audit eventsINFO

7. SERVICES MATRIX

All services follow the SERVICE_PATTERN.md convention: main.py < 100 lines, adapters/, api/routes.py, config.py.

ServicePortSacred OrderAuthCORSLifespan
api_graph8000Orchestration
api_babel_gardens8009Babel Gardens
api_pattern_weavers8011Pattern Weavers
api_codex_hunters8008Codex Hunters
api_memory_orders8012Memory Orders
api_vault_keepers8013Vault Keepers
api_orthodoxy_wardens8014Orthodoxy Wardens
api_neural_engine8001Computation
api_embedding8010Vector ops
api_conclave8015Bus management
api_mcp8020MCP tools
redis_streams_exporter9091Monitoring

8. SACRED ORDERS CONFORMANCE

Sacred OrderLIVELLO 1LIVELLO 2ConformanceNotes
Babel Gardens✅ 10/10 dirs✅ main.py < 100L95%Missing _legacy/ dir (no legacy code to archive)
Pattern Weavers✅ 10/10 dirs✅ main.py < 100L95%Missing _legacy/ dir (no legacy code to archive)
Codex Hunters✅ 10/10 dirs✅ main.py < 100L93%yaml import in consumers (data-driven config)
Vault Keepers✅ 10/10 dirs✅ main.py < 100L90%MetricNames defined
Memory Orders✅ 10/10 dirs✅ main.py < 100L90%Legacy tests archived
Orthodoxy Wardens✅ 10/10 dirs✅ main.py < 100L85%Impure agents archived to _legacy/

All 6 Sacred Orders have complete LIVELLO 2 service implementations with adapters, routes, and models.


9. INVARIANTS (NON-NEGOTIABLE RULES)

These rules are enforced across the codebase and must be preserved by any future work:

  1. Core stays generic — no domain logic in vitruvyan_core/core/. Domains plug in via domains/ and contracts/.
  2. No cross-service imports — services communicate via REST or StreamBus events only.
  3. Agents for all external accessPostgresAgent, QdrantAgent, LLMAgent only. No raw psycopg2.connect(), qdrant_client.QdrantClient(), or from openai import OpenAI.
  4. No secrets in source — all credentials via env vars with ${PLACEHOLDER} in docs.
  5. Streams, not Pub/Sub — Redis Streams is canonical transport. Acknowledge after handling. Generator consumption.
  6. Bus is payload-blind — transport layer never inspects, routes, or correlates event content.
  7. Validated lists are authoritative — if client sends validated_entities, backend respects it (including explicit []).
  8. LLM-first, never heuristics-first — intent, emotion, entity extraction delegate to LLM. Regex is only fallback.
  9. No load_dotenv() anywhere — configuration exclusively via environment variables. Zero load_dotenv() calls in core and services.
  10. Failed events to DLQ — events exceeding DLQ_MAX_RETRIES must be routed to the Dead Letter Queue, not left in PEL indefinitely.

10. TESTING

Test SuiteCountStatus
Architectural tests (tests/architectural/)165✅ All passing
Orchestration base class tests19✅ All passing (core-only)
Finance vertical tests (tests/verticals/)12✅ All passing (guarded with importorskip)
Hardening tests (tests/test_hardening_fixes.py)29✅ All passing
Auth middleware tests14✅ All passing
Skipped (infrastructure-dependent)12Expected (need Docker)

Final Closure Certification (5 sections, all passed):

  • S1 Structural: 256 files AST-scanned, 0 import violations
  • S2 Performance: Neural Engine O(n) scaling, 24K entities/sec, no memory leaks
  • S3 Concurrency: 50 concurrent pipelines, fault injection, no deadlocks
  • S4 Multi-Vertical: 4 domains loaded dynamically, 0 collisions
  • S5 Security: 642 files secret-scanned, 8/8 cold boot imports, 0 load_dotenv()

Full report: docs/planning/V1_FINAL_CLOSURE_CERTIFICATION_FEB15_2026.md

Hardening test breakdown (29 tests, 6 classes):

  • TestNodeExecutionGuard — 7 tests (success, timeout, exception, per-call override, env config, singleton, state preservation)
  • TestDeadLetterQueue — 8 tests (retry tracking, DLQ routing, idempotency, serialization, listing, health, ACK)
  • TestRedisKeysElimination — 2 tests (source code scan verifying scan_iter usage)
  • TestAuditLogger — 9 tests (schema, error codes, JSON serialization, Redis fields, backends, disable, singleton, metadata)
  • TestLoadDotenvRemoval — 2 tests (source code scan verifying no load_dotenv in core)
  • TestTraceIdFullLength — 1 test (full UUID4 = 36 chars)

11. KNOWN RESIDUAL ITEMS (Low Priority, Non-Blocking)

These items are documented for completeness. None block V1.0 release.

ItemLocationImpact
acomplete() not truly asyncllm_agent.py L540Minor — wraps sync in thread
httpx I/O in LIVELLO 1vsgs_engine.py L93-101Minor — edge case module
logging.basicConfig() in library modulevault_node.py L22Cosmetic
nest_asyncio.apply() globalllm_mcp_node.py L24Pragmatic (MCP requirement)
foundation/ empty subdirectories3 dead scaffolding dirsCosmetic
__all__ duplicated exportssynaptic_conclave/__init__.pyCosmetic
Qdrant top_k cap 50 hard-codedqdrant_agent.py L131Minor
Qdrant default collection namesqdrant_agent.py L153, L241, L323Minor
Alembic path hard-codedalchemist_agent.py L30Minor
BFG git history purgePre-public release taskDeferred
redis_streams_exporter no authMonitoring endpointP3

12. RELEASE READINESS SCORE

CriterionScoreDescription
Domain-Agnostic98%Core fully agnostic; 0 hard imports core→finance. Finance tests isolated in tests/verticals/ with importorskip. Babel plugin imports conditional. 4 verticals proven (finance, energy, facility, dummy_test). Residual: cosmetic docstring mentions.
No Hard-Coded98%All via env vars. Zero load_dotenv() in core AND services. Residual: 3 Qdrant collection defaults.
Security94%Auth middleware, Redis TLS/password, CORS, structured audit logging. Residual: git history purge.
Scalability96%Pooling, SCAN (complete), lazy init, execution guard, DLQ, trace ID collision-safe. Residual: async LLM.
Plugin-Ready97%contracts/, ILLMProvider, BaseGraphState, IntentRegistry, PromptRegistry.
TOTAL97.5%RELEASE READY — Final Closure Certified

13. COMMIT HISTORY (Remediation Arc)

CommitPhaseDescriptionFilesDelta
eae8c0eFASE 0Security emergency (passwords, IPs, CORS, .env)31Critical fixes
a16ff1fFASE 1Domain-agnostic core (~90 violations resolved)~45+/- extensive
c11f0a0FASE 2Sacred Orders cleanup (legacy archival, imports)13Structural
b1c8870FASE 5Quality & Polish (contracts, BaseGraphState, logging)34+444/-310
4ddf0e9FASE 3Security infrastructure (Redis TLS, auth, CORS, hostnames)25+510/-70
dc5c1b9FASE 4Scalability (pooling, SCAN, lazy init, env vars, ILLMProvider)9+286/-77
5e214ebHARDENINGExecution guard, DLQ, KEYS→SCAN, audit logging, load_dotenv removal17+1421/-31
b61d848COUPLINGFinance test isolation (tests/verticals/), babel plugin conditional imports8+384/-250
26f4a95CERTIFICATIONV1.0 structural certification — PASS (5 criteria verified)1+254
743a54dFINAL CERTFinal Closure Certification — ALL 5 SECTIONS PASSED (S1-S5)8+399/-3

Score progression: 79% → 96% (remediation) → 97% (hardening) → 97.5% (final closure).

All phases completed (0, 1, 2, 3, 4, 5) + Hardening + Coupling + Structural Cert + Final Closure Certification.