🏗️ Architecture

A visual guide to how ChatrixCD works under the hood.

💡 Quick Summary: ChatrixCD bridges Matrix (encrypted chat) and Semaphore UI (CI/CD automation) with a Python bot that handles commands, manages tasks, and provides a beautiful TUI.

📊 System Overview

ChatrixCD Architecture Diagram

🧩 Core Components

🤖 Bot Core (bot.py)

The Heart of ChatrixCD

  • Matrix client management
  • E2E encryption handling
  • Event processing
  • Auto-sync & device verification

⚡ Commands (commands.py)

Command Processing Engine

  • Command parsing & validation
  • Semaphore API integration
  • Task management
  • Response formatting

🖥️ TUI (tui.py)

Interactive Interface

  • Status monitoring
  • Room management
  • Device verification
  • Log viewing

⚙️ Config (config.py)

Configuration Manager

  • HJSON parsing
  • Schema validation
  • Auto-migration
  • Secure defaults

🚀 Semaphore (semaphore.py)

CI/CD Integration

  • REST API client
  • Task lifecycle management
  • Status monitoring
  • Log retrieval

📝 Messages (messages.py)

Response Templates

  • Varied greetings
  • Sassy responses
  • Auto-reload support
  • Emoji & formatting

🔄 Data Flow

1️⃣

User Sends Command

User types !cd run 1 2 in a Matrix room

🔐 Message is E2E encrypted if room is encrypted

2️⃣

Bot Receives & Decrypts

Bot receives message event, decrypts it (if encrypted), and parses the command

🔍 Command parser validates syntax and permissions

3️⃣

Request Confirmation

Bot fetches template details and sends confirmation message with reaction buttons

👍👎 User reacts with thumbs up/down

4️⃣

Execute Task

Bot makes API call to Semaphore UI to start the task

🚀 Task ID returned and tracked

5️⃣

Monitor & Update

Bot polls task status and sends updates back to the room

📊 Real-time status updates with colored indicators

6️⃣

Task Complete

Final status sent with completion time and success/failure indicators

✅❌ Success = 🎉, Failure = 😔


🔐 Security Architecture

🔒 E2E Encryption

Matrix-nio handles Olm/Megolm encryption automatically. All encrypted room messages are secure.

🔑 Key Storage

Encryption keys stored in store/ directory with proper file permissions.

🛡️ Device Verification

Supports emoji, QR code, and fingerprint verification for trusted devices.

🔐 OIDC/SSO

Native OIDC authentication with major identity providers.

🚫 Permission Control

Configurable allowed_rooms restricts bot to authorized spaces.

🔍 Audit Trail

All commands and actions logged for security auditing.


🎯 Design Principles

Principle Implementation
🔄 Async First All I/O operations use async/await for non-blocking execution
🎭 User Experience Fun personality, emoji, reaction confirmations
🛡️ Security First E2E encryption, device verification, permission controls built-in
🔧 Configuration HJSON support, validation, auto-migration, sensible defaults
📝 DRY Code Extracted helpers, shared utilities, reusable components
✅ Testability Small focused methods, dependency injection, comprehensive tests

📦 Technology Stack

🐍 Python 3.12+

Modern Python with async/await

📱 matrix-nio

Matrix client with E2E encryption

🌐 aiohttp

Async HTTP for Semaphore API

🖥️ Textual

Terminal UI framework

📝 HJSON

Human-friendly JSON config

🔐 cryptography

Encryption & key management


📚 Learn More

🔧 Implementation Details

Full ARCHITECTURE.md →

🤝 Contributing

Contributing Guide →

🔒 Security

Security Policy →