Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Architecture

dev-mondoshawan edited this page Apr 15, 2026 · 1 revision

System Architecture

This document describes the technical architecture of the Dissensus AI Debate Engine.


High-Level System Diagram

┌─────────────────────────────────────────────────────────────────────────┐
│ CLIENT BROWSER │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────────┐ │
│ │ CIPHER Column │ │ PRISM Column │ │ NOVA Column │ │
│ │ (Red/Skeptic) │ │ (Blue/Synthesizer)│ │ (Green/Advocate) │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────────────┘ │
│ ↑ EventSource (SSE) │
└───────────────────────────┼─────────────────────────────────────────────┘
 │
 ▼
┌─────────────────────────────────────────────────────────────────────────┐
│ NGINX (SSL/Reverse Proxy) │
│ - SSL termination │
│ - Static asset serving │
│ - Proxy to Node.js │
└───────────────────────────┬─────────────────────────────────────────────┘
 │
 ▼
┌─────────────────────────────────────────────────────────────────────────┐
│ NODE.JS / EXPRESS SERVER (:3000) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ Routes │ │ Debate │ │ Card │ │ Metrics │ │
│ │ /api/* │──│ Engine │──│ Generator │ │ Dashboard │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────────────────────────────────────────┐ │
│ │ Agents │ │ AI Provider APIs │ │
│ │ (CIPHER, │──│ ┌──────────┐ ┌──────────┐ ┌────────────────┐ │ │
│ │ NOVA, │ │ │ DeepSeek │ │ Gemini │ │ OpenAI │ │ │
│ │ PRISM) │ │ └──────────┘ └──────────┘ └────────────────┘ │ │
│ └─────────────┘ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘

Component Overview

Express Server (server/index.js)

The main application server built on Express.js:

Feature Implementation
Protocol HTTP with Server-Sent Events (SSE)
Port Configurable via PORT env var (default: 3000)
Security Helmet headers, rate limiting, input validation
Static Files Serves public/ directory

Key endpoints:

  • GET /api/debate/stream — SSE streaming debate endpoint
  • POST /api/debate/validate — Preflight validation
  • GET /api/providers — Available AI providers/models
  • GET /api/health — Health check
  • GET /api/metrics — Usage analytics
  • POST /api/card — Generate shareable debate cards

Debate Engine (server/debate-engine.js)

The core orchestration logic:

  • Multi-provider support — OpenAI, DeepSeek, Google Gemini
  • Streaming architecture — Real-time token delivery via SSE
  • 4-phase execution — Structured debate progression
  • Context accumulation — Each phase builds on prior context

Agent System (server/agents.js)

Personality definitions and system prompts for the three agents:

  • CIPHER — Skeptic/red-team prompts
  • NOVA — Advocate/optimist prompts
  • PRISM — Synthesizer/referee prompts with structured verdict format

Card Generator (server/card-generator.js)

Generates shareable PNG images of debate verdicts for social media sharing.

Metrics System (server/metrics.js)

In-memory analytics tracking:

  • Debate counts by provider
  • Recent topics
  • Error rates
  • Public dashboard at /metrics

Data Flow

1. Topic Validation

User submits topic
 ↓
POST /api/debate/validate
 ↓
├─ Check topic length (3-500 chars)
├─ Validate provider/model
└─ Verify API key (user or server)

2. SSE Stream Initialization

GET /api/debate/stream?topic=...&provider=...&model=...
 ↓
├─ Set SSE headers (text/event-stream)
├─ Apply rate limiting (10/min prod, 100/min dev)
└─ Initialize DebateEngine instance

3. 4-Phase Debate Execution

Phase 1: Independent Analysis
├─ All 3 agents run in parallel
├─ Each analyzes topic independently
└─ Results stored in debateContext.phase1
Phase 2: Opening Arguments
├─ Sequential execution (CIPHER → NOVA → PRISM)
├─ Each presents formal position
└─ Results stored in debateContext.phase2
Phase 3: Cross-Examination
├─ CIPHER challenges NOVA
├─ NOVA counters CIPHER
├─ PRISM challenges both
└─ Results stored in debateContext.phase3
Phase 4: Final Verdict
├─ CIPHER final statement
├─ NOVA final statement
├─ PRISM delivers definitive verdict
└─ Results stored in debateContext.phase4

4. Real-Time Streaming

Each agent response is streamed chunk-by-chunk:

// Server sends:
data: {"type":"agent-chunk","phase":1,"agent":"cipher","chunk":"The..."}
data: {"type":"agent-chunk","phase":1,"agent":"cipher","chunk":" primary..."}
data: {"type":"agent-done","phase":1,"agent":"cipher"}
// Client receives via EventSource:
es.addEventListener('message', (e) => {
 const data = JSON.parse(e.data);
 appendChunk(data.agent, data.chunk);
});

Frontend Architecture

Technology Stack

Layer Technology
Framework Vanilla JavaScript (no framework)
Styling Custom CSS with CSS variables
Streaming Native EventSource API
State In-memory JS objects
Storage localStorage for API keys

Layout Structure

┌─────────────────────────────────────────────────────────────┐
│ Header: Provider Selector | Model Selector | API Key Input │
├─────────────────────────────────────────────────────────────┤
│ Topic Input │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ CIPHER │ │ PRISM │ │ NOVA │ │
│ │ 🔴 Red │ │ 🔵 Blue │ │ 🟢 Green │ │
│ │ │ │ │ │ │ │
│ │ Skeptic │ │ Synthesizer │ │ Advocate │ │
│ │ Column │ │ Column │ │ Column │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Phase Indicator | Progress Bar | Share Button │
└─────────────────────────────────────────────────────────────┘

Key Files

File Purpose
public/index.html Main application shell
public/js/app.js Debate controller, EventSource handling
public/css/styles.css Cyberpunk theme, responsive layout
public/metrics.html Public analytics dashboard

Security Architecture

Helmet Headers

app.use(helmet({
 contentSecurityPolicy: false, // Allows inline event handlers
 crossOriginEmbedderPolicy: false
}));

Rate Limiting

Endpoint Production Development
/api/debate/stream 10/min 100/min
/api/card 20/min 100/min
/api/metrics 120/min 300/min

XSS Prevention

  • All user input sanitized via toString().trim()
  • No user content rendered as HTML
  • API keys never logged or stored server-side

API Key Handling

User API Key → Client-side only → Sent directly to AI provider
 ↓
Server Key (.env) → Server memory only → Used when user key absent

Server-side keys are never exposed to clients — only a boolean hasServerKey is sent.


Key Files Reference

File Description
server/index.js Express server, routes, SSE streaming
server/debate-engine.js 4-phase debate orchestration, provider configs
server/agents.js Agent personality definitions and system prompts
server/card-generator.js PNG card generation for social sharing
server/metrics.js In-memory analytics and dashboard data
server/debate-of-the-day.js Trending topic selection
public/index.html Main UI
public/js/app.js Frontend debate controller
public/css/styles.css Cyberpunk theme styles
package.json Dependencies and scripts

Deployment Architecture

VPS Deployment (Recommended)

Internet → Nginx (443) → Node.js (:3000)
 ↓
 Static assets
 SSL termination
 Rate limiting
 Reverse proxy

Environment Configuration

Environment TRUST_PROXY TRUST_PROXY_HOPS
VPS + Nginx unset (default) 1
Direct (no proxy) 0
Cloudflare unset 1-2

For deployment details, see the Getting Started guide and VPS-DEPLOY.md

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /