How achraf-farhat/octopus works
1. System shape
- Octopus is a containerized security-operations platform split into a React frontend, a FastAPI backend, and external security/AI services. The backend is the control plane that owns auth, business logic, persistence, and integration with Wazuh and the local LLM.
2. Frontend presentation layer
- frontend/src is a single-page app built with Vite + React and styled with Tailwind.
- Pages are domain-oriented: Dashboard, Incidents, Playbooks, Rules, ThreatHunt, Users, and Login.
- Shared UI components include alert tables, trend charts, AI explanation panels, permission gating, and route protection.
- context/AuthContext.jsx and lib/auth.js manage session state; lib/api.js is the API client boundary to the backend.
3. Frontend access control and session flow
- The frontend enforces route protection with ProtectedRoute and component-level authorization with PermissionGate.
- Login is a backend-issued JWT flow; refresh-token support is reflected in the backend model set.
- After authentication, the UI reads role/permission state from the auth context and selectively renders SOC functionality.
4. Backend API layer
- backend/app/main.py is the FastAPI entrypoint, with bootstrap.py handling startup wiring.
- API surface is split by domain routers: auth, users, alerts, incidents, rules, playbooks, threat_hunt, ai, and health.
- deps.py likely centralizes request dependencies such as current user, DB session, and RBAC checks.
5. Security and authorization boundary
- core/security.py and core/rbac.py define JWT handling and role-based access control.
- The README-defined roles are enforced across the API: Admin, SOC_Manager, SOC_L3, SOC_L2, SOC_L1.
- Security-sensitive state is persisted through refresh_token and audit_log models, which support token lifecycle and traceability.
6. Persistence layer
- PostgreSQL is the primary system of record, accessed through SQLAlchemy-style models in backend/app/models.
- The schema is domain-centric: alerts, incidents, custom rules, playbooks, playbook executions, AI analyses, search history, threat-hunt messages, users, refresh tokens, and audit logs.
- db/base.py and db/session.py form the database boundary; everything else depends on those shared primitives.
7. Security operations domain model
- Alerts and incidents represent operational detections and their triage lifecycle.
- Rules and custom rules model detection content and generated Wazuh XML rules.
- Playbooks and playbook executions represent response automation and execution history.
- Search history and threat-hunt messages capture analyst-driven investigation context over time.
8. AI subsystem
- services/ollama_client.py and services/ai_prompts.py connect the backend to the local Ollama-hosted LLM.
- The AI API is used for natural-language threat hunting, alert explanation, and rule generation.
- schemas/threat_hunt.py and related models indicate conversational workflows with persisted message history and analysis outputs.
9. External security integrations
- services/wazuh_client.py is the integration boundary to Wazuh Manager for querying security data and managing rules/agents.
- Suricata is part of the overall security stack from an architectural perspective, but it is external to this repo and likely feeds events into Wazuh.
- The backend sits between analysts and these systems, translating UI actions and natural language into operational queries and rule changes.
10. Async/background processing
- celery_app.py and tasks.py define asynchronous processing on top of Celery with Redis as broker/cache, matching the README.
- This layer is where alert correlation, risk scoring, and MITRE ATT&CK enrichment are offloaded so the API stays responsive.
- Background work produces persisted analysis artifacts that the frontend can later display.
11. Auditability and governance
- services/audit.py plus the audit_log model create an explicit audit trail for security actions and administrative changes.
- This is important because the platform can generate, explain, and deploy detection content; those actions need traceability and accountability.
12. Deployment/runtime boundaries
- The repo is designed for Docker Compose orchestration, with separate Dockerfiles for backend and frontend.
- The backend expects environment-based configuration (.env.example files); the frontend is built and served through Nginx in production.
- Runtime dependencies called out by the repo are PostgreSQL, Redis, a local Ollama instance, and external Wazuh connectivity.
13. Primary end-to-end data flows
- Analyst logs in through the React app → FastAPI auth issues JWT/refresh tokens → frontend stores session state.
- UI actions call domain routers → backend validates RBAC → persists or reads from PostgreSQL → optionally calls Wazuh or Ollama.
- Long-running enrichment/correlation jobs are queued to Celery → results are stored back in the database → frontend consumes them in dashboards and detail views.
14. How to draw the architecture
- Place the React SPA at the edge, the FastAPI backend in the center, PostgreSQL/Redis as internal infrastructure, and Wazuh/Ollama as external engines.
- Show the backend as the hub with distinct lanes for auth/security, SOC domain APIs, AI services, and async tasks.
- Represent PostgreSQL as the source of truth for users, incidents, alerts, rules, playbooks, audit logs, and AI/chat history.
Main entry points: routers Domain Routers · App.jsx Octopus UI · models Domain Models · tasks.py Async Tasks
Components 19
Frontend SPA
React/Vite analyst interface and client-side access control
- Octopus UI · Main analyst interface for SOC workflows
frontend/src/App.jsx - Domain Pages · Dashboard, incidents, playbooks, rules, threat hunt, users, login
frontend/src/pages - Shared UI · Tables, charts, explanation panels, route protection, permission gating
frontend/src/components - Session State · Auth context, JWT storage, and API client boundary
frontend/src/context/AuthContext.jsx
Backend API
FastAPI control plane, domain services, and persistence
- API Entry · Application bootstrap and server entrypoint
backend/app/main.py - Bootstrap · Startup configuration and dependency setup
backend/app/bootstrap.py - Domain Routers · Auth, users, alerts, incidents, rules, playbooks, threat hunt, AI, health
backend/app/routers - Security Core · JWT handling and role-based authorization
backend/app/core/security.py - Request Deps · Current user, DB session, and RBAC guards
backend/app/deps.py - Domain Models · Alerts, incidents, rules, playbooks, users, tokens, audits, and AI/chat history
backend/app/models - DB Boundary · SQLAlchemy base and session primitives
backend/app/db - AI Service · Prompts and Ollama client for explanation, hunting, and rule generation
backend/app/services/ollama_client.py - Wazuh Service · Query and manage Wazuh data and rules
backend/app/services/wazuh_client.py - Audit Service · Security action logging and traceability
backend/app/services/audit.py - Async Tasks · Background correlation, scoring, and enrichment work
backend/app/tasks.py
Runtime Infra
Shared data and background processing services
- PostgreSQL · Persistent store for operational and governance data
- Redis · Celery broker and cache runtime
External Engines
Third-party or out-of-repo security systems
- Ollama · Local model runtime used by backend AI features
- Wazuh Manager · External detection and rule management system
Connections 22
- Octopus UI → Domain Pages: renders · SPA routes to domain-specific screens
- Octopus UI → Shared UI: composes · Uses shared UI building blocks
- Octopus UI → Session State: uses · Reads session and permission state
- Session State → Domain Routers: calls API · Client API boundary into backend domains
- Domain Pages → Domain Routers: requests data · Dashboard and workflow screens fetch backend resources
- API Entry → Bootstrap: starts with · Entrypoint delegates startup wiring
- API Entry → Domain Routers: mounts · Registers domain API surface
- Domain Routers → Request Deps: guards with · Applies dependency-based auth and DB context
- Request Deps → Security Core: enforces · Current user and RBAC checks
- Domain Routers → Domain Models: reads/writes · Domain endpoints persist and fetch operational state
- Domain Models → DB Boundary: mapped on · Models sit on shared DB primitives
- DB Boundary → PostgreSQL: persists to · Primary database backend
- Domain Routers → Audit Service: records · Administrative and security actions are audited
- Audit Service → Domain Models: writes logs · Creates audit trail records
- Domain Routers → AI Service: invokes · AI explanations, hunting, and rule assistance
- AI Service → Ollama: queries · LLM inference boundary
- Domain Routers → Wazuh Service: integrates · Reads detections and manages rules/agents
- Wazuh Service → Wazuh Manager: talks to · External SOC platform integration
- Async Tasks → Redis: queued by · Celery broker/cache runtime
- Async Tasks → Domain Models: stores results · Background jobs persist analysis artifacts
- Domain Routers → Async Tasks: offloads · Long-running enrichment and correlation work
- Octopus UI → Domain Routers: consumes · UI drives backend workflows via API