Architecture

Component Architecture

aphrodite proxy binary (separate process)vendor/headroom-core (aphrodite-headroom-core)aphrodite core crate (rlib, linked into dylib + binary)libaphrodite_hermes.{dylib,so,dll}$HERMES_HOME/aphrodite (canonical runtime home)Hermes host processproxiesPython plugin (thin loader)register/invokeC-ABI ctypesfetch viadownload.sh(BINARY_VERSION-pinned)materialize builtinsunique-path copiesread/writeloadssubprocess:aphrodite(auto-launch)HTTP /healthHTTP/v1/chat/completionsHTTPHTTP forwardinline_storeHermes runtime(registers hooks/tools; skills are dev-side,never shipped)__init__.py ctypes shim_load_dylib · _probe_dylib · _call_json ·registerlayout_check · download.shbinaries/aphrodite + libaphrodite_hermes.{dylib,so,dll}(populated by explicit download.sh / aphroditesetup)directives/(materialized builtins)aphrodite.toml · ccr.db · proxy-stderr.logaphrodite-hermes (bridge crate)process-global STATE (OnceLock)dispatch_tool · call_hook · get_schemas/get_hooksversion · proxy_health · materialize_directiveshooks (transform_*, pre/post_llm_call)flow::build_turn_context (assembler)directives · session · catalogbuiltin_directives/*.md (embedded)marker · resolve · preview · stage2 ·struct_extractcore C-ABI: aphrodite_init/dispatch (HANDLES)CcrStore trait · compute_key (BLAKE3)SqliteCcrStoreInMemoryCcrStore (LRU+TTL)RedisCcrStore (compiled, no call site)main.rs · dual axum listeners:9797 cache proxy (InMemory CCR):9798 token proxy (Sqlite CCR)proxy_handler · compress_chat_completioninline_ccr LRU (1024) · response_cache LRUOpenAI/Anthropic-compatible clientUpstream LLM API (DeepSeek/OpenAI/...)HOT
ARCHITECTURE/10-COMPONENT

Top-level components and the two boundaries that matter: the C-ABI (Python shim ↔ Rust dylib) and the HTTP boundary (LLM clients / Hermes ↔ the two loopback proxies ↔ upstream API).

Runtime artifacts (binary, dylib, config, directives, logs) live in the canonical runtime home ~/.hermes/aphrodite - the plugin dir holds only the loader + downloader, and layout self-heal (layout_check.py + layout_schema.json) repairs any misplaced runtime state back to that home at startup.

aphrodite proxy binary (separate process)vendor/headroom-core (aphrodite-headroom-core)aphrodite core crate (rlib, linked into dylib + binary)libaphrodite_hermes.{dylib,so,dll}$HERMES_HOME/aphrodite (canonical runtime home)Hermes host processproxiesPython plugin (thin loader)register/invokeC-ABI ctypesfetch viadownload.sh(BINARY_VERSION-pinned)materialize builtinsunique-path copiesread/writeloadssubprocess:aphrodite(auto-launch)HTTP /healthHTTP/v1/chat/completionsHTTPHTTP forwardinline_storeHermes runtime(registers hooks/tools; skills are dev-side,never shipped)__init__.py ctypes shim_load_dylib · _probe_dylib · _call_json ·registerlayout_check · download.shbinaries/aphrodite + libaphrodite_hermes.{dylib,so,dll}(populated by explicit download.sh / aphroditesetup)directives/(materialized builtins)aphrodite.toml · ccr.db · proxy-stderr.logaphrodite-hermes (bridge crate)process-global STATE (OnceLock)dispatch_tool · call_hook · get_schemas/get_hooksversion · proxy_health · materialize_directiveshooks (transform_*, pre/post_llm_call)flow::build_turn_context (assembler)directives · session · catalogbuiltin_directives/*.md (embedded)marker · resolve · preview · stage2 ·struct_extractcore C-ABI: aphrodite_init/dispatch (HANDLES)CcrStore trait · compute_key (BLAKE3)SqliteCcrStoreInMemoryCcrStore (LRU+TTL)RedisCcrStore (compiled, no call site)main.rs · dual axum listeners:9797 cache proxy (InMemory CCR):9798 token proxy (Sqlite CCR)proxy_handler · compress_chat_completioninline_ccr LRU (1024) · response_cache LRUOpenAI/Anthropic-compatible clientUpstream LLM API (DeepSeek/OpenAI/...)HOT
ARCHITECTURE/10-COMPONENT

Boundary notes:

  • C-ABI (dashed ctypes edges): aphrodite-hermes exposes seven aphrodite_hermes_* process-global functions (dispatch, hooks, schemas, version, health, directives materialize - no skill export anymore); the core crate additionally exposes handle-based aphrodite_* functions (aphrodite_init + aphrodite_dispatch). Both guard panics so no unwind crosses FFI. Declarations come from the generated _bindings.py (cbindgen → ctypesgen), replayed onto the plugin’s CDLL handle by bind_to() with a manual restype fallback and a _REQUIRED_VOID_P completeness assertion.
  • HTTP boundary: clients and Hermes talk to the two loopback listeners; loopback_only + require_mgmt_token middleware gate the management routes, and a catch-all route forwards everything else to upstream.
  • Store backends: token proxy → SQLite, cache proxy → in-memory LRU; Redis is compiled in the vendored crate but wired by no build_state arm.
  • Runtime home vs plugin tree: the plugin is a pure loader. Every runtime artifact resolves from the ONE runtime-home decision shared by both halves (issue 40): $APHRODITE_HOME (the shim exports its own resolution there at import) → $HERMES_HOME + /aphrodite → ~/.hermes/aphrodite; the env overrides APHRODITE_BINARY_PATH / APHRODITE_HERMES_DYLIB_PATH take precedence for the binary/dylib paths. Plugin-dir binaries/ copies survive only as legacy fallbacks, and layout_check.py heals toward the same decision at register().
  • The core crate is linked into both the dylib (Hermes path) and the proxy binary - the marker/resolve/preview logic is shared, but the two run in separate processes with separate CCR state.