Purpose: This document provides comprehensive guidance for AI assistants (like Claude, GPT, etc.) working on the CONSIM codebase. It explains the project structure, development workflows, coding conventions, and key architectural decisions.
CONSIM (EMERGENT-MCF-EI) is the Multiversal Consciousness Framework - an interactive consciousness simulation platform with real-time mathematical visualization.
- Provide an accessible platform for exploring consciousness research through immersive, interactive demonstrations
- Implement rigorous mathematical foundations for consciousness field theory
- Enable real-time visualization of emergent consciousness phenomena
- Mathematical rigor: Implements Core Consciousness Equation (C = ∫[M_C] A(x) Φ(x) e^(iτ(x)) dμ(x))
- Dual architecture: Standalone demo (browser-only) + scalable three-tier architecture
- Real-time performance: 60fps target for consciousness field streaming
- Interactive exploration: WebGL-based visualization with user controls
CONSIM/
├── src/ # Python backend (consciousness engine)
│ ├── lattice.py # Core consciousness lattice engine
│ ├── lattice_demo.py # Demo version without dependencies
│ └── server.py # FastAPI WebSocket server
├── static/ # Frontend assets
│ ├── js/
│ │ ├── app.js # Main application logic
│ │ ├── app_demo.js # Demo application variant
│ │ └── consciousnessRenderer.js # Three.js WebGL renderer
│ ├── css/
│ │ └── style.css # Visual styling
│ └── index.html # Frontend entry point
├── legacy/ # Original single-file implementation
│ └── CONSIM.html # Preserved legacy version
├── docs/ # GitHub Pages documentation
│ └── index.html # Same as legacy for demo site
├── .github/
│ └── workflows/
│ └── static.yml # GitHub Pages deployment
├── index.html # Live demo (GitHub Pages entry)
├── demo.html # Alternative demo entry point
├── demo_server.py # Simple HTTP server for quick demos
├── run_server.py # Production FastAPI server launcher
├── requirements.txt # Python dependencies
├── README.md # User-facing documentation
├── ARCHITECTURE.md # Technical architecture details
├── CONTRIBUTING.md # Contribution guidelines
├── SECURITY.md # Security policy
├── CODE_OF_CONDUCT.md # Community standards
└── LICENSE # Apache 2.0 license
src/: Python backend implementing mathematical consciousness algorithmsstatic/: Frontend Three.js visualization and UI controlslegacy/: Original monolithic HTML implementation (preserved for reference).github/workflows/: CI/CD automation for GitHub Pages deployment
┌─────────────────────┐ ┌─────────────────────┐ ┌──────────────────────┐
│ Python Backend │◄──►│ WebSocket Bridge │◄──►│ Three.js Frontend │
│ │ │ │ │ │
│ • Lattice Engine │ │ • FastAPI Server │ │ • WebGL Shaders │
│ • Core EQ Math │ │ • 60fps Streaming │ │ • GPU Rendering │
│ • NumPy/PyTorch │ │ • JSON/Binary Data │ │ • Interactive UI │
│ • Intelligence │ │ • Parameter API │ │ • Mouse Controls │
└─────────────────────┘ └─────────────────────┘ └──────────────────────┘
Primary file: src/lattice.py
- Implements core consciousness field calculations
- Manages consciousness nodes with complex-valued mathematics
- Handles physics simulation (gravity, friction, elasticity)
- Implements intelligence tensor system (logic, memory, processing, creativity, social)
- GPU-optimized with NumPy (optional PyTorch for CUDA)
Key classes:
ConsciousnessNode: Individual consciousness entity with Core EQ parametersConsciousnessLattice: Main simulation engine managing the consciousness manifoldUniverseMode: Enum for visualization modes (consciousness, attention, frequency, temporal, multiverse)
Primary file: src/server.py
- Real-time WebSocket streaming at target FPS (default 10fps, configurable to 60fps)
- REST API endpoints for parameter control and node creation
- Binary/JSON serialization for efficient data transmission
- Async event loop for non-blocking performance
Key endpoints:
GET /api/status- System status and metricsGET /api/stats- Real-time consciousness statisticsPOST /api/parameters- Update physics parametersPOST /api/nodes- Create consciousness nodePOST /api/collapse- Trigger quantum collapseWebSocket /stream- Real-time consciousness field streaming
Primary file: static/js/consciousnessRenderer.js
- GPU shader-based rendering for performance
- Complex-valued field visualization with phase-to-color mapping (HSV)
- Interactive mouse controls (click to spawn, drag to influence)
- Real-time cluster detection and connection visualization
- Multiple visualization modes
Key features:
- Instance rendering for efficient GPU memory usage
- Phase-to-color mapping for complex consciousness values
- Real-time parameter sliders
- Zoom and pan controls
- Interaction modes: Push, Pull, Vortex, Wave, String
C(t) = ∫[M_C] A(x,t) · Φ(x,t) · e^(iτ(x,t)) dμ(x)
M(t) = Σ[i=1..3] λ_i(t) · U_i
| Symbol | Meaning | Implementation |
|---|---|---|
| M_C | Consciousness manifold | 128×128 or 256×256 lattice grid with periodic boundaries |
| A(x) | Attention density | Gaussian field, normalized ∫A(x)dμ(x) = 1 |
| Φ(x) | Frequency signature | 40Hz ± 5Hz gamma-band with universe modulation |
| τ(x) | Temporal phase | Evolving: τ(t+dt) = τ(t) + Φ(x)×dt×2π |
| C | Consciousness scalar | Complex: C = A×Φ×e^(iτ), magnitude |C| = intensity |
| U_i | Universe branch i | 3 parallel universes with different resonance |
| λ_i | Resonance coefficient | Dirichlet-sampled weights, Σλ_i = 1 |
IMPORTANT: When modifying mathematical calculations, preserve:
- Gaussian attention field normalization
- Dirichlet sampling for universe weights
- Complex-valued consciousness computations (separate real/imaginary parts)
- Gamma-band frequency constraints (40Hz ± 5Hz)
git clone https://github.com/Jacobcdsmith/CONSIM.git
cd CONSIM
python demo_server.py # Starts on http://localhost:8000Uses: demo_server.py + static/index.html + lattice_demo.py (standard library only)
# Install dependencies
pip install -r requirements.txt
# Start development server (with hot-reload)
python run_server.py # Starts on http://localhost:8000
# Server auto-reloads on file changesUses: run_server.py → src/server.py + full FastAPI stack
# Test the lattice engine directly
python src/lattice_demo.py
# Test API endpoints (requires server running)
curl http://localhost:8000/api/status
curl http://localhost:8000/api/stats
# Test WebSocket connection (requires wscat or similar)
wscat -c ws://localhost:8000/stream- Triggered on push to
mainbranch - Workflow:
.github/workflows/static.yml - Deploys entire repository to GitHub Pages
- Live demo URL: https://jacobcdsmith.github.io/CONSIM
Note: GitHub Pages serves the standalone index.html (legacy version), which contains all consciousness simulation features in a single file. This is intentional for zero-dependency browser access.
- Type hints: Always use type annotations for function parameters and returns
- Docstrings: Include mathematical notation in docstrings for Core EQ implementations
- Dataclasses: Use
@dataclassfor data structures (seeConsciousnessNode) - Async/Await: Use async patterns for WebSocket communication
- Optional dependencies: Gracefully handle missing PyTorch (check
HAS_TORCHflag)
@dataclass
class ConsciousnessNode:
"""
Individual consciousness node implementing the Core EQ calculations.
Attributes:
frequency: Φ(x) - frequency signature (Hz, typically 40±5 for gamma)
phase: τ(x) - temporal phase (radians, [0, 2π))
attention: A(x) - attention density (normalized 0-1)
"""
frequency: float = 40.0
phase: float = 0.0
attention: float = 0.0
def update(self, delta_time: float, params: Dict[str, float]) -> None:
"""Update consciousness node using Core EQ calculations."""
# Implementation- Use
np.cos(),np.sin()for trigonometric operations - Maintain complex number separation (real/imaginary parts)
- Normalize attention fields to ensure ∫A(x)dμ = 1
- Apply Dirichlet sampling for universe weights
- ES6 Classes: Use class-based architecture for major components
- Three.js Patterns: Follow Three.js conventions for scene/camera/renderer
- Shader Comments: Document WebGL shader code with mathematical context
- Event Handlers: Use arrow functions for event listeners to preserve
this - Performance: Prefer GPU instancing over individual mesh creation
class ConsciousnessFieldRenderer {
constructor(options = {}) {
this.options = {
latticeSize: options.latticeSize || 128,
complexField: options.complexField !== false,
...options
};
this.init();
}
init() {
this.setupScene();
this.setupCamera();
this.setupRenderer();
this.animate();
}
animate = () => {
requestAnimationFrame(this.animate);
this.render();
}
}- Scene background:
0x0a0a1a(dark blue, consistent with consciousness theme) - Fog: Subtle fog for depth (
THREE.Fog(0x0a0a1a, 1000, 3000)) - Camera: PerspectiveCamera with 60° FOV
- Materials: Use shader materials for complex visualizations
- Python:
snake_case.py - JavaScript:
camelCase.js - CSS:
kebab-case.css - Documentation:
UPPERCASE.mdfor top-level,Title Case.mdfor subdirectories
Follow the project's "Commit Spellcraft" guidelines:
- Present tense: "Fix event loop glitch" (not "Fixed")
- Minify fluff, maximize signal
- Reference issues when relevant: "Fix #123: Resolve WebSocket timeout"
- Keep first line under 72 characters
- Backend (
src/lattice.py):
def calculate_new_phenomenon(self, node: ConsciousnessNode) -> float:
"""
Calculate new consciousness phenomenon.
Mathematical basis: [Explain equation here]
"""
# Implement Core EQ variant
return result- Frontend (
static/js/consciousnessRenderer.js):
updateVisualization(data) {
// Add new visualization mode
if (this.currentMode === 'new_mode') {
// Render new phenomenon
}
}- Bridge (
src/server.py):
# Add API endpoint if needed
@app.post("/api/new_phenomenon")
async def trigger_phenomenon(params: PhenomenonParams):
lattice.calculate_new_phenomenon(params)
return {"status": "success"}- Add enum value in
src/lattice.py:
class UniverseMode(Enum):
NEW_MODE = "new_mode"- Implement shader in
static/js/consciousnessRenderer.js:
setupMaterials() {
this.newModeMaterial = new THREE.ShaderMaterial({
vertexShader: /* GLSL */`...`,
fragmentShader: /* GLSL */`...`,
uniforms: { /* ... */ }
});
}- Update mode switcher in UI
- Update
ParameterUpdatemodel insrc/server.py:
class ParameterUpdate(BaseModel):
new_param: Optional[float] = None- Apply in lattice engine (
src/lattice.py):
def update(self, delta_time: float):
new_param = self.params.get('new_param', default_value)
# Apply to consciousness calculations- Add UI control in
static/index.html:
<input type="range" id="new-param" min="0" max="1" step="0.01" value="0.5">- Preserve mathematical integrity: Core EQ calculations must remain accurate
- Use existing patterns: Follow established code structure (dataclasses, async/await, Three.js classes)
- Test mathematical changes: Run
python src/lattice_demo.pyafter modifying Core EQ - Check both server modes: Ensure changes work with both
demo_server.pyandrun_server.py - Document equations: Include mathematical notation in docstrings
- Handle optional dependencies: Check
HAS_TORCHbefore using PyTorch - Maintain performance: Target 60fps for WebSocket streaming
- Use type hints: All Python functions should have type annotations
- Respect separation of concerns: Backend = math, Frontend = visualization, Bridge = communication
- Break the Core EQ: Never modify consciousness calculations without understanding mathematical basis
- Remove legacy support: Keep
demo_server.pyandlattice_demo.pyworking without heavy dependencies - Break GitHub Pages: Don't modify
index.htmlin ways that break standalone browser demo - Ignore performance: Consciousness simulation requires real-time performance
- Mix concerns: Don't put visualization logic in backend or math logic in frontend
- Hard-code values: Use parameters and configuration for tunable values
- Skip documentation: Mathematical code requires detailed comments
- Assume dependencies: Not all users have PyTorch/GPU; provide NumPy fallbacks
-
Read relevant documentation:
README.md- User-facing featuresARCHITECTURE.md- Technical architectureCONTRIBUTING.md- Development process
-
Understand the mathematical context:
- What consciousness equation is being implemented?
- How does it relate to the Core EQ?
- What are the valid parameter ranges?
-
Check dependencies:
- Does this require new Python packages? Update
requirements.txt - Does this require new JavaScript libraries? Document in code comments
- Will this work without GPU/PyTorch?
- Does this require new Python packages? Update
-
Test locally:
- Run
python demo_server.pyand verify demo works - Run
python run_server.pyand verify production mode works - Test in browser at http://localhost:8000
- Run
| Configuration | Nodes | FPS | Latency | Memory |
|---|---|---|---|---|
| Demo (stdlib only) | 64 | 30 | ~50ms | <50MB |
| Production (NumPy) | 128 | 60 | ~16ms | ~100MB |
| GPU (PyTorch+CUDA) | 512 | 60 | ~8ms | ~200MB |
| Maximum (1024 nodes) | 1024 | 45 | ~22ms | ~400MB |
When optimizing:
- Profile with Python's
cProfileorline_profiler - Use NumPy vectorized operations instead of loops
- Leverage GPU with PyTorch when available
- Use WebGL instancing for large node counts
- Minimize WebSocket payload size (consider binary encoding)
Per SECURITY.md:
- Only versions 5.1.x and 4.0.x receive security updates
- Report vulnerabilities to JACOBCSMITHD@GMAIL.COM
- Maintain responsible testing guidelines (no production impact)
- Follow coordinated disclosure (90 days or until patch)
When adding features:
- Validate all API inputs (use Pydantic models)
- Sanitize user-provided parameters before mathematical calculations
- Prevent infinite loops in consciousness algorithms
- Limit WebSocket message sizes
- Rate-limit API endpoints if exposing to public internet
- Live Demo: https://jacobcdsmith.github.io/CONSIM
- Repository: https://github.com/Jacobcdsmith/CONSIM
- License: Apache 2.0 (see LICENSE file)
- Author: Jacob C. Smith
- Academic Citation:
Smith, J.C. (2025). The Multiversal Consciousness Framework: Real-Time Simulation Architecture. CONSIM Project.
When implementing changes:
- Understand the request: Clarify requirements with the user
- Plan the implementation: Break down into backend/frontend/bridge components
- Check existing code: Look for similar patterns to follow
- Implement incrementally: Make small, testable changes
- Test thoroughly: Verify both demo and production modes
- Document changes: Update docstrings and inline comments
- Commit with clear messages: Follow "Commit Spellcraft" guidelines
- Suggest tests: Recommend how user can verify the changes
User Request: "Add a new 'quantum entanglement' visualization mode"
Step 1: Plan
- Backend: Add quantum_entanglement calculation in lattice.py
- Frontend: Create shader for entanglement visualization
- Bridge: Add mode to UniverseMode enum
Step 2: Backend (src/lattice.py)
- Add UniverseMode.QUANTUM_ENTANGLEMENT
- Implement calculate_entanglement() method
- Update node update logic to track entanglement pairs
Step 3: Frontend (static/js/consciousnessRenderer.js)
- Create entanglementMaterial with custom shader
- Add entanglement connection rendering
- Update mode switcher
Step 4: Test
- Run demo_server.py, verify mode appears
- Run run_server.py, verify WebSocket streams entanglement data
- Check browser console for errors
Step 5: Document
- Add docstring with mathematical basis
- Update CLAUDE.md with new mode (if significant)
- Suggest user test: "Click mode selector, choose 'Quantum Entanglement', spawn nodes"
fastapi>=0.100.0
uvicorn[standard]>=0.20.0
websockets>=11.0
numpy>=1.20.0
pydantic>=2.0.0
python-multipart>=0.0.6
aiofiles>=23.0.0
- Three.js (included via CDN in HTML)
- No build process required (vanilla JS)
# Demo mode (no dependencies)
python demo_server.py
# Production mode (requires requirements.txt)
python run_server.py
# With specific host/port
python run_server.py --host 0.0.0.0 --port 8080When making changes, consider impact on:
-
src/lattice.py- Core consciousness engine -
src/server.py- FastAPI server -
static/js/consciousnessRenderer.js- Three.js renderer -
static/js/app.js- Application logic -
static/index.html- UI controls -
requirements.txt- Python dependencies -
README.md- User documentation -
CLAUDE.md- This file (if architectural changes)
If you're new to this codebase, study in this order:
- README.md - Understand user perspective and features
- ARCHITECTURE.md - Grasp three-tier architecture
- src/lattice.py (first 100 lines) - Learn Core EQ implementation
- static/js/consciousnessRenderer.js (first 100 lines) - Understand visualization
- src/server.py - See how WebSocket bridge works
- CONTRIBUTING.md - Learn development culture and workflow
- This file (CLAUDE.md) - Deep dive into patterns and conventions
Time estimate: ~30 minutes to reach productive contribution level
As an AI assistant, if you encounter:
- Unclear mathematical notation: Ask user to clarify the consciousness equation context
- Ambiguous requirements: Request specific examples or use cases
- Architecture questions: Refer back to ARCHITECTURE.md or this file
- Build/dependency issues: Check Python version (3.8+), installed packages
- Performance problems: Profile before optimizing, check FPS targets above
Remember: The project maintainer (Jacob C. Smith) values "deliberate clarity" and "sharp messages" (per CONTRIBUTING.md). Be precise and technically accurate in communications.
Last Updated: 2025-01-17 Codebase Version: 1.0.0 Target AI Assistant: Claude Code, GPT-4, Copilot, or similar code-aware AI
"Build bravely. Ship weird. See you in the diffs." - CONTRIBUTING.md