# galsakuri/homesoc architecture

> Architecture diagram of the GitHub repository galsakuri/homesoc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/galsakuri/homesoc
- Repository: https://github.com/galsakuri/homesoc

## Overview

1. **Overall shape**
   - HomeSOC is a three-part local SOC stack: a **macOS collection agent**, a **Python/FastAPI backend**, and a **React/TypeScript dashboard**.
   - The backend is the system of record: it stores events, evaluates detections, exposes APIs, and pushes live updates to the UI.

2. **macOS agent boundary**
   - `agents/macos` is a privileged endpoint collector that runs on the host Mac.
   - It is split into a small agent core plus collectors for different telemetry sources, including **Endpoint Security / `eslogger`** and **network observation**.
   - The agent sends batched security events to the backend over HTTP/JSON and periodically reports state/health so the backend can show agent status.

3. **Telemetry sources on the host**
   - The agent focuses on host-level security signals: process execution, file/system activity, auth-related activity, network connections, and other macOS events mentioned in the README.
   - This is important architecturally because the system is not scraping logs from a cloud service; it is gathering local machine telemetry at the endpoint boundary.

4. **Backend API surface**
   - `backend/api` is organized by domain: **events, alerts, agents, rules, auth, users, dashboard, setup, demo, websocket**.
   - The API serves both machine clients and the dashboard:
     - agents authenticate and submit events,
     - the dashboard reads data and manages settings,
     - WebSocket clients subscribe to live updates.

5. **Ingestion and persistence pipeline**
   - `backend/ingestion/pipeline.py` is the central event path.
   - Incoming agent events are normalized, filtered, and written through the repository layer into **SQLite** (`backend/db`).
   - The database layer is intentionally isolated behind `models.py`, `repository.py`, and `connection.py`, which makes the storage boundary clear for diagrams.

6. **Detection engine**
   - `backend/engine` contains the rule loader and detector.
   - Detection rules are stored as YAML in `backend/rules`, with built-in macOS-focused rules such as suspicious shell execution, outbound connections, privilege escalation, and brute-force auth.
   - The engine runs against ingested events and emits alerts when rules match; rules can be single-event or threshold-based.

7. **Alert delivery / async side effects**
   - Alert dispatch is separated from the main API path via `backend/worker`.
   - `redis_client.py` and `notifier.py` indicate a queue-backed worker model: detection results can be handed off to Redis and processed asynchronously for notifications.
   - Redis is optional in deployment, but when enabled it is the main decoupling point between detection and delivery.

8. **Dashboard boundary**
   - `dashboard/` is a standalone Vite React app served behind Nginx in its container.
   - It talks to the backend through the REST API and `dashboard/src/api/websocket.ts` for live event streaming.
   - The UI is split by concerns: dashboard overview, live feed, events table, alerts, agents, rules, settings, and setup guidance.

9. **Shared contracts**
   - `shared/` holds cross-cutting types and protocol/schema definitions used by multiple layers.
   - This is the repo’s contract boundary: it keeps agent/backend/dashboard payloads aligned and reduces drift in event and rule formats.

10. **Security and identity model**
    - The system uses **API-key auth** for agents and **JWT-based auth** for dashboard/user access.
    - The README’s setup flow and the backend modules suggest separate concerns for onboarding, user management, and authenticated operations.
    - This separation matters in diagrams: endpoint trust is different from human dashboard access.

11. **Operational configuration**
    - Runtime configuration is driven by `HOMESOC_*` environment variables, including API key, JWT secret, port, SQLite path, event retention, and Redis URL.
    - Deployment is containerized with `compose.yaml`, with separate Dockerfiles for backend and dashboard.
    - The backend is therefore a local-first service, not a cloud/SaaS architecture.

12. **Data flow summary**
    - The main flow is: **macOS agent collects events → backend ingests and stores them → detection engine evaluates rules → alerts are generated → WebSocket/API updates reach the dashboard → optional worker sends notifications**.
    - Per-agent settings loop back from the dashboard to the backend, affecting collector toggles, rule enablement, and whitelist filtering on the next heartbeat.

13. **Testing and support tooling**
    - `tests/` covers API behavior, refresh/retention logic, and related fixes.
    - `scripts/` includes dev/demo helpers and test-event generation, which supports local validation of the full pipeline.
    - `docs/runbooks` suggests the project is designed for reproducible local operations and troubleshooting rather than ad hoc use.

Main entry points: [`backend/api`](https://github.com/galsakuri/homesoc/tree/main/backend/api) (API router), [`dashboard/src/api/client.ts`](https://github.com/galsakuri/homesoc/blob/main/dashboard/src/api/client.ts) (API client), [`agents/common/transport.py`](https://github.com/galsakuri/homesoc/blob/main/agents/common/transport.py) (HTTP send), [`agents/macos/main.py`](https://github.com/galsakuri/homesoc/blob/main/agents/macos/main.py) (Agent core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_endpoint["macOS agent"]
  node_agent_main["Agent core<br/>macOS endpoint agent<br/>[main.py]"]
  node_agent_runtime["Agent shell<br/>agent runtime<br/>[base_agent.py]"]
  node_collector_es["ES logger<br/>telemetry collector<br/>[eslogger.py]"]
  node_collector_net["Network<br/>telemetry collector<br/>[network.py]"]
  node_agent_transport["HTTP send<br/>agent transport<br/>[transport.py]"]
end

subgraph group_backend["Backend"]
  node_api_surface["API router<br/>FastAPI routes"]
  node_api_ws["WebSocket<br/>live updates<br/>[ws.py]"]
  node_api_auth["Auth<br/>identity API<br/>[auth.py]"]
  node_ingestion["Pipeline<br/>ingestion flow<br/>[pipeline.py]"]
  node_detector["Detector<br/>rules engine<br/>[detector.py]"]
  node_rules_loader["Rules load<br/>rule loader<br/>[rules_loader.py]"]
  node_repo["Repository<br/>data access<br/>[repository.py]"]
  node_db[("SQLite<br/>local datastore<br/>[connection.py]")]
  node_worker["Worker<br/>async delivery<br/>[notifier.py]"]
  node_redis["Redis<br/>queue/cache<br/>[redis_client.py]"]
  node_rules["Rule pack<br/>YAML rules"]
end

subgraph group_dashboard["Dashboard"]
  node_ui_shell["UI shell<br/>React app<br/>[App.tsx]"]
  node_ui_views["Pages<br/>dashboard views"]
  node_ui_api["API client<br/>frontend data layer<br/>[client.ts]"]
end

subgraph group_shared["Shared & ops"]
  node_contracts["Contracts<br/>shared schemas<br/>[schemas.py]"]
  node_ops["Compose<br/>deployment<br/>[compose.yaml]"]
end

node_agent_main -->|"runs on"| node_agent_runtime
node_agent_main -->|"collects"| node_collector_es
node_agent_main -->|"collects"| node_collector_net
node_collector_es -->|"batches"| node_agent_transport
node_collector_net -->|"batches"| node_agent_transport
node_agent_transport -->|"POST events"| node_api_surface
node_api_auth -->|"protects"| node_api_surface
node_api_surface -->|"ingest"| node_ingestion
node_ingestion -->|"stores"| node_repo
node_repo -->|"persists"| node_db
node_ingestion -->|"evaluates"| node_detector
node_detector -->|"loads"| node_rules_loader
node_rules_loader -->|"reads"| node_rules
node_detector -->|"alerts"| node_worker
node_worker -->|"queues"| node_redis
node_api_surface -->|"streams"| node_api_ws
node_ui_shell -->|"composes"| node_ui_views
node_ui_shell -->|"fetches"| node_ui_api
node_ui_api -->|"reads/writes"| node_api_surface
node_ui_api -->|"subscribes"| node_api_ws
node_contracts -.->|"aligns"| node_agent_transport
node_contracts -.->|"aligns"| node_api_surface
node_contracts -.->|"aligns"| node_ui_api
node_ops -->|"deploys"| node_api_surface
node_ops -->|"deploys"| node_ui_shell

click node_agent_main "https://github.com/galsakuri/homesoc/blob/main/agents/macos/main.py"
click node_agent_runtime "https://github.com/galsakuri/homesoc/blob/main/agents/common/base_agent.py"
click node_collector_es "https://github.com/galsakuri/homesoc/blob/main/agents/macos/collectors/eslogger.py"
click node_collector_net "https://github.com/galsakuri/homesoc/blob/main/agents/macos/collectors/network.py"
click node_agent_transport "https://github.com/galsakuri/homesoc/blob/main/agents/common/transport.py"
click node_api_surface "https://github.com/galsakuri/homesoc/tree/main/backend/api"
click node_api_ws "https://github.com/galsakuri/homesoc/blob/main/backend/api/ws.py"
click node_api_auth "https://github.com/galsakuri/homesoc/blob/main/backend/api/auth.py"
click node_ingestion "https://github.com/galsakuri/homesoc/blob/main/backend/ingestion/pipeline.py"
click node_detector "https://github.com/galsakuri/homesoc/blob/main/backend/engine/detector.py"
click node_rules_loader "https://github.com/galsakuri/homesoc/blob/main/backend/engine/rules_loader.py"
click node_repo "https://github.com/galsakuri/homesoc/blob/main/backend/db/repository.py"
click node_db "https://github.com/galsakuri/homesoc/blob/main/backend/db/connection.py"
click node_worker "https://github.com/galsakuri/homesoc/blob/main/backend/worker/notifier.py"
click node_redis "https://github.com/galsakuri/homesoc/blob/main/backend/worker/redis_client.py"
click node_rules "https://github.com/galsakuri/homesoc/tree/main/backend/rules"
click node_ui_shell "https://github.com/galsakuri/homesoc/blob/main/dashboard/src/App.tsx"
click node_ui_views "https://github.com/galsakuri/homesoc/tree/main/dashboard/src/pages"
click node_ui_api "https://github.com/galsakuri/homesoc/blob/main/dashboard/src/api/client.ts"
click node_contracts "https://github.com/galsakuri/homesoc/blob/main/shared/schemas.py"
click node_ops "https://github.com/galsakuri/homesoc/blob/main/compose.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent_main,node_agent_runtime,node_collector_es,node_collector_net,node_agent_transport toneBlue
class node_api_surface,node_api_ws,node_api_auth,node_ingestion,node_detector,node_rules_loader,node_repo,node_db,node_worker,node_redis,node_rules toneAmber
class node_ui_shell,node_ui_views,node_ui_api toneMint
class node_contracts,node_ops toneRose
```

## Components

### macOS agent

Privileged local telemetry collector on the host Mac.

- [Agent core](https://github.com/galsakuri/homesoc/blob/main/agents/macos/main.py): macOS endpoint agent · Entry point and coordination layer for the host collector. · `agents/macos/main.py`
- [Agent shell](https://github.com/galsakuri/homesoc/blob/main/agents/common/base_agent.py): agent runtime · Shared agent base and transport integration. · `agents/common/base_agent.py`
- [ES logger](https://github.com/galsakuri/homesoc/blob/main/agents/macos/collectors/eslogger.py): telemetry collector · Endpoint Security and process/system activity collection. · `agents/macos/collectors/eslogger.py`
- [Network](https://github.com/galsakuri/homesoc/blob/main/agents/macos/collectors/network.py): telemetry collector · Network observation and connection telemetry collection. · `agents/macos/collectors/network.py`
- [HTTP send](https://github.com/galsakuri/homesoc/blob/main/agents/common/transport.py): agent transport · Batched JSON delivery of security events and health state. · `agents/common/transport.py`

### Backend

FastAPI service that ingests, detects, stores, and serves data.

- [API router](https://github.com/galsakuri/homesoc/tree/main/backend/api): FastAPI routes · Domain API surface for agents, alerts, events, auth, users, setup, demo, and dashboard. · `backend/api`
- [WebSocket](https://github.com/galsakuri/homesoc/blob/main/backend/api/ws.py): live updates · Push channel for dashboard and streaming clients. · `backend/api/ws.py`
- [Auth](https://github.com/galsakuri/homesoc/blob/main/backend/api/auth.py): identity API · API-key and JWT authentication boundary. · `backend/api/auth.py`
- [Pipeline](https://github.com/galsakuri/homesoc/blob/main/backend/ingestion/pipeline.py): ingestion flow · Normalizes, filters, and routes incoming agent events. · `backend/ingestion/pipeline.py`
- [Detector](https://github.com/galsakuri/homesoc/blob/main/backend/engine/detector.py): rules engine · Evaluates ingested events against macOS detection rules. · `backend/engine/detector.py`
- [Rules load](https://github.com/galsakuri/homesoc/blob/main/backend/engine/rules_loader.py): rule loader · Loads YAML rule definitions into the detection engine. · `backend/engine/rules_loader.py`
- [Repository](https://github.com/galsakuri/homesoc/blob/main/backend/db/repository.py): data access · Storage abstraction over event, alert, agent, and user records. · `backend/db/repository.py`
- [SQLite](https://github.com/galsakuri/homesoc/blob/main/backend/db/connection.py): local datastore · System of record for persisted events and derived state. · `backend/db/connection.py`
- [Worker](https://github.com/galsakuri/homesoc/blob/main/backend/worker/notifier.py): async delivery · Background side effects and notification dispatch. · `backend/worker/notifier.py`
- [Redis](https://github.com/galsakuri/homesoc/blob/main/backend/worker/redis_client.py): queue/cache · Optional queue-backed decoupling point for alert delivery. · `backend/worker/redis_client.py`
- [Rule pack](https://github.com/galsakuri/homesoc/tree/main/backend/rules): YAML rules · Built-in macOS-focused detection rules. · `backend/rules`

### Dashboard

Standalone React UI for local SOC monitoring and control.

- [UI shell](https://github.com/galsakuri/homesoc/blob/main/dashboard/src/App.tsx): React app · Main dashboard application and layout composition. · `dashboard/src/App.tsx`
- [Pages](https://github.com/galsakuri/homesoc/tree/main/dashboard/src/pages): dashboard views · Dashboard, events, alerts, agents, rules, settings, and guide screens. · `dashboard/src/pages`
- [API client](https://github.com/galsakuri/homesoc/blob/main/dashboard/src/api/client.ts): frontend data layer · REST client and WebSocket subscription hooks. · `dashboard/src/api/client.ts`

### Shared & ops

Cross-cutting contracts and deployment/support tooling.

- [Contracts](https://github.com/galsakuri/homesoc/blob/main/shared/schemas.py): shared schemas · Cross-layer enums, protocol definitions, and payload schemas. · `shared/schemas.py`
- [Compose](https://github.com/galsakuri/homesoc/blob/main/compose.yaml): deployment · Containerized local deployment and service orchestration. · `compose.yaml`

## Connections

- Agent core → Agent shell: runs on · Main agent entry uses the shared base runtime.
- Agent core → ES logger: collects · Coordinates Endpoint Security telemetry collection.
- Agent core → Network: collects · Coordinates network observation collection.
- ES logger → HTTP send: batches · Collected events are handed to the transport layer.
- Network → HTTP send: batches · Network events are handed to the transport layer.
- HTTP send → API router: POST events · Sends batched events and health state to the backend API.
- Auth → API router: protects · Authentication gates machine and human API access.
- API router → Pipeline: ingest · Incoming agent events flow into the central pipeline.
- Pipeline → Repository: stores · Normalized events and derived records are written through the repository.
- Repository → SQLite: persists · Repository talks to the SQLite storage layer.
- Pipeline → Detector: evaluates · Events are passed into the detection engine.
- Detector → Rules load: loads · Detection uses the YAML rule pack.
- Rules load → Rule pack: reads · Rule definitions are sourced from backend/rules.
- Detector → Worker: alerts · Detection results can trigger async side effects.
- Worker → Redis: queues · Optional queue-backed handoff for notifications.
- API router → WebSocket: streams · API publishes live updates over WebSocket.
- UI shell → Pages: composes · Application shell hosts the major dashboard pages.
- UI shell → API client: fetches · Dashboard uses REST and WebSocket client code.
- API client → API router: reads/writes · Frontend data layer talks to backend REST endpoints.
- API client → WebSocket: subscribes · Frontend subscribes to live updates.
- Contracts → HTTP send: aligns · Shared payload contracts keep agent messages consistent.
- Contracts → API router: aligns · Backend API models follow the shared schemas.
- Contracts → API client: aligns · Frontend types and API parsing follow the shared contracts.
- Compose → API router: deploys · Compose defines backend runtime wiring.
- Compose → UI shell: deploys · Compose and containers serve the dashboard build.
