# gacwr/openuba architecture

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

- Interactive diagram: https://gitdiagram.com/gacwr/openuba
- Repository: https://github.com/gacwr/openuba

## Overview

#### Purpose and Entry Points
OpenUBA is a Kubernetes-native UEBA/security-analytics platform: ingest behavioral data, run inspectable ML models, evaluate detection rules, and manage anomalies, alerts, and cases. Primary application entry points are FastAPI in `core/fastapi_app.py`, the Next.js App Router in `interface/app/layout.tsx`, the Kubernetes controller in `core/operator/main.py`, and the Python SDK in `sdk/src/openuba/client.py`.

#### API, Identity, and Application Domain
The Python backend exposes REST APIs for models, datasets, jobs, rules, workspaces, anomalies, cases, and settings through router modules such as `core/api_routers/models.py`, `core/api_routers/pipelines.py`, and `core/api_routers/workspaces.py`. It applies JWT authentication/RBAC through `core/auth.py`; API schemas separate request/response contracts from persistence. Domain-facing services coordinate workflows rather than placing them in endpoints, notably `core/services/model_orchestrator.py`, `core/services/rule_engine.py`, and `core/services/workspace_service.py`.

#### System of Record and Query Boundary
PostgreSQL is the authoritative metadata store for users, model lifecycle, jobs, datasets, rules, anomalies, cases, and workspace records. SQLAlchemy models and repository layer form the persistence boundary: `core/db/models.py`, `core/database.py`, and `core/repositories/model_repository.py`. Schema evolution is managed through `alembic/env.py` and `alembic/versions/001_initial_schema.py`. PostGraphile exposes database-derived GraphQL, including subscription-oriented UI access, via `core/graphql/postgraphile.py` and `k8s/postgraphile-deployment.yaml`.

#### Data Ingestion and Analytics Stores
Ingestion services move configured datasets into compute/search backends: `core/services/data_ingestion.py`, `core/integrations/spark.py`, and `core/integrations/elasticsearch.py`. Models access data through pluggable loaders—local pandas files, Elasticsearch, Spark, and source groups—in `core/model_modules/local_pandas/local_pandas.py`, `core/model_modules/es/es.py`, and `core/model_modules/source_group/loader.py`. Spark supplies distributed compute and Elasticsearch supports searchable analytics; PostgreSQL retains platform metadata rather than replacing these data-plane systems.

#### Model Registry, Installation, and Execution
Model discovery/install is adapter-based, allowing local filesystem, GitHub, OpenUBA Hub, HuggingFace, and Kubeflow sources through `core/registry/registry_service.py`, `core/registry/adapters/github_adapter.py`, and `core/services/model_installer.py`. Installed model packages follow `MODEL.py` plus manifest conventions, represented by `core/model_library/basic_model/MODEL.py` and `core/model_library/basic_model/model.yaml`. Training/inference orchestration submits isolated executions; framework-specific runner images execute model code via `docker/model-runner/runner.py` and Dockerfiles under `docker/model-runner/`.

#### Kubernetes Execution and Workspaces
The custom Kopf operator watches training, inference, pipeline, and workspace CRDs, then creates ephemeral Jobs/pods instead of persistent per-model services. Control logic is in `core/operator/pipeline_handler.py` and `core/operator/workspace_handler.py`; resource contracts are in `k8s/crds/ubatraining.yaml`, `k8s/crds/ubainference.yaml`, and `k8s/crds/ubaworkspace-crd.yaml`. Shared persistent volumes bridge runners, artifacts, source code, and datasets. Managed notebook workspaces use the SDK (`sdk/src/openuba/context.py`) to register models, submit jobs, and publish visualizations.

#### Detection-to-Investigation Flow
Model inference produces scores/results that become platform anomalies; the rule engine evaluates deterministic rule graphs against model outputs and emits alerts, which can link to cases. Relevant boundaries are `core/services/rule_engine.py`, `core/api_routers/anomalies.py`, and `core/api_routers/cases.py`. Scheduling is centralized in `core/services/model_scheduler.py`. The frontend renders these operational workflows and talks primarily to GraphQL via `interface/src/lib/apollo-client.ts`, while REST handles command-style backend operations.

#### Deployment Topology
Containers deploy backend, frontend, operator, PostGraphile, PostgreSQL, Spark, and Elasticsearch to Kubernetes. Core manifests include `k8s/backend-deployment.yaml`, `k8s/operator-deployment.yaml`, and `k8s/spark-deployment.yaml`; Docker Compose supports a local topology in `docker-compose.yml`. The frontend is Next.js/TypeScript, the backend/operator/SDK are Python, and external LLM providers are mediated by `core/services/chat_service.py` (Ollama, OpenAI, Claude, Gemini).

Main entry points: [`core/fastapi_app.py`](https://github.com/gacwr/openuba/blob/master/core/fastapi_app.py) (FastAPI backend), [`core/services/model_orchestrator.py`](https://github.com/gacwr/openuba/blob/master/core/services/model_orchestrator.py) (Domain services), [`core/operator/main.py`](https://github.com/gacwr/openuba/blob/master/core/operator/main.py) (Kopf operator), [`docker/model-runner/runner.py`](https://github.com/gacwr/openuba/blob/master/docker/model-runner/runner.py) (Isolated model runners)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Platform API"]
  node_backend["FastAPI backend<br/>Python API<br/>[fastapi_app.py]"]
  node_auth["JWT &amp; RBAC<br/>identity<br/>[auth.py]"]
  node_domain["Domain services<br/>workflow services"]
  node_postgres[("PostgreSQL metadata<br/>system of record<br/>[database.py]")]
  node_repositories["Repository layer<br/>persistence boundary"]
  node_graphql["PostGraphile GraphQL<br/>query API<br/>[postgraphile.py]"]
end

subgraph group_data["Data &amp; Detection"]
  node_ingestion["Data ingestion<br/>data-plane service<br/>[data_ingestion.py]"]
  node_loaders["Pluggable data loaders<br/>model input<br/>[local_pandas.py]"]
  node_spark{{"Spark<br/>distributed compute<br/>[spark.py]"}}
  node_elasticsearch[("Elasticsearch<br/>analytics search<br/>[elasticsearch.py]")]
  node_rule_engine["Rule engine<br/>detection service<br/>[rule_engine.py]"]
  node_registry["Model registry<br/>adapter registry"]
end

subgraph group_execution["Kubernetes Execution"]
  node_scheduler["Model scheduler<br/>job scheduling<br/>[model_scheduler.py]"]
  node_operator{{"Kopf operator<br/>Kubernetes controller<br/>[main.py]"}}
  node_crds["OpenUBA CRDs<br/>Kubernetes contracts<br/>[ubatraining.yaml]"]
  node_runner["Isolated model runners<br/>ephemeral Jobs/pods<br/>[runner.py]"]
  node_workspaces["Managed workspaces<br/>notebook workloads"]
end

subgraph group_clients["Clients"]
  node_frontend["Next.js frontend<br/>operations UI<br/>[layout.tsx]"]
  node_sdk["Python SDK<br/>workspace client<br/>[client.py]"]
end

node_frontend -->|"queries and subscriptions"| node_graphql
node_frontend -->|"REST commands"| node_backend
node_backend -->|"authenticates"| node_auth
node_backend -->|"delegates workflows"| node_domain
node_domain -->|"persists platform state"| node_repositories
node_repositories -->|"SQLAlchemy access"| node_postgres
node_graphql -->|"database-derived schema"| node_postgres
node_ingestion -->|"loads distributed data"| node_spark
node_ingestion -->|"indexes analytics data"| node_elasticsearch
node_loaders -->|"reads compute data"| node_spark
node_loaders -->|"reads searchable data"| node_elasticsearch
node_registry -->|"installs model packages"| node_domain
node_domain -->|"schedules training and inference"| node_scheduler
node_scheduler -->|"submits custom resources"| node_operator
node_crds -->|"watched resources"| node_operator
node_operator -->|"creates ephemeral Jobs"| node_runner
node_operator -->|"creates workspace pods"| node_workspaces
node_runner -->|"loads model inputs"| node_loaders
node_runner -->|"emits inference results"| node_rule_engine
node_rule_engine -->|"records alerts and cases"| node_repositories
node_sdk -->|"registers models and submits jobs"| node_backend
node_sdk -->|"runs in notebooks"| node_workspaces

click node_backend "https://github.com/gacwr/openuba/blob/master/core/fastapi_app.py"
click node_auth "https://github.com/gacwr/openuba/blob/master/core/auth.py"
click node_domain "https://github.com/gacwr/openuba/blob/master/core/services/model_orchestrator.py"
click node_postgres "https://github.com/gacwr/openuba/blob/master/core/database.py"
click node_repositories "https://github.com/gacwr/openuba/blob/master/core/repositories/model_repository.py"
click node_graphql "https://github.com/gacwr/openuba/blob/master/core/graphql/postgraphile.py"
click node_ingestion "https://github.com/gacwr/openuba/blob/master/core/services/data_ingestion.py"
click node_loaders "https://github.com/gacwr/openuba/blob/master/core/model_modules/local_pandas/local_pandas.py"
click node_spark "https://github.com/gacwr/openuba/blob/master/core/integrations/spark.py"
click node_elasticsearch "https://github.com/gacwr/openuba/blob/master/core/integrations/elasticsearch.py"
click node_rule_engine "https://github.com/gacwr/openuba/blob/master/core/services/rule_engine.py"
click node_registry "https://github.com/gacwr/openuba/blob/master/core/registry/registry_service.py"
click node_scheduler "https://github.com/gacwr/openuba/blob/master/core/services/model_scheduler.py"
click node_operator "https://github.com/gacwr/openuba/blob/master/core/operator/main.py"
click node_crds "https://github.com/gacwr/openuba/blob/master/k8s/crds/ubatraining.yaml"
click node_runner "https://github.com/gacwr/openuba/blob/master/docker/model-runner/runner.py"
click node_workspaces "https://github.com/gacwr/openuba/blob/master/core/operator/workspace_handler.py"
click node_frontend "https://github.com/gacwr/openuba/blob/master/interface/app/layout.tsx"
click node_sdk "https://github.com/gacwr/openuba/blob/master/sdk/src/openuba/client.py"

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_backend,node_auth,node_domain,node_postgres,node_repositories,node_graphql toneBlue
class node_ingestion,node_loaders,node_spark,node_elasticsearch,node_rule_engine,node_registry toneAmber
class node_scheduler,node_operator,node_crds,node_runner,node_workspaces toneMint
class node_frontend,node_sdk toneRose
```

## Components

### Platform API

- [FastAPI backend](https://github.com/gacwr/openuba/blob/master/core/fastapi_app.py): Python API · REST command APIs and platform coordination. · `core/fastapi_app.py`
- [JWT & RBAC](https://github.com/gacwr/openuba/blob/master/core/auth.py): identity · `core/auth.py`
- [Domain services](https://github.com/gacwr/openuba/blob/master/core/services/model_orchestrator.py): workflow services · Coordinates model, rule, and workspace workflows. · `core/services/model_orchestrator.py`
- [PostgreSQL metadata](https://github.com/gacwr/openuba/blob/master/core/database.py): system of record · Authoritative platform metadata and investigation records. · `core/database.py`
- [Repository layer](https://github.com/gacwr/openuba/blob/master/core/repositories/model_repository.py): persistence boundary · `core/repositories/model_repository.py`
- [PostGraphile GraphQL](https://github.com/gacwr/openuba/blob/master/core/graphql/postgraphile.py): query API · Database-derived GraphQL with subscriptions. · `core/graphql/postgraphile.py`

### Data & Detection

- [Data ingestion](https://github.com/gacwr/openuba/blob/master/core/services/data_ingestion.py): data-plane service · `core/services/data_ingestion.py`
- [Pluggable data loaders](https://github.com/gacwr/openuba/blob/master/core/model_modules/local_pandas/local_pandas.py): model input · Loads local, Elasticsearch, Spark, and source-group data. · `core/model_modules/local_pandas/local_pandas.py`
- [Spark](https://github.com/gacwr/openuba/blob/master/core/integrations/spark.py): distributed compute · `core/integrations/spark.py`
- [Elasticsearch](https://github.com/gacwr/openuba/blob/master/core/integrations/elasticsearch.py): analytics search · `core/integrations/elasticsearch.py`
- [Rule engine](https://github.com/gacwr/openuba/blob/master/core/services/rule_engine.py): detection service · Evaluates rule graphs against model outputs. · `core/services/rule_engine.py`
- [Model registry](https://github.com/gacwr/openuba/blob/master/core/registry/registry_service.py): adapter registry · Discovers model packages from local and remote sources. · `core/registry/registry_service.py`

### Kubernetes Execution

- [Model scheduler](https://github.com/gacwr/openuba/blob/master/core/services/model_scheduler.py): job scheduling · `core/services/model_scheduler.py`
- [Kopf operator](https://github.com/gacwr/openuba/blob/master/core/operator/main.py): Kubernetes controller · Reconciles training, inference, pipeline, and workspace CRDs. · `core/operator/main.py`
- [OpenUBA CRDs](https://github.com/gacwr/openuba/blob/master/k8s/crds/ubatraining.yaml): Kubernetes contracts · `k8s/crds/ubatraining.yaml`
- [Isolated model runners](https://github.com/gacwr/openuba/blob/master/docker/model-runner/runner.py): ephemeral Jobs/pods · Framework-specific containers execute training and inference. · `docker/model-runner/runner.py`
- [Managed workspaces](https://github.com/gacwr/openuba/blob/master/core/operator/workspace_handler.py): notebook workloads · Notebook pods share data and artifacts with runners. · `core/operator/workspace_handler.py`

### Clients

- [Next.js frontend](https://github.com/gacwr/openuba/blob/master/interface/app/layout.tsx): operations UI · `interface/app/layout.tsx`
- [Python SDK](https://github.com/gacwr/openuba/blob/master/sdk/src/openuba/client.py): workspace client · `sdk/src/openuba/client.py`

## Connections

- Next.js frontend → PostGraphile GraphQL: queries and subscriptions
- Next.js frontend → FastAPI backend: REST commands
- FastAPI backend → JWT & RBAC: authenticates
- FastAPI backend → Domain services: delegates workflows
- Domain services → Repository layer: persists platform state
- Repository layer → PostgreSQL metadata: SQLAlchemy access
- PostGraphile GraphQL → PostgreSQL metadata: database-derived schema
- Data ingestion → Spark: loads distributed data
- Data ingestion → Elasticsearch: indexes analytics data
- Pluggable data loaders → Spark: reads compute data
- Pluggable data loaders → Elasticsearch: reads searchable data
- Model registry → Domain services: installs model packages
- Domain services → Model scheduler: schedules training and inference
- Model scheduler → Kopf operator: submits custom resources
- OpenUBA CRDs → Kopf operator: watched resources
- Kopf operator → Isolated model runners: creates ephemeral Jobs
- Kopf operator → Managed workspaces: creates workspace pods
- Isolated model runners → Pluggable data loaders: loads model inputs
- Isolated model runners → Rule engine: emits inference results
- Rule engine → Repository layer: records alerts and cases
- Python SDK → FastAPI backend: registers models and submits jobs
- Python SDK → Managed workspaces: runs in notebooks
