Architecture

129K lines of pure C11 — modular static libraries, 56 standalone binaries, zero external dependencies. Every component from HTTP to TLS to containers built in-house.

129,395
129K lines of C
476
476 source files
56
56 executables
0
Zero deps

Overview

scorpiox code is written entirely in C11 with zero external runtime dependencies. The codebase compiles to 56 standalone static binaries — each tool is self-contained with no shared libraries needed at runtime. The architecture follows a layered library model: foundational utilities in libsxutil, networking and AI providers in libsxnet, and terminal UI in libsxui.

Core Libraries

Module Type Lines Files Purpose
libsxutil library 19,221 55 Core utilities — config, logging, platform abstraction, conversation management, session handling, command parsing, PTY control, process monitoring, background tasks, tool definitions, WASM execution support
libsxnet library 21,149 36 Networking and AI providers — HTTP client, streaming SSE, multi-provider AI backends (Anthropic, OpenAI, Gemini, Claude Code, Codex, ScorpioX), MCP protocol, FRP reverse proxy, JSON processing
libsxui library 11,092 15 Terminal UI — rich TUI rendering, ANSI escape sequences, input handling, markdown rendering, syntax highlighting, diff viewer, image display
libsxbridge library 524 2 C#/.NET bridge — P/Invoke compatible shared library interface for managed language interop
sxterm library 1,874 2 Terminal control — raw terminal mode, input parsing, UTF-8 handling
libtb4 library 1,022 3 Thunderbolt 4 raw Ethernet — direct frame I/O for LAN file transfer
yyjson vendored 19,556 2 High-performance JSON parser — vendored, used via sx_json_yy wrapper layer
mbedTLS vendored 206,340 18 TLS library — vendored for FRP crypto, email server TLS. Avoids OpenSSL dependency

Dependency Graph

  sx (main TUI)
  ├── sxui ────────┐
  │   ├── sxutil     
  │   └── sxnet      
  ├── sxnet ───────┤
  │   ├── sxutil     
  │   └── mbedtls    
  ├── sxutil ──────┤
  │   └── yyjson     
  ├── sxterm         
  └── curl (system)  
                       
  sxbridge ──────────┘
  └── sxutil

  ▪ vendored  ▪ project lib  ▪ dependency flow

Executables

Major Components

Name Lines Description
sx 6,176 Main TUI — the primary interactive terminal UI (aliased as "scorpiox")
scorpiox-tmux 6,048 Tmux mission control — terminal multiplexer management with sxmux backend
scorpiox-multiplexer 4,949 Terminal multiplexer — built-in PTY-based terminal multiplexer
scorpiox-server-email 5,378 Full SMTP + IMAP email server with TLS, DKIM, maildir storage
scorpiox-server 3,018 HTTP server for Python script execution
scorpiox-bashShell wrapper
scorpiox-configConfiguration management
scorpiox-convConversation manager
scorpiox-debugDebugging tool
scorpiox-loggerLog viewer
scorpiox-searchWeb search tool
scorpiox-docsDocumentation reader
scorpiox-agentAgentic executor
scorpiox-tasksTask manager
scorpiox-planmodePlan mode manager
scorpiox-askuserquestionInteractive Q&A TUI
scorpiox-voiceVoice recording & transcription
scorpiox-emailEmail client (SMTP sender)
scorpiox-executecurlCurl executor
scorpiox-mcpMCP protocol client
scorpiox-hookEvent hook system
scorpiox-cronCrontab wrapper CLI
scorpiox-sdkHeadless CLI for programmatic usage
scorpiox-screenshotCross-platform screenshot
scorpiox-renderimageTerminal image renderer
scorpiox-rewindConversation rewind tool
scorpiox-transcriptTranscript viewer TUI
scorpiox-otpTOTP generator
scorpiox-usageToken usage tracking
scorpiox-runtestTest runner
scorpiox-systempromptSystem prompt management
scorpiox-printlogsLog printer
scorpiox-emit-sessionSession event telemetry
scorpiox-frpFRP-compatible reverse proxy client
scorpiox-dnsLightweight LAN DNS server
scorpiox-beamFast LAN file transfer
scorpiox-thunderbolt4Raw Ethernet file transfer over TB4
scorpiox-hostSession gateway server + CLI client
scorpiox-trafficNetwork traffic monitoring
scorpiox-sshpassSSH wrapper with PTY password feeding
scorpiox-geminiAnthropic-to-Gemini API proxy
scorpiox-openaiAnthropic-to-OpenAI API proxy
scorpiox-pwshRemote PowerShell via REST API
scorpiox-spaceship-cliDNS management via Spaceship API
scorpiox-claudecode-fetchtokenClaude Code token fetcher
scorpiox-codex-fetchtokenCodex token fetcher
scorpiox-whatsappWhatsApp CLI
scorpiox-imessageiMessage CLI
scorpiox-podmanPodman container execution
scorpiox-unshareRootless container runtime using user namespaces — pure libc
scorpiox-initContainer init binary — PID 1 inside containers
scorpiox-vmKVM virtual machine runner — direct kernel boot via KVM ioctls
scorpiox-wslWSL2 stateless execution
scorpiox-busyboxBusyBox applet manager
scorpiox-vault-gitGit repo offline backup
scorpiox-mirror-gitGit fleet mirror tool

Code Patterns

Pattern Detail
Memory Management Manual malloc/calloc/realloc/free — no arenas, some pool patterns. 176 pool refs, 121 malloc, 31 calloc, 51 realloc, 753 free calls in core libs.
String Handling Safe C string functions — snprintf (2064 calls), strncpy (543), strdup (390). Standard libc approach, no strlcpy.
Error Handling fprintf(stderr, ...) for error reporting (1384 calls), errno checking (354 refs), perror (23), exit() for fatal errors (76 calls).
JSON yyjson (vendored) for high-performance parsing, sx_json_yy wrapper layer in libsxutil, sx_json helpers in libsxnet.
HTTP libcurl for HTTP client, custom SSE streaming parser, WASM-specific HTTP via Emscripten fetch API.
TLS mbedTLS (vendored) for FRP crypto and email server TLS — avoids OpenSSL dependency.
Platform Abstraction sx_platform.h with compile-time #ifdef SX_LINUX/SX_MACOS/SX_WINDOWS/EMSCRIPTEN, runtime detection.
Provider Pattern Plugin-like multi-provider system — sx_provider.c dispatches to provider-specific implementations (Anthropic, OpenAI, Gemini, Claude Code, Codex, ScorpioX).
Logging Custom sx_log module with severity levels, file-based log output.

Build System

Build Tool
CMake 3.16+
C Standard
C11
Linking
Static
Targets
54 executables
Cross-compilation
ARM64, WASM, MinGW
Platforms
Linux, macOS, Windows, WASM

CMake Options

Option Description
SX_STATIC_LINK Build fully static executables (ON by default)
SX_CROSS_ARM64 Cross-compile for ARM64/aarch64
SX_BUILD_TESTS Build unit tests
SX_BUILD_DLL Build shared library for C# P/Invoke
SX_GENERATE_MODELS Generate model header from API

Design Principles

Line Count Breakdown

Directory Lines %
scorpiox/libsxutil/ 19,221 5.4%
scorpiox/libsxnet/ 21,149 6.0%
scorpiox/libsxui/ 11,092 3.1%
scorpiox/libsxbridge/ 524 0.1%
scorpiox/libtb4/ 1,022 0.3%
scorpiox/ (executables) 75,158 21.2%
bridge/ 1,229 0.3%
vendor/yyjson/ 19,556 5.5%
vendor/mbedtls/ 206,340 58.1%
Project code (excl. vendor) 129,395 36.4%
Total (with vendor) 355,291 100%