# πŸ—ΊοΈ BlackRoad OS Repository Map **Version**: 2.5 **Date**: 2025-11-18 **Purpose**: Complete module-by-module breakdown showing how components connect --- ## Repository Structure ``` BlackRoad-Operating-System/ # Canonical OS monorepo β”œβ”€β”€ backend/ # FastAPI backend + static UI β”‚ β”œβ”€β”€ app/ # Core application β”‚ β”‚ β”œβ”€β”€ main.py # FastAPI app, router registration β”‚ β”‚ β”œβ”€β”€ config.py # Settings (Pydantic) β”‚ β”‚ β”œβ”€β”€ database.py # SQLAlchemy async sessions β”‚ β”‚ β”œβ”€β”€ redis_client.py # Redis connection pool β”‚ β”‚ β”œβ”€β”€ models/ # Database models (SQLAlchemy) β”‚ β”‚ β”œβ”€β”€ routers/ # API endpoint routers (33+) β”‚ β”‚ β”œβ”€β”€ services/ # Business logic layer β”‚ β”‚ └── utils/ # Shared utilities β”‚ β”œβ”€β”€ static/ # Frontend UI (canonical) β”‚ β”‚ β”œβ”€β”€ index.html # Main OS interface β”‚ β”‚ β”œβ”€β”€ prism/ # Prism Console UI β”‚ β”‚ β”œβ”€β”€ js/ # JavaScript modules β”‚ β”‚ └── assets/ # CSS, images, fonts β”‚ β”œβ”€β”€ tests/ # Backend test suite β”‚ β”œβ”€β”€ requirements.txt # Python dependencies β”‚ └── Dockerfile # Container definition β”‚ β”œβ”€β”€ agents/ # 200+ AI agent ecosystem β”‚ β”œβ”€β”€ base/ # Core agent framework β”‚ β”œβ”€β”€ categories/ # 10 agent categories β”‚ └── tests/ # Agent tests β”‚ β”œβ”€β”€ sdk/ # Client SDKs β”‚ β”œβ”€β”€ python/ # Python SDK β”‚ └── typescript/ # TypeScript SDK β”‚ β”œβ”€β”€ codex-docs/ # MkDocs documentation β”‚ β”œβ”€β”€ mkdocs.yml # Docs configuration β”‚ β”œβ”€β”€ docs/ # Markdown documentation β”‚ └── DEPLOY_DOCS.md # Deployment guide β”‚ β”œβ”€β”€ infra/ # Infrastructure configs β”‚ β”œβ”€β”€ cloudflare/ # DNS, Workers β”‚ β”œβ”€β”€ railway/ # Railway deployment β”‚ └── env/ # Environment variables β”‚ β”œβ”€β”€ .github/ # GitHub automation β”‚ β”œβ”€β”€ workflows/ # CI/CD pipelines β”‚ └── CODEOWNERS # Code ownership β”‚ β”œβ”€β”€ docs/ # Legacy docs (consolidating to codex-docs/) β”œβ”€β”€ scripts/ # Utility scripts β”œβ”€β”€ ops/ # Operations tools └── [Root documentation files] β”œβ”€β”€ README.md # Project overview β”œβ”€β”€ CLAUDE.md # AI assistant guide β”œβ”€β”€ MASTER_ORCHESTRATION_PLAN.md # Infrastructure blueprint β”œβ”€β”€ PHASE2_5_SUMMARY_FOR_ALEXA.md # Phase 2.5 summary └── DEPLOYMENT_NOTES.md # Production deployment guide ``` --- ## Module Connections & Data Flow ### 1. Request Flow (User β†’ Backend β†’ Database) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ USER BROWSER β”‚ β”‚ - Visits: https://blackroad.systems β”‚ β”‚ - Loads: backend/static/index.html β”‚ β”‚ - Executes: JavaScript (OS boot) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ HTTP Request β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CLOUDFLARE CDN β”‚ β”‚ - DNS resolution β”‚ β”‚ - SSL termination β”‚ β”‚ - Static asset caching β”‚ β”‚ - DDoS protection β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Proxy β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ RAILWAY β†’ FastAPI Backend (backend/app/main.py) β”‚ β”‚ β”‚ β”‚ Request Handling: β”‚ β”‚ 1. CORS Middleware (app/main.py:78) β”‚ β”‚ 2. Timing Middleware (app/main.py:89) β”‚ β”‚ 3. Router Matching β”‚ β”‚ β”‚ β”‚ Routes: β”‚ β”‚ β€’ GET / β†’ StaticFiles(backend/static/) β”‚ β”‚ β€’ GET /prism β†’ StaticFiles(backend/static/prism/) β”‚ β”‚ β€’ GET /api/docs β†’ OpenAPI documentation β”‚ β”‚ β€’ GET /health β†’ Health check endpoint β”‚ β”‚ β€’ POST /api/auth/login β†’ auth.router β”‚ β”‚ β€’ GET /api/prism/jobs β†’ prism.router (future) β”‚ β”‚ β€’ [30+ other API routes] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ROUTER LAYER (backend/app/routers/) β”‚ β”‚ β”‚ β”‚ Example: POST /api/auth/login β”‚ β”‚ 1. routers/auth.py:login() β”‚ β”‚ 2. Validate request (Pydantic schema) β”‚ β”‚ 3. Call service layer β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SERVICE LAYER (backend/app/services/) β”‚ β”‚ β”‚ β”‚ Example: services/auth.py β”‚ β”‚ 1. authenticate_user(email, password) β”‚ β”‚ 2. Query database via models β”‚ β”‚ 3. Verify password hash β”‚ β”‚ 4. Generate JWT token β”‚ β”‚ 5. Store session in Redis β”‚ β”‚ 6. Return user data + token β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DATA LAYER β”‚ β”‚ β”‚ β”‚ PostgreSQL (Railway managed): β”‚ β”‚ β€’ app/database.py β†’ async session β”‚ β”‚ β€’ app/models/ β†’ SQLAlchemy ORM β”‚ β”‚ β€’ Tables: users, wallets, blocks, etc. β”‚ β”‚ β”‚ β”‚ Redis (Railway managed): β”‚ β”‚ β€’ app/redis_client.py β†’ connection pool β”‚ β”‚ β€’ Usage: sessions, caching, WebSocket state β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Response β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ BROWSER (JavaScript) β”‚ β”‚ - Receives JSON response β”‚ β”‚ - Updates OS UI (DOM manipulation) β”‚ β”‚ - Stores token in localStorage β”‚ β”‚ - Makes subsequent API calls with auth header β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## 2. Frontend Architecture (Vanilla JavaScript) ### Main OS (backend/static/) ``` static/ β”œβ”€β”€ index.html # OS entry point β”‚ └── Loads: β”‚ β”œβ”€β”€ css/os.css # OS styling β”‚ β”œβ”€β”€ js/os.js # Core OS runtime β”‚ β”œβ”€β”€ js/components.js # UI component library β”‚ β”œβ”€β”€ js/registry.js # App registry β”‚ └── js/apps/*.js # Individual apps β”‚ β”œβ”€β”€ js/ β”‚ β”œβ”€β”€ os.js # Core OS β”‚ β”‚ β”œβ”€β”€ window.OS object # Global OS namespace β”‚ β”‚ β”œβ”€β”€ Event bus # Inter-app communication β”‚ β”‚ β”œβ”€β”€ Window manager # Draggable windows β”‚ β”‚ └── State management # Local storage β”‚ β”‚ β”‚ β”œβ”€β”€ components.js # UI Components β”‚ β”‚ β”œβ”€β”€ Button() # Button component β”‚ β”‚ β”œβ”€β”€ Card() # Card component β”‚ β”‚ β”œβ”€β”€ Modal() # Modal dialog β”‚ β”‚ └── [12+ other components] β”‚ β”‚ β”‚ β”œβ”€β”€ registry.js # App Registry β”‚ β”‚ β”œβ”€β”€ List of all apps # Icon, name, category β”‚ β”‚ └── App initialization # Load on demand β”‚ β”‚ β”‚ └── apps/ # Application Modules β”‚ β”œβ”€β”€ prism.js # Prism Console app β”‚ β”œβ”€β”€ lucidia.js # AI chat app β”‚ β”œβ”€β”€ miners.js # Mining app β”‚ β”œβ”€β”€ dashboard.js # Dashboard app β”‚ └── [20+ other apps] β”‚ └── assets/ β”œβ”€β”€ css/ # Stylesheets β”‚ β”œβ”€β”€ os.css # Main OS styles β”‚ β”œβ”€β”€ win95.css # Windows 95 theme β”‚ └── components.css # Component styles β”‚ └── images/ # Icons, logos, backgrounds ``` ### Prism Console (backend/static/prism/) ``` prism/ β”œβ”€β”€ index.html # Prism entry point (served at /prism) β”‚ └── Loads: β”‚ β”œβ”€β”€ css/prism.css # Prism-specific styling β”‚ β”œβ”€β”€ js/prism-core.js # Prism runtime β”‚ └── js/prism-components.js # Prism UI components β”‚ β”œβ”€β”€ js/ β”‚ β”œβ”€β”€ prism-core.js # Core Prism logic β”‚ β”‚ β”œβ”€β”€ Job queue management # Monitor running jobs β”‚ β”‚ β”œβ”€β”€ Event log viewer # System event stream β”‚ β”‚ β”œβ”€β”€ Metrics dashboard # Health, performance β”‚ β”‚ └── API client # Calls /api/prism/* β”‚ β”‚ β”‚ └── prism-components.js # Prism-specific UI β”‚ β”œβ”€β”€ JobCard() # Job display card β”‚ β”œβ”€β”€ LogViewer() # Event log component β”‚ └── MetricsChart() # Metrics visualization β”‚ └── assets/ └── css/prism.css # Prism styling ``` ### Communication Pattern ```javascript // Example: Prism Console fetching jobs // 1. Prism UI component (prism/js/prism-core.js) async function fetchJobs() { const response = await fetch('/api/prism/jobs', { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` } }); const jobs = await response.json(); renderJobs(jobs); } // 2. Backend router (backend/app/routers/prism.py) @router.get("/jobs") async def get_jobs( current_user = Depends(get_current_user), db: AsyncSession = Depends(get_db) ): jobs = await db.execute(select(Job).where(Job.user_id == current_user.id)) return jobs.scalars().all() // 3. Response flows back to frontend, rendered in UI ``` --- ## 3. Backend API Architecture ### Router Organization (backend/app/routers/) ``` routers/ β”œβ”€β”€ auth.py # Authentication β”‚ β”œβ”€β”€ POST /api/auth/register # User registration β”‚ β”œβ”€β”€ POST /api/auth/login # User login β”‚ β”œβ”€β”€ POST /api/auth/refresh # Token refresh β”‚ └── GET /api/auth/me # Current user β”‚ β”œβ”€β”€ prism_static.py # Prism Console static serving (NEW) β”‚ └── GET /prism/* # Serve Prism UI files β”‚ β”œβ”€β”€ prism.py # Prism API (future) β”‚ β”œβ”€β”€ GET /api/prism/jobs # List jobs β”‚ β”œβ”€β”€ POST /api/prism/jobs # Create job β”‚ β”œβ”€β”€ GET /api/prism/jobs/{id} # Get job details β”‚ β”œβ”€β”€ GET /api/prism/events # Event stream β”‚ └── GET /api/prism/metrics # System metrics β”‚ β”œβ”€β”€ dashboard.py # Dashboard data β”‚ β”œβ”€β”€ GET /api/dashboard/stats # System statistics β”‚ └── GET /api/dashboard/activity # Recent activity β”‚ β”œβ”€β”€ blockchain.py # RoadChain β”‚ β”œβ”€β”€ GET /api/blockchain/blocks # List blocks β”‚ β”œβ”€β”€ POST /api/blockchain/blocks # Create block β”‚ └── GET /api/blockchain/verify # Verify chain β”‚ β”œβ”€β”€ ai_chat.py # AI/Lucidia integration β”‚ β”œβ”€β”€ POST /api/chat/message # Send message β”‚ └── GET /api/chat/history # Chat history β”‚ β”œβ”€β”€ miner.py # Mining operations β”‚ β”œβ”€β”€ POST /api/miner/start # Start mining β”‚ β”œβ”€β”€ POST /api/miner/stop # Stop mining β”‚ └── GET /api/miner/stats # Mining statistics β”‚ └── [30+ other routers] # See backend/app/main.py for full list ``` ### Service Layer (backend/app/services/) ``` services/ β”œβ”€β”€ auth.py # Authentication logic β”‚ β”œβ”€β”€ authenticate_user() # Verify credentials β”‚ β”œβ”€β”€ create_access_token() # Generate JWT β”‚ └── verify_token() # Validate JWT β”‚ β”œβ”€β”€ crypto.py # Cryptography β”‚ β”œβ”€β”€ hash_password() # Password hashing β”‚ β”œβ”€β”€ verify_password() # Password verification β”‚ └── encrypt_wallet_key() # Wallet encryption β”‚ β”œβ”€β”€ blockchain.py # RoadChain logic β”‚ β”œβ”€β”€ create_block() # Create new block β”‚ β”œβ”€β”€ verify_chain() # Verify blockchain β”‚ └── calculate_hash() # SHA-256 hashing β”‚ └── [Other services] ``` ### Database Models (backend/app/models/) ``` models/ β”œβ”€β”€ user.py # User model β”‚ β”œβ”€β”€ id: int (PK) β”‚ β”œβ”€β”€ email: str (unique) β”‚ β”œβ”€β”€ password_hash: str β”‚ β”œβ”€β”€ created_at: datetime β”‚ └── Relationships: wallets, jobs β”‚ β”œβ”€β”€ wallet.py # Wallet model β”‚ β”œβ”€β”€ id: int (PK) β”‚ β”œβ”€β”€ user_id: int (FK β†’ users) β”‚ β”œβ”€β”€ address: str (unique) β”‚ β”œβ”€β”€ private_key_encrypted: str β”‚ └── balance: float β”‚ β”œβ”€β”€ block.py # Blockchain block β”‚ β”œβ”€β”€ id: int (PK) β”‚ β”œβ”€β”€ index: int β”‚ β”œβ”€β”€ timestamp: datetime β”‚ β”œβ”€β”€ data: JSON β”‚ β”œβ”€β”€ previous_hash: str β”‚ └── hash: str β”‚ β”œβ”€β”€ job.py # Prism job (future) β”‚ β”œβ”€β”€ id: int (PK) β”‚ β”œβ”€β”€ user_id: int (FK β†’ users) β”‚ β”œβ”€β”€ type: str (e.g., "deploy", "test") β”‚ β”œβ”€β”€ status: str (pending/running/completed/failed) β”‚ β”œβ”€β”€ created_at: datetime β”‚ └── result: JSON β”‚ └── [Other models] ``` --- ## 4. Agent Ecosystem (agents/) ### Base Framework (agents/base/) ``` base/ β”œβ”€β”€ agent.py # Base Agent class β”‚ β”œβ”€β”€ __init__(name, version, category) β”‚ β”œβ”€β”€ async execute() # Main execution method β”‚ β”œβ”€β”€ async initialize() # Setup before execution β”‚ β”œβ”€β”€ async cleanup() # Cleanup after execution β”‚ └── async on_error(error) # Error handling β”‚ β”œβ”€β”€ executor.py # Execution engine β”‚ β”œβ”€β”€ run_agent(agent) # Execute single agent β”‚ β”œβ”€β”€ run_workflow(agents) # Execute agent workflow β”‚ └── schedule_agent(agent, cron) # Schedule recurring execution β”‚ └── registry.py # Agent discovery β”œβ”€β”€ register(agent) # Register agent β”œβ”€β”€ discover() # Auto-discover agents └── get_agent(name) # Get agent by name ``` ### Agent Categories (agents/categories/) ``` categories/ β”œβ”€β”€ devops/ # DevOps agents (30+) β”‚ β”œβ”€β”€ deploy_agent.py # Deployment automation β”‚ β”œβ”€β”€ monitor_agent.py # Infrastructure monitoring β”‚ └── backup_agent.py # Backup automation β”‚ β”œβ”€β”€ engineering/ # Engineering agents (40+) β”‚ β”œβ”€β”€ code_review_agent.py # Code review β”‚ β”œβ”€β”€ test_generator_agent.py # Test generation β”‚ └── refactor_agent.py # Code refactoring β”‚ β”œβ”€β”€ ai_ml/ # AI/ML agents (25+) β”‚ β”œβ”€β”€ model_trainer_agent.py # Model training β”‚ β”œβ”€β”€ data_pipeline_agent.py # Data processing β”‚ └── inference_agent.py # Model inference β”‚ └── [7 more categories] # See agents/README.md ``` ### Agent Communication (via Prism) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT A (Deploy Agent) β”‚ β”‚ 1. Execute deployment β”‚ β”‚ 2. Publish event to Prism: {"type": "deploy_complete"} β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Event β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PRISM (Event Bus) β”‚ β”‚ - Receives event β”‚ β”‚ - Logs to event table (database) β”‚ β”‚ - Publishes to Redis (pub/sub) β”‚ β”‚ - Notifies subscribed agents β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Subscription β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT B (Monitor Agent) β”‚ β”‚ 1. Receives "deploy_complete" event β”‚ β”‚ 2. Runs health checks β”‚ β”‚ 3. Publishes event: {"type": "health_check_passed"} β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## 5. Documentation (codex-docs/) ### MkDocs Structure ``` codex-docs/ β”œβ”€β”€ mkdocs.yml # Configuration β”‚ β”œβ”€β”€ site_name: "BlackRoad OS Codex" β”‚ β”œβ”€β”€ theme: material # Material for MkDocs β”‚ β”œβ”€β”€ plugins: search, etc. # MkDocs plugins β”‚ └── nav: [navigation structure] # Sidebar navigation β”‚ β”œβ”€β”€ docs/ # Markdown documentation β”‚ β”œβ”€β”€ index.md # Landing page β”‚ β”‚ β”‚ β”œβ”€β”€ architecture/ # Architecture docs β”‚ β”‚ β”œβ”€β”€ overview.md # System overview β”‚ β”‚ β”œβ”€β”€ phase2-decisions.md # Phase 2.5 decisions β”‚ β”‚ └── infra-deployment.md # Deployment architecture β”‚ β”‚ β”‚ β”œβ”€β”€ api/ # API reference β”‚ β”‚ β”œβ”€β”€ authentication.md # Auth endpoints β”‚ β”‚ β”œβ”€β”€ prism.md # Prism API β”‚ β”‚ └── blockchain.md # RoadChain API β”‚ β”‚ β”‚ β”œβ”€β”€ guides/ # User guides β”‚ β”‚ β”œβ”€β”€ quickstart.md # Quick start guide β”‚ β”‚ β”œβ”€β”€ deployment.md # Deployment guide β”‚ β”‚ └── development.md # Development setup β”‚ β”‚ β”‚ β”œβ”€β”€ agents/ # Agent documentation β”‚ β”‚ β”œβ”€β”€ overview.md # Agent ecosystem β”‚ β”‚ β”œβ”€β”€ creating-agents.md # How to create agents β”‚ β”‚ └── categories.md # Agent categories β”‚ β”‚ β”‚ └── contributing.md # Contribution guidelines β”‚ β”œβ”€β”€ DEPLOY_DOCS.md # Deployment guide for docs β”‚ └── site/ # Generated site (gitignored) └── [Built HTML files] ``` ### Documentation Deployment Flow ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DEVELOPER β”‚ β”‚ 1. Edit markdown in codex-docs/docs/ β”‚ β”‚ 2. Test locally: mkdocs serve β”‚ β”‚ 3. Commit and push to main β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Git Push β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ GITHUB ACTIONS (.github/workflows/docs-deploy.yml) β”‚ β”‚ 1. Checkout code β”‚ β”‚ 2. Install MkDocs + Material theme β”‚ β”‚ 3. Run: mkdocs build --strict β”‚ β”‚ 4. Deploy to gh-pages branch β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Deploy β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ GITHUB PAGES β”‚ β”‚ - Serves from: gh-pages branch β”‚ β”‚ - URL: https://blackboxprogramming.github.io/BlackRoad-* β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ DNS β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CLOUDFLARE β”‚ β”‚ - CNAME: docs.blackroad.systems β†’ blackboxprogramming.github.io β”‚ β”‚ - Proxied: Yes (SSL + CDN) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ USER β”‚ β”‚ - Visits: https://docs.blackroad.systems β”‚ β”‚ - Views: MkDocs documentation β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## 6. SDK Architecture (sdk/) ### Python SDK (sdk/python/) ```python # Example usage: from blackroad import BlackRoadClient client = BlackRoadClient( base_url="https://blackroad.systems", api_key="your-api-key" ) # Authenticate user = await client.auth.login("email@example.com", "password") # Create a job job = await client.prism.create_job({ "type": "deploy", "target": "production", "config": {...} }) # Monitor job status = await client.prism.get_job_status(job.id) ``` ### TypeScript SDK (sdk/typescript/) ```typescript // Example usage: import { BlackRoadClient } from '@blackroad/sdk'; const client = new BlackRoadClient({ baseUrl: 'https://blackroad.systems', apiKey: 'your-api-key' }); // Authenticate const user = await client.auth.login('email@example.com', 'password'); // Create a job const job = await client.prism.createJob({ type: 'deploy', target: 'production', config: {...} }); // Monitor job const status = await client.prism.getJobStatus(job.id); ``` --- ## 7. Infrastructure (infra/) ### Cloudflare (infra/cloudflare/) ``` cloudflare/ β”œβ”€β”€ records.yaml # DNS records β”œβ”€β”€ CLOUDFLARE_DNS_BLUEPRINT.md # DNS configuration guide β”œβ”€β”€ DNS_CONFIGURATION.md # Detailed DNS setup (NEW) └── cloudflare_dns_sync.py # Automated DNS sync script ``` ### Railway (infra/railway/) ``` railway/ β”œβ”€β”€ RAILWAY_DEPLOYMENT_GUIDE.md # Complete deployment guide (NEW) β”œβ”€β”€ railway.toml # Railway configuration └── railway.json # Service definitions ``` ### Environment (infra/env/) ``` env/ └── ENVIRONMENT_MAP.md # Cross-platform env vars ``` --- ## 8. CI/CD (.github/workflows/) ``` workflows/ β”œβ”€β”€ ci.yml # Main CI (lint, test, build) β”œβ”€β”€ backend-tests.yml # Backend test suite β”œβ”€β”€ railway-deploy.yml # Deploy to Railway β”œβ”€β”€ docs-deploy.yml # Deploy docs to GitHub Pages (NEW) β”œβ”€β”€ railway-automation.yml # Railway secrets audit └── [Other workflows] ``` --- ## API Contracts Between Layers ### Frontend ↔ Backend **Authentication:** ```typescript // Request POST /api/auth/login { "email": "user@example.com", "password": "password123" } // Response { "access_token": "eyJhbGciOi...", "token_type": "bearer", "user": { "id": 1, "email": "user@example.com" } } ``` **Prism Jobs:** ```typescript // Request GET /api/prism/jobs Headers: { "Authorization": "Bearer eyJhbGciOi..." } // Response { "data": [ { "id": 1, "type": "deploy", "status": "completed", "created_at": "2025-11-18T12:00:00Z", "result": {...} } ], "total": 42, "page": 1, "per_page": 20 } ``` ### Backend ↔ Database **User Query:** ```python # ORM Query (SQLAlchemy) from app.models.user import User from sqlalchemy import select result = await db.execute( select(User).where(User.email == email) ) user = result.scalar_one_or_none() ``` **Blockchain Query:** ```python # Get latest blocks from app.models.block import Block result = await db.execute( select(Block) .order_by(Block.index.desc()) .limit(10) ) blocks = result.scalars().all() ``` ### Backend ↔ Redis **Session Storage:** ```python # Store session await redis.setex( f"session:{user_id}", 3600, # 1 hour json.dumps({"user_id": user_id, "email": email}) ) # Retrieve session session_data = await redis.get(f"session:{user_id}") ``` **WebSocket State:** ```python # Publish event await redis.publish( "prism:events", json.dumps({"type": "job_completed", "job_id": 123}) ) # Subscribe to events pubsub = redis.pubsub() await pubsub.subscribe("prism:events") ``` --- ## Key Integration Points ### 1. OS β†’ Prism Console - User clicks "Prism Console" app in OS - OS opens window with iframe/route to `/prism` - Prism UI loads, shares auth token from OS - Prism makes API calls to `/api/prism/*` ### 2. Prism β†’ Backend API - Prism fetches jobs: `GET /api/prism/jobs` - Backend queries database via models - Returns JSON response - Prism renders in UI ### 3. Backend β†’ Database - Router receives request - Service layer business logic - ORM query via async session - Results returned to router ### 4. Backend β†’ Redis - Session management - WebSocket state - Caching API responses - Pub/sub for real-time events ### 5. Frontend β†’ Documentation - "Help" link in OS - Opens new tab to `https://docs.blackroad.systems` - MkDocs site served from GitHub Pages - Searchable documentation --- ## Deployment Connections ### Development Environment ``` Developer Machine β”œβ”€β”€ Backend: http://localhost:8000 β”‚ β”œβ”€β”€ OS: http://localhost:8000/ β”‚ β”œβ”€β”€ Prism: http://localhost:8000/prism β”‚ └── API Docs: http://localhost:8000/api/docs β”‚ β”œβ”€β”€ Docs: http://localhost:8001 β”‚ └── mkdocs serve (port 8001) β”‚ β”œβ”€β”€ PostgreSQL: localhost:5432 (via Docker) └── Redis: localhost:6379 (via Docker) ``` ### Production Environment ``` User Browser ↓ Cloudflare CDN (DNS + SSL) ↓ Railway Backend β”œβ”€β”€ FastAPI (port 8000) β”œβ”€β”€ PostgreSQL (Railway managed) └── Redis (Railway managed) GitHub Pages └── Docs (codex-docs/ β†’ gh-pages branch) ``` --- ## Phase 2 vs Phase 3: Monorepo Evolution ### Phase 2 (Current): Monorepo **All in `BlackRoad-Operating-System`:** - βœ… Single source of truth - βœ… Easy cross-component changes - βœ… Simple CI/CD ### Phase 3 (Future): Multi-Repo **When to split:** - Team size > 10 developers - Independent release cycles needed - Different tech stacks emerging **Potential split:** ``` blackroad-os-core β†’ Core runtime (Python) blackroad-os-api β†’ Backend API (Python/FastAPI) blackroad-os-web β†’ Frontend UI (JavaScript) blackroad-os-prism β†’ Prism Console (JavaScript/Python) blackroad-os-operator β†’ Worker engine (Python) blackroad-os-docs β†’ Documentation (Markdown/MkDocs) ``` **Migration strategy:** - Use `git subtree split` to preserve history - Set up cross-repo CI coordination - Implement versioned API contracts - Maintain unified documentation --- ## Summary: How It All Connects 1. **User** visits `blackroad.systems` 2. **Cloudflare** resolves DNS, terminates SSL, proxies to Railway 3. **Railway** runs FastAPI backend 4. **Backend** serves static OS UI from `backend/static/` 5. **OS** boots in browser, renders Windows 95-style interface 6. **User** opens Prism Console app 7. **OS** loads `/prism` route (static Prism UI) 8. **Prism** makes API calls to `/api/prism/*` 9. **Backend** routes to `routers/prism.py` 10. **Router** calls service layer 11. **Service** queries database via models 12. **Database** returns data 13. **Service** returns to router 14. **Router** returns JSON to Prism 15. **Prism** renders data in UI 16. **User** sees job queue, metrics, events **For documentation:** 1. **Developer** edits `codex-docs/docs/` 2. **Push** to main branch 3. **GitHub Actions** runs `mkdocs build` 4. **Deploys** to `gh-pages` branch 5. **GitHub Pages** serves at `blackboxprogramming.github.io/...` 6. **Cloudflare** CNAMEs `docs.blackroad.systems` to GitHub Pages 7. **User** visits `https://docs.blackroad.systems` --- **Where AI meets the open road.** πŸ›£οΈ *Complete repository map showing all module connections and data flows.*