How ixi-enki/ferngeist works
1. Overall shape
Ferngeist is a modular Android client for ACP-compatible coding agents. The APK is split into an app shell plus feature, bridge, gateway, data, and shared-core modules. The main architectural goal is to keep UI, persisted state, and ACP transport concerns separated.
2. App shell and composition root
app/ is the Android entry point: it owns MainActivity, the application class, Hilt wiring, theme setup, and the foreground service used to keep agent connections alive. It does not contain the core domain logic; it assembles the modules and drives navigation.
3. Shared contracts and domain models
core/model/ defines the app-wide abstractions: chat/domain models, server/session models, repository interfaces, and lightweight stores such as recent CWD and recent selection. This module is the boundary between UI/logic and persistence, so feature modules talk to interfaces rather than database classes.
4. Shared UI and common utilities
core/common/ contains reusable Compose UI pieces and a shared MviViewModel base. It also holds UI-specific helpers like connection diagnostics and shared-bounds keys used across screens. This is the common presentation layer used by multiple features.
5. Persistence subsystem
data/database/ is the local persistence implementation. It provides the Room database, DAOs, entities, encryption helpers, and repository implementations for servers, sessions, gateway bindings, and target session settings. Its role is to implement the core/model repository contracts and store app state locally.
6. Gateway client subsystem
gateway-client/ encapsulates communication with the optional Ferngeist ACP Gateway. It handles pairing payload parsing, URL resolution, credential refresh, proof-based auth, and repository calls to the gateway’s REST endpoint. This module exists so the rest of the app does not need to know gateway-specific protocol details.
7. ACP bridge and session orchestration
acp-bridge/ is the transport/session layer that connects the app to ACP agents. It includes connection management, diagnostics, permissions/connectivity handling, auth header building, session registry/update mapping, and a session state engine/reducer. The bridge exposes a chat-session facade that the features can use without dealing with raw transport callbacks.
8. Feature modules
feature/serverlist/ manages saved servers, gateways, pairing/auth data, and consent for launching agents.
feature/sessionlist/ manages session discovery and the user’s recent working directory.
feature/chat/ renders the live chat experience, including message streaming, markdown state, scroll behavior, tool-call rendering, and session coordination.
Each feature module owns its own ViewModels, Compose screens, and small local stores.
9. Primary data flows
User actions start in Compose screens, flow into feature ViewModels, then into shared repositories/stores and the ACP bridge. Persisted server/session/gateway state comes from Room/DataStore implementations in data/database and feature-local stores. When a chat starts, the bridge streams ACP updates back into the chat reducer/ViewModel, which updates the UI incrementally.
10. Connection modes
Ferngeist supports two connection paths: direct/manual ACP servers over WebSocket, and gateway-backed local agents through the optional Ferngeist ACP Gateway. The gateway path adds pairing, auth, and URL resolution before the ACP session is opened; the manual path connects directly to the agent endpoint via the ACP SDK.
11. Android-specific runtime concerns
The app includes a foreground service and battery-optimization helpers, indicating the connection may need to survive backgrounding. Network/security and localization resources are bundled in the app, and the project targets Android 13+.
12. Boundaries to draw in an architecture diagram
The clearest boundaries are: UI/features vs shared contracts, contracts vs persistence implementations, app vs background/runtime services, and app vs external ACP/Gateway services. The ACP bridge and gateway client are the two key integration layers between the Android UI and the outside agent ecosystem.
Main entry points: AcpChatSessionFacade.kt ACP bridge · MainActivity.kt App · ServerListViewModel.kt Servers · ServerRepositoryImpl.kt Repos impl
Components 16
App shell
Android entry point, dependency wiring, and runtime services.
- App · Composition root with application, activity, DI, theme, and foreground service.
app/src/main/kotlin/com/tamimarafat/ferngeist/MainActivity.kt - Foreground svc · Keeps agent connections alive in backgrounded app states.
app/src/main/kotlin/com/tamimarafat/ferngeist/service/FerngeistForegroundService.kt - Battery help · Battery optimization prompts, preferences, and controller support.
app/src/main/kotlin/com/tamimarafat/ferngeist/service/BatteryOptimizationHelper.kt
Shared core
App-wide contracts, models, and reusable presentation utilities.
- Models · Chat, server, session, gateway-binding models and repository/store interfaces.
core/model/src/main/kotlin/com/tamimarafat/ferngeist/core/model/ChatDomainModels.kt - Common UI · Reusable Compose widgets and shared MVI base view model.
core/common/src/main/kotlin/com/tamimarafat/ferngeist/core/common/MviViewModel.kt
Persistence
Local database, entities, DAOs, and repository implementations.
- Database · Room database entry point for local state storage.
data/database/src/main/kotlin/com/tamimarafat/ferngeist/data/database/FerngeistDatabase.kt - Repos impl · Repository implementations bridging contracts to local persistence.
data/database/src/main/kotlin/com/tamimarafat/ferngeist/data/database/repository/ServerRepositoryImpl.kt - DAOs · Entities and DAOs for servers, sessions, gateways, and launch settings.
data/database/src/main/kotlin/com/tamimarafat/ferngeist/data/database/dao/ServerDao.kt - Crypto · Credential encryption helpers used by persisted auth data.
data/database/src/main/kotlin/com/tamimarafat/ferngeist/data/database/crypto/CredentialEncryptor.kt
Integrations
ACP bridge and optional Ferngeist gateway client.
- ACP bridge · Session orchestration, connection management, diagnostics, and chat-session facade.
acp-bridge/src/main/kotlin/com/tamimarafat/ferngeist/acp/bridge/facade/AcpChatSessionFacade.kt - Session engine · Reducer, runtime, snapshot, and registry for ACP session updates.
acp-bridge/src/main/kotlin/com/tamimarafat/ferngeist/acp/bridge/session/SessionStateEngine.kt - Connection · Connection manager, orchestrator, auth headers, permissions, and connectivity diagnostics.
acp-bridge/src/main/kotlin/com/tamimarafat/ferngeist/acp/bridge/connection/ConnectionOrchestrator.kt - Gateway client · Optional Ferngeist ACP Gateway client for pairing, proof auth, and URL resolution.
gateway-client/src/main/kotlin/com/tamimarafat/ferngeist/gateway/GatewayRepositoryImpl.kt
Feature modules
User-facing screens and their view models.
- Servers · Saved servers, gateways, pairing data, and launch consent flows.
feature/serverlist/src/main/kotlin/com/tamimarafat/ferngeist/feature/serverlist/ServerListViewModel.kt - Sessions · Session discovery and recent working-directory selection.
feature/sessionlist/src/main/kotlin/com/tamimarafat/ferngeist/feature/sessionlist/SessionListViewModel.kt - Chat · Live chat screen, streaming updates, markdown state, and tool-call rendering.
feature/chat/src/main/kotlin/com/tamimarafat/ferngeist/feature/chat/ChatViewModel.kt
Connections 24
- App → Servers: navigates to · App shell hosts the server management entry points.
- App → Sessions: navigates to · App shell routes into session selection and discovery.
- App → Chat: hosts · App shell launches the live chat experience.
- App → Foreground svc: starts · Foreground service is managed by the app runtime.
- App → Battery help: uses · Battery-optimization helpers support background longevity.
- Servers → Models: uses · Feature logic depends on shared domain models and repository contracts.
- Sessions → Models: uses · Recent CWD and session-related contracts are shared through core models.
- Chat → Models: uses · Chat UI and reducers consume shared chat/session domain types.
- Servers → Gateway client: calls · Gateway setup, pairing, and auth flows are delegated to the gateway client.
- Servers → Repos impl: persists via · Saved server and gateway state is stored through repository implementations.
- Sessions → Repos impl: persists via · Recent working-directory and session state are stored locally.
- Chat → ACP bridge: streams via · Chat session coordination relies on the ACP bridge facade.
- Chat → Common UI: renders with · Shared UI primitives and MVI base support the chat experience.
- Servers → Common UI: renders with · Common Compose widgets and state helpers are reused in server screens.
- Sessions → Common UI: renders with · Shared UI primitives are reused in session-related screens.
- Repos impl → Database: implements · Repository adapters are backed by the Room database.
- Repos impl → DAOs: reads/writes · Data access flows through DAOs and entity mappings.
- Repos impl → Crypto: secures · Encrypted storage is used for sensitive credential-like values.
- ACP bridge → Session engine: orchestrates · The bridge coordinates session state, updates, and lifecycle.
- ACP bridge → Connection: opens · Transport setup and connection management are handled in the bridge layer.
- ACP bridge → Gateway client: integrates with · Gateway-backed sessions depend on pairing and auth support from the gateway client.
- ACP bridge → Models: adapts · Bridge-facing session and chat types align with shared contracts.
- Gateway client → Models: returns · Gateway repository results map into shared domain models.
- Foreground svc → ACP bridge: keeps alive · Foreground runtime support protects active ACP connections.