Architecture

System design, data flow, and component reference for the Liminal creative coding agent.

System Overview

5-layer architecture from user interface to infrastructure.

Layer 1: User Interface

CLI, Chat, Bubble Tea TUI

Entry points via bin/liminal, src/chat/, src/tui-bridge/.

Layer 2: Core Loop

RalphLoop, LLM Client

Generate → Evaluate → Iterate → Improve. Configurable model roles.

Layer 3: Intelligence

Brain, Compost, Evolution, Harness

Artistic knowledge, creative seeds, MAP-Elites, self-improvement.

Layer 4: Generators

12 launch creative domains

p5.js, SVG, GLSL, Three.js, Hydra, Strudel, Tone.js, Revideo, HyperFrames, ASCII, Kinetic, TextGen.

Layer 5: Infrastructure

Guardrails, Security, FS, Ledger

M1-M18 guardrails, SSRF protection, LiminalFS, task ledger.

Core Loop: RalphLoop

The iterative generation engine that drives all creative output.

Prompt → Brain (enhance) → LLM (generate) → Evaluator (score)
    ↑                                                      ↓
    ← Harness (detect stagnation, adapt strategy) ← Guardrails (validate)

Three Model Roles

RoleTemperaturePurpose
Generator0.7Creative code generation
Evaluator0.2Quality assessment and scoring
Harness0.5Pattern detection and repair

Roles configured in src/config/RoleConfig.ts. Provider detection via detectProviderFromUrl() in src/llm/MultiProviderConfig.ts.

LLM Client

Model-agnostic provider system with circuit breaker and failover.

Supported Providers

ProviderBase URLNotes
MiniMaxapi.minimax.io/anthropicPreferred cloud
OpenAIapi.openai.comFull support
Anthropicapi.anthropic.comFull support
Googlegenerativelanguage.googleapis.comGemini models
Ollamalocalhost:11434Local inference
OpenRouteropenrouter.aiMulti-model router
GLM / ZhipuAIapi.z.aiGLM models
Kimi Codeapi.kimi.com/codingK2P5 coding endpoint
Moonshot AIapi.moonshot.aiLegacy Kimi endpoint
Customlocalhost:8000/v1 or configured URLOpenAI-compatible endpoints

Circuit Breaker

Automatic failover chain: When a provider fails (timeout, auth error, network error), the system automatically falls back to the next provider in the role-specific chain. Each role (Generator, Evaluator, Harness) has its own fallback chain.

Provider adapters live in src/llm/providers/. The ProviderFactory resolves the correct adapter from baseUrl. The CapabilityRegistry maintains a static model→capabilities map for 30+ models.

Meta-Harness

Self-improving system that observes failures, detects patterns, and applies targeted fixes.

7 Harness Tools

ToolRate LimitPurpose
read_file10 reads/minRead source files for context
write_file10 writes/minApply code changes
build12 builds/minCompile and check for errors
test12 tests/minRun test suites
install_package5 installs/minAdd dependencies
run_script10 runs/minExecute arbitrary scripts
query_knowledge15 queries/minSearch internal knowledge base

Up to 3 retries per tool call. The LLM Mode Agent (src/harness/agent/LLMModeAgent.ts) orchestrates multi-step repair workflows using these tools. Safety: shell-free execFileSync in verifier, metacharacter guards.

Generator Architecture

12 launch generators unified under the TierBasedGenerator base class.

GeneratorDomainDirectoryStatus
p5.js2D Canvassrc/generators/p5/Stable
SVGVector Artsrc/generators/svg/Stable
GLSLShaderssrc/generators/glsl/Stable
Three.js3D Scenessrc/generators/three/Stable
StrudelLive Musicsrc/generators/strudel/Stable
HydraVisual Synthsrc/generators/hydra/Stable
Tone.jsWeb Audiosrc/generators/tone/Stable
RevideoVideosrc/generators/revideo/Active
HyperFramesHTML/GSAP Compositionsrc/generators/hyperframes/Active
ASCIITerminal Artsrc/generators/ascii/Stable
KineticMotion Artsrc/generators/kinetic/Active
TextGenGenerative Textsrc/generators/textgen/Stable
TierBasedGenerator: The launch generators inherit from a common base class that provides template scaffolding, evaluation integration, and model-tier awareness. This ensures consistent behavior across all 12 launch domains.

Guardrail System

18-type multi-layer safety system in src/guardrails/.

Core (M1-M8)

  • M1 Code Validation — Syntax and structure checks
  • M2 Type Safety — TypeScript type verification
  • M3 Test Verification — Test execution and pass/fail
  • M4 Schema Validation — Output schema compliance
  • M5 Resource Limits — Memory and CPU constraints
  • M6 Code Style — Linting and formatting
  • M7 Catastrophic Failure — Crash prevention
  • M8 Registry — Guardrail management and composition

Extended (M9-M11)

  • M9 Semantic Validator — Output relevance and coherence
  • M10 Runtime Health — Performance monitoring
  • M11 Accessibility — WCAG compliance checks

Compliance (M12-M18)

  • M12 Privacy — Data protection guardrails
  • M13 Fairness — Bias detection and prevention
  • M14 Supply Chain — Dependency validation
  • M15 Resilience — Graceful degradation
  • M16 Audit Trail — Operation logging
  • M17 Explainability — Decision transparency
  • M18 Injection Prevention — Prompt injection defense

Source structure: src/guardrails/{core,compliance,evolution,hygiene,correctness,validation,observation,remediation,rules}/ with standalone modules for AccessibilityGuardrails, RuntimeHealthMonitor, and SemanticValidator.

Data Flow

User Prompt
    ↓
Brain (src/brain/)
    → Artistic knowledge injection
    → Compost seed retrieval
    → Archive example selection
    ↓
RalphLoop (src/core/)
    → Enhanced prompt construction
    ↓
Generator (src/generators/*/)
    → Domain-specific code generation via LLM
    ↓
Evaluator (src/harness/)
    → Multi-dimensional quality scoring
    → 3-agent critique board (Minimalist / Expressionist / Technician)
    ↓
Guardrails (src/guardrails/)
    → M1-M18 validation pipeline
    → Aesthetic quality gate
    ↓
Output
    → Code file + evaluation report
    → Compost seed (if quality threshold met)
    → Archive entry (if novel)

File Structure

48 subsystems in src/.

src/
├── core/               Loop engine, validation, domain detection
├── llm/                LLM client, provider adapters, circuit breaker
├── config/             Configuration loading, role-based model selection
├── types/              Shared TypeScript types
├── constants/          Project-wide constants
├── errors/             Error types and handling
├── utils/              Utility functions
│
├── generators/         11 domain generators (p5, glsl, three, strudel, ...)
│
├── harness/            Meta-harness: failure logging, pattern detection, agent
├── guardrails/         M1-M18 multi-layer guardrail system
├── security/           SSRF protection, rate limiting, sandbox
├── sandbox/            Code execution sandbox
│
├── brain/              Artistic knowledge, prompt enhancement
├── compost/            Compost Mill pipeline (digest, collide, score, promote)
├── evolution/          MAP-Elites, novelty archive, cross-domain crossover
├── embeddings/         Local SBERT embedding service
├── intuition/          Thompson Sampling, domain prototypes
├── learning/           Meta-learning and improvement tracking
│
├── audio/              Audio analysis, pitch detection, visual mapping
├── music/              Theory engine, Euclidean rhythms, Markov chains
├── musicToVisual/      Audio-to-visual parameter mapping
│
├── aesthetic/          Color theory, design tiers, multi-critic evaluation
├── calibration/        Aesthetic calibration and scoring
│
├── tui/                Terminal UI (NaturalInterface, routing)
├── tui-bridge/         HTTP/SSE bridge for Bubble Tea runtime
├── chat/               Interview-driven creative sessions
├── gui/                Web GUI (Express server)
│
├── collab/             Multi-agent board, swarm coordination
├── swarm/              Swarm generation strategies
├── routing/            Dual-model routing (fast + powerful)
│
├── fs/                 LiminalFS: ProjectStore, EventStore, AssetStore
├── ledger/             Task corpus, runner, verifier
├── render/             Rendering pipeline
├── export/             Output format conversion
├── gallery/            Sketch gallery management
├── fix/                Auto-fix with LLM
├── quality/            Quality metrics and tracking
│
├── plugins/            Plugin system
├── composite/          Composite generation
├── composition/        Composition API
│
├── prompts/            Prompt templates and libraries
├── nodeprompt/         Node-based prompt construction
├── runtime-core/       Runtime environment management
├── ui/                 Shared UI components
├── improvement/        Self-improvement tracking
├── entropy/            Entropy-based diversity measures
├── scavenger/          Scavenger agent for resource recovery
└── git/                Git integration utilities