# zoyaumar/kubernetes-ops-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/zoyaumar/kubernetes-ops-assistant
- Repository: https://github.com/zoyaumar/kubernetes-ops-assistant

## Overview

#### Purpose and system shape
Kubernetes Ops Assistant is an event-driven, Kubernetes-native RAG system: it captures cluster events/logs, indexes evidence in PostgreSQL/pgvector, and answers incident questions with cited LLM responses. The main executable services are the watcher, indexer, and Node/TypeScript API; React is the user entry point.

#### Cluster ingestion boundary
The watcher is the boundary to the Kubernetes API. It uses a least-privilege Kubernetes client to observe deployments, pods, events, and logs, normalizes them into shared cluster-event schemas, and publishes them to NATS JetStream.
- `apps/watcher/app/main.py`
- `apps/watcher/app/watchers/pods.py`
- `apps/watcher/app/publishers/nats_publisher.py`

#### Durable event transport and scaling
NATS JetStream decouples cluster observation from indexing. The consumer model is at-least-once: messages are only acknowledged after persistence, so failures trigger redelivery. The indexer is intended to be KEDA-scaled from queue backlog; failed messages have a DLQ handling path.
- `apps/indexer/app/consumers/nats_consumer.py`
- `apps/indexer/app/dlq/handler.py`
- `k8s/keda/indexer-scaledobject.yaml`

#### Indexing and persistence pipeline
The Python indexer consumes cluster events, normalizes, deduplicates, chunks text, generates local embeddings, and writes event/conversation-related evidence and vectors to PostgreSQL with pgvector. Database uniqueness plus stable event identity make redelivery idempotent.
- `apps/indexer/app/main.py`
- `apps/indexer/app/processing/deduplicate.py`
- `apps/indexer/app/repositories/embeddings.py`
- `db/schema.sql`

#### API and RAG orchestration
The Node API is the synchronous application boundary for clients. Chat routes invoke a RAG orchestrator that combines structured filtering, time-aware retrieval, vector similarity, ranking, prompt construction, citation formatting, and an LLM provider. API routes also expose auth, conversation, cluster, and health concerns.
- `apps/api/src/server.ts`
- `apps/api/src/routes/chat.ts`
- `apps/api/src/rag/orchestrator.ts`
- `apps/api/src/rag/retrieval.ts`

#### Model-provider boundaries
Generation is behind a provider interface, with Groq and mock implementations; embeddings are independently abstracted in the indexer and currently support a local provider. This separates the retrieval/prompt pipeline from external LLM availability and model choices.
- `apps/api/src/llm/provider.ts`
- `apps/api/src/llm/groq.ts`
- `apps/indexer/app/embeddings/provider.py`

#### User access and deployment platform
The React/Vite frontend calls the API; API middleware supplies authentication, request IDs, and centralized errors. Services are containerized and deployed to kind/Kubernetes alongside PostgreSQL, NATS, RBAC/service accounts, and service manifests. Prometheus, Grafana, and OpenTelemetry are provisioned for observability.
- `frontend/src/app/App.tsx`
- `apps/api/src/middleware/auth.ts`
- `k8s/base/rbac.yaml`
- `k8s/observability/otel-collector.yaml`

Main entry points: [`apps/watcher/app/main.py`](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/main.py) (Watcher), [`apps/indexer/app/main.py`](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/main.py) (Indexer), [`apps/api/src/server.ts`](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/server.ts) (Node API), [`apps/indexer/app/consumers/nats_consumer.py`](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/consumers/nats_consumer.py) (JetStream consumer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cluster["Cluster ingestion"]
  node_kubernetes{{"Kubernetes API<br/>cluster API"}}
  node_watcher["Watcher<br/>Python service<br/>[main.py]"]
  node_pod_watcher["Pod watcher<br/>watcher module<br/>[pods.py]"]
  node_rbac["RBAC and service account<br/>Kubernetes access policy<br/>[rbac.yaml]"]
  node_nats_publisher["NATS publisher<br/>publisher module<br/>[nats_publisher.py]"]
end

subgraph group_pipeline["Event pipeline"]
  node_jetstream["NATS JetStream<br/>durable event transport"]
  node_indexer["Indexer<br/>Python worker<br/>[main.py]"]
  node_consumer["JetStream consumer<br/>consumer module<br/>[nats_consumer.py]"]
  node_indexing_pipeline["Evidence processing<br/>normalization and chunking<br/>[deduplicate.py]"]
  node_embedding_provider["Embedding provider<br/>embedding interface<br/>[provider.py]"]
  node_dlq["DLQ handler<br/>failure handler<br/>[handler.py]"]
end

subgraph group_application["Application and RAG"]
  node_frontend["React frontend<br/>user interface<br/>[App.tsx]"]
  node_api["Node API<br/>synchronous application boundary<br/>[server.ts]"]
  node_api_middleware["API middleware<br/>auth and request handling<br/>[auth.ts]"]
  node_chat_routes["Chat routes<br/>API route<br/>[chat.ts]"]
  node_rag["RAG orchestrator<br/>retrieval and response pipeline<br/>[orchestrator.ts]"]
  node_retrieval["Retrieval<br/>vector and temporal search<br/>[retrieval.ts]"]
  node_llm_provider["LLM provider interface<br/>generation boundary<br/>[provider.ts]"]
  node_groq["Groq provider<br/>LLM implementation<br/>[groq.ts]"]
end

subgraph group_platform["Platform services"]
  node_postgres[("PostgreSQL + pgvector<br/>evidence store<br/>[schema.sql]")]
  node_keda["KEDA scaler<br/>autoscaling policy"]
  node_observability["OpenTelemetry collector<br/>telemetry pipeline"]
end

node_rbac -.->|"authorizes"| node_watcher
node_kubernetes -->|"pods and events"| node_pod_watcher
node_pod_watcher -->|"normalized observations"| node_watcher
node_watcher -->|"cluster events"| node_nats_publisher
node_nats_publisher -->|"publishes"| node_jetstream
node_jetstream -->|"durable delivery"| node_consumer
node_consumer -->|"messages"| node_indexer
node_indexer -->|"processes"| node_indexing_pipeline
node_indexing_pipeline -->|"chunks"| node_embedding_provider
node_embedding_provider -->|"vectors"| node_postgres
node_indexing_pipeline -->|"idempotent evidence"| node_postgres
node_consumer -.->|"failed messages"| node_dlq
node_keda -.->|"scales on backlog"| node_indexer
node_frontend -->|"client requests"| node_api
node_api_middleware -->|"protects"| node_api
node_api -->|"routes chat"| node_chat_routes
node_chat_routes -->|"questions"| node_rag
node_rag -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"filtered vector search"| node_postgres
node_rag -->|"generation request"| node_llm_provider
node_llm_provider -->|"implementation"| node_groq
node_watcher -.->|"telemetry"| node_observability
node_indexer -.->|"telemetry"| node_observability
node_api -.->|"telemetry"| node_observability

click node_watcher "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/main.py"
click node_pod_watcher "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/watchers/pods.py"
click node_rbac "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/base/rbac.yaml"
click node_nats_publisher "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/publishers/nats_publisher.py"
click node_indexer "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/main.py"
click node_consumer "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/consumers/nats_consumer.py"
click node_indexing_pipeline "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/processing/deduplicate.py"
click node_embedding_provider "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/embeddings/provider.py"
click node_postgres "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/db/schema.sql"
click node_dlq "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/dlq/handler.py"
click node_keda "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/keda/indexer-scaledobject.yaml"
click node_frontend "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/frontend/src/app/App.tsx"
click node_api "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/server.ts"
click node_api_middleware "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/middleware/auth.ts"
click node_chat_routes "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/routes/chat.ts"
click node_rag "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/rag/orchestrator.ts"
click node_retrieval "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/rag/retrieval.ts"
click node_llm_provider "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/llm/provider.ts"
click node_groq "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/llm/groq.ts"
click node_observability "https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/observability/otel-collector.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_kubernetes,node_watcher,node_pod_watcher,node_rbac,node_nats_publisher toneBlue
class node_jetstream,node_indexer,node_consumer,node_indexing_pipeline,node_embedding_provider,node_dlq toneAmber
class node_frontend,node_api,node_api_middleware,node_chat_routes,node_rag,node_retrieval,node_llm_provider,node_groq toneMint
class node_postgres,node_keda,node_observability toneRose
```

## Components

### Cluster ingestion

- **Kubernetes API**: cluster API · Deployments, pods, events, and logs.
- [Watcher](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/main.py): Python service · Observes and normalizes cluster evidence. · `apps/watcher/app/main.py`
- [Pod watcher](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/watchers/pods.py): watcher module · `apps/watcher/app/watchers/pods.py`
- [RBAC and service account](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/base/rbac.yaml): Kubernetes access policy · Least-privilege access for cluster observation. · `k8s/base/rbac.yaml`
- [NATS publisher](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/watcher/app/publishers/nats_publisher.py): publisher module · `apps/watcher/app/publishers/nats_publisher.py`

### Event pipeline

- **NATS JetStream**: durable event transport · At-least-once delivery decouples observation from indexing.
- [Indexer](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/main.py): Python worker · Persists idempotent evidence and vector records. · `apps/indexer/app/main.py`
- [JetStream consumer](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/consumers/nats_consumer.py): consumer module · Acknowledges only after persistence. · `apps/indexer/app/consumers/nats_consumer.py`
- [Evidence processing](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/processing/deduplicate.py): normalization and chunking · Deduplicates events, chunks text, and creates stable evidence. · `apps/indexer/app/processing/deduplicate.py`
- [Embedding provider](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/embeddings/provider.py): embedding interface · Local embeddings are generated independently of LLM generation. · `apps/indexer/app/embeddings/provider.py`
- [DLQ handler](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/indexer/app/dlq/handler.py): failure handler · Handles messages that cannot be indexed. · `apps/indexer/app/dlq/handler.py`

### Application and RAG

- [React frontend](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/frontend/src/app/App.tsx): user interface · `frontend/src/app/App.tsx`
- [Node API](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/server.ts): synchronous application boundary · Exposes chat, auth, conversations, cluster, and health routes. · `apps/api/src/server.ts`
- [API middleware](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/middleware/auth.ts): auth and request handling · Supplies authentication, request IDs, and centralized errors. · `apps/api/src/middleware/auth.ts`
- [Chat routes](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/routes/chat.ts): API route · `apps/api/src/routes/chat.ts`
- [RAG orchestrator](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/rag/orchestrator.ts): retrieval and response pipeline · Builds ranked, cited answers from filtered evidence. · `apps/api/src/rag/orchestrator.ts`
- [Retrieval](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/rag/retrieval.ts): vector and temporal search · `apps/api/src/rag/retrieval.ts`
- [LLM provider interface](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/llm/provider.ts): generation boundary · Supports Groq and mock implementations. · `apps/api/src/llm/provider.ts`
- [Groq provider](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/apps/api/src/llm/groq.ts): LLM implementation · `apps/api/src/llm/groq.ts`

### Platform services

- [PostgreSQL + pgvector](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/db/schema.sql): evidence store · Stores evidence, conversations, and vectors with uniqueness constraints. · `db/schema.sql`
- [KEDA scaler](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/keda/indexer-scaledobject.yaml): autoscaling policy · Scales indexers from queue backlog. · `k8s/keda/indexer-scaledobject.yaml`
- [OpenTelemetry collector](https://github.com/zoyaumar/kubernetes-ops-assistant/blob/main/k8s/observability/otel-collector.yaml): telemetry pipeline · Feeds provisioned observability tooling. · `k8s/observability/otel-collector.yaml`

## Connections

- RBAC and service account → Watcher: authorizes
- Kubernetes API → Pod watcher: pods and events
- Pod watcher → Watcher: normalized observations
- Watcher → NATS publisher: cluster events
- NATS publisher → NATS JetStream: publishes
- NATS JetStream → JetStream consumer: durable delivery
- JetStream consumer → Indexer: messages
- Indexer → Evidence processing: processes
- Evidence processing → Embedding provider: chunks
- Embedding provider → PostgreSQL + pgvector: vectors
- Evidence processing → PostgreSQL + pgvector: idempotent evidence
- JetStream consumer → DLQ handler: failed messages
- KEDA scaler → Indexer: scales on backlog
- React frontend → Node API: client requests
- API middleware → Node API: protects
- Node API → Chat routes: routes chat
- Chat routes → RAG orchestrator: questions
- RAG orchestrator → Retrieval: retrieves evidence
- Retrieval → PostgreSQL + pgvector: filtered vector search
- RAG orchestrator → LLM provider interface: generation request
- LLM provider interface → Groq provider: implementation
- Watcher → OpenTelemetry collector: telemetry
- Indexer → OpenTelemetry collector: telemetry
- Node API → OpenTelemetry collector: telemetry
