How nahom-zewdu/kms works
1. Overall shape
KMS is a two-process system: a Go backend handles all inbound webhooks and Slack interactions, while a Python NLP worker performs extraction, graph building, and natural-language answering. The main architectural boundary is event ingestion/orchestration in Go versus semantic processing and database writes/reads in Python.
2. External entry points
The system receives events from Slack and GitHub. Slack is both an ingestion source and the user-facing query surface via the @KMS bot. GitHub events appear to cover webhook-driven knowledge capture from commits/PRs. These sources enter through the Go API under api/handlers/.
3. Go backend responsibilities
The Go app is the edge/orchestration layer. Its handlers/ package exposes webhook routes, while services/ coordinates source-specific logic for Slack, GitHub, verification, bot behavior, and metrics. domain/ holds shared contracts and structs, and repository/ contains adapters for Redis Streams and Supabase.
4. Queue-based handoff
After validation, the Go service pushes work into Redis Streams. The README names three logical streams: slack_jobs, github_jobs, and query_jobs. This decouples webhook latency from downstream processing and gives the system retry/consumer-group semantics for resilience and exactly-once-style processing.
5. Python worker as the knowledge engine
The Python side consumes Redis stream jobs through nlp/worker/consumer.py and processor.py. This worker is the main computational layer: it transforms raw Slack/GitHub payloads into structured knowledge and also handles user questions. The worker is separate from the Go API, which keeps heavy NLP/LLM work out of the request path.
6. Ingestion pipeline
The ingestion path in nlp/worker/ingestion.py uses the engine/ package for deterministic extraction:
- ner.py for entity recognition
- re.py for relation extraction
- llm.py and prompt.py for structured LLM calls
- schema.py for strict output models
The design goal is grounded extraction: entities and edges are tied to real UUIDs before being stored.
7. Knowledge graph persistence
Supabase/Postgres is the system of record. The schema files show tables/functions for:
- entities, edges, raw_data, events
- embedding support
- graph traversal RPCs
- vector search RPCs
This indicates the database is not just storage; it also exposes graph/query primitives used by the Python layer.
8. Query and answer path
User questions enter through Slack, are routed by the Go backend into the query job stream, and are handled in Python by the query subsystem (nlp/query_handler.py plus query_engine/). The query engine combines retrieval, analysis, synthesis, and caching, then uses an LLM to produce a natural-language answer grounded in the stored graph and vector data.
9. Slack response loop
The Slack bot is the user-facing feedback channel. Go owns verification, message intake, and bot command plumbing (slack_verifier, slack_bot, slack services), while Python produces the answer payload. The final answer is posted back into the original Slack thread, closing the asynchronous loop.
10. Data integrity and operational concerns
The repo emphasizes reliability features: exactly-once processing, safe upserts with fallback, referential integrity, and an audit trail via raw events. The Go metrics service and Python logging/utilities suggest the system is designed for observable ingestion and query processing rather than a stateless request/response app.
11. Supporting subsystems
nlp/utils/ provides Redis, Supabase, DB helper, and logging wrappers; nlp/migrations/ includes an embedding backfill path. The query_engine/ package is more modular than the older query_handler.py, which suggests the query stack is evolving toward a cleaner retrieval/analysis/synthesis pipeline.
12. What to draw in an architecture diagram
The key boxes are: Slack/GitHub sources, Go API edge layer, Redis Streams, Python NLP worker, Supabase knowledge graph, and Slack bot response path. The most important arrows are:
- inbound webhooks → Go
- Go → Redis Streams
- Redis Streams → Python worker
- Python worker → Supabase
- query path → retrieval/vector/graph/LLM → Slack reply
This captures the repo’s main separation of concerns and the asynchronous knowledge-oracle workflow.
Main entry points: services/slack.go Slack service · routes.go Routes · handlers/slack.go Slack handler · github.go GitHub service
Components 18
External sources
Inbound event producers and user-facing Slack surface.
- Slack · Webhook source and bot conversation surface.
- GitHub · Event source for repository knowledge capture.
Go edge
Webhook intake, validation, and job orchestration.
- API entry · Process entrypoint and HTTP server startup.
api/main.go - Routes · HTTP route wiring for incoming webhooks.
api/handlers/routes.go - Slack handler · Slack webhook ingestion and event handling.
api/handlers/slack.go - GitHub handler · GitHub webhook ingestion and event handling.
api/handlers/github.go - Core service · Shared business coordination across sources and jobs.
api/services/core.go - Slack service · Slack-specific processing and command coordination.
api/services/slack.go - GitHub service · GitHub-specific processing and event normalization.
api/services/github.go - Slack bot · Bot plumbing for replies and thread updates.
api/services/slack_bot.go - Verifier · Slack request verification and trust boundary.
api/services/slack_verifier.go
Python NLP
Async ingestion, query, and answer generation.
- Job consumer · Consumes Redis stream jobs and dispatches processing.
nlp/worker/consumer.py - Ingestion · Transforms source events into structured knowledge.
nlp/worker/ingestion.py - Query worker · Handles user questions and response jobs.
nlp/worker/query.py - Extraction engine · NER, relation extraction, prompts, schemas, and LLM calls.
nlp/engine - Query engine · Retrieval, analysis, caching, synthesis, and vector recall.
nlp/query_engine
Persistence
Redis Streams and Supabase/Postgres knowledge store.
- Redis Streams · Async handoff for ingestion and query jobs.
api/repository/redis_stream.go - Supabase · System of record for entities, edges, events, and vector search.
api/repository/supabase.go
Connections 21
- Slack → API entry: events · Slack webhooks enter the Go API.
- GitHub → API entry: webhooks · GitHub events enter the Go API.
- API entry → Routes: boot · Main wires HTTP routes and server startup.
- Routes → Slack handler: route · Slack routes are bound to the Slack handler.
- Routes → GitHub handler: route · GitHub routes are bound to the GitHub handler.
- Slack handler → Verifier: verify · Slack requests are authenticated before processing.
- Slack handler → Slack service: delegate · Verified Slack events are normalized and handled.
- GitHub handler → GitHub service: delegate · GitHub webhook payloads are normalized and handled.
- Slack service → Core service: coordinate · Slack logic shares orchestration with core services.
- GitHub service → Core service: coordinate · GitHub logic shares orchestration with core services.
- Slack service → Redis Streams: enqueue · Slack jobs are pushed to Redis Streams.
- GitHub service → Redis Streams: enqueue · GitHub jobs are pushed to Redis Streams.
- Slack service → Slack bot: reply · Slack bot plumbing posts responses back to threads.
- Redis Streams → Job consumer: consume · Python worker consumes queued jobs.
- Job consumer → Ingestion: ingest · Source jobs flow into the ingestion pipeline.
- Job consumer → Query worker: query · Query jobs flow into the question-answer path.
- Ingestion → Extraction engine: extract · Extraction engine produces structured entities and edges.
- Extraction engine → Supabase: write · Structured knowledge is persisted to Supabase.
- Query worker → Query engine: analyze · Query engine performs retrieval and synthesis.
- Query engine → Supabase: read · Query engine reads graph and vector data from Supabase.
- Query engine → Slack bot: answer · Generated answers are sent back through Slack.