How ignaciobarroso/datasecurity-melichallenge works
1. This repository is a Python 3.11 system for autonomous threat detection and reporting. The architecture is split into four major boundaries: the FastAPI service under api/, the core analysis/RAG code under src/, the static frontend under frontend/, and the operational stack defined by Docker Compose plus supporting services.
2. The main runtime entrypoints are main.py at the repo root for CLI usage and api/main.py for the HTTP API. The API is the primary integration surface for the rest of the system; it exposes analysis, RAG, health, and UI-serving endpoints, while the CLI wraps the same backend capabilities for local execution.
3. The API layer is thin and service-oriented. api/routers/analysis.py handles the multi-agent analysis workflow, api/routers/rag.py handles direct question-answering and RAG debugging, and api/app.py wires the FastAPI application together. api/services/crew_service.py and api/services/rag_service.py adapt the core src/ modules into request/response behavior, session handling, and mode selection.
4. The central analysis pipeline lives in src/mcp_crews.py and src/agents.py. The repository implements a 3-agent sequential flow: Analyzers classify the incident, a second stage maps findings to MITRE ATT&CK, and a final stage generates a prioritized report. src/models.py defines the structured outputs and validation used to keep the report in a stable JSON schema.
5. There are two execution modes for the analyzer, and this is an important architectural boundary. In heavy mode, the system uses a CrewAI-style multi-agent flow with more retrieval and more tracing. In turbo mode, it uses a simpler single-pass pipeline optimized for speed, but both modes must produce the same final report shape and both can be selected per request via query parameter.
6. RAG is a separate subsystem under src/rag_system/ and src/tools/dbir_rag_tool.py. The knowledge base is the DBIR 2025 PDF in data/input/, ingested through src/rag_system/ingest.py using hierarchical chunking. Retrieval uses a ParentDocumentRetriever pattern backed by Chroma as the vector store and Redis as the persistent docstore when available.
7. The retrieval flow has two layers of relevance control. First, embeddings and the vector store retrieve candidate passages from the DBIR corpus; then reranking is applied either with Cohere if COHERE_API_KEY is configured or with a local MMR-style selection fallback. This affects both answer quality and the context that is passed to the LLM.
8. MITRE ATT&CK mapping is isolated behind tool adapters. src/tools/mitre_tool.py provides local MITRE access, while src/tools/mcp_external.py connects to an external MCP server. In the deployed architecture, docker/ and docker-compose.yml run that MCP server in its own container, so the analyzer can prefer remote ATT&CK tools and fall back to local attackcti-based logic when needed.
9. LLM and model-provider concerns are centralized in src/llm_provider.py, with runtime configuration in src/config.py. The system can use OpenAI by default or Ollama as an alternative provider, and the chosen provider affects embeddings, retrieval augmentation, and final report generation. src/cache.py supports reuse in the faster execution path.
10. Tracing and observability are first-class parts of the design. src/trace.py and src/logging_config.py coordinate per-session logging, producing session-scoped logs and structured JSON traces under logs/. That trace boundary is important because the system is meant to audit both task inputs/outputs and tool calls across the multi-agent workflow.
11. The frontend is intentionally minimal and static. frontend/index.html plus its CSS/JS assets are served by the API at /ui, and it acts as a lightweight operator console rather than a separate application tier. The frontend mainly triggers the API endpoints and exposes the heavy/turbo mode switch.
12. The data and artifact directories reflect the system’s operational flow. data/input/ contains the source DBIR PDF, data/custom_inputs/ and reports/ hold sample inputs and outputs, and data/examples/ provides an example report artifact. This makes the repo suitable for offline reproducibility and for regression testing of report structure.
13. Docker is used to separate the app from its dependencies. The stack includes the API container, ChromaDB REST, Redis, and the MITRE MCP service, with an optional Ollama path. The health endpoint is designed to verify these boundaries individually, so architecture diagrams should show service-level dependencies rather than a single monolithic process.
14. Quality and validation tooling are part of the architecture, not just development support. tests/ includes API, UI, logging, tool, and end-to-end checks; evaluation/validate_rag.py measures RAG faithfulness and context precision against the real pipeline. That means the repo’s core contracts are the API schema, the final report schema, and the retrieval behavior, all of which are testable and benchmarked.
Main entry points: mcp_crews.py Crew pipeline · app.py App wiring · dbir_rag_tool.py DBIR tool · turbo_pipeline.py Turbo pipeline
Components 27
API service
FastAPI application, routers, and request-facing adapters.
- API entry · HTTP server entrypoint.
api/main.py - App wiring · Creates and configures the FastAPI application.
api/app.py - Analysis API · Exposes multi-agent analysis and mode selection endpoints.
api/routers/analysis.py - RAG API · Exposes retrieval, QA, and RAG debugging endpoints.
api/routers/rag.py - Crew service · Bridges API requests to the analysis pipeline.
api/services/crew_service.py - RAG service · Bridges API requests to retrieval and answer generation.
api/services/rag_service.py
Analysis core
Incident analysis pipeline, report schema, configuration, and runtime plumbing.
- CLI entry · Command-line entrypoint for local execution.
main.py - Crew pipeline · Sequential multi-agent analysis and report generation flow.
src/mcp_crews.py - Agents · Defines analyzer, MITRE mapping, and reporting roles.
src/agents.py - Report schema · Structured outputs and validation for the final report.
src/models.py - Turbo pipeline · Faster single-pass analysis path with the same output shape.
src/turbo_pipeline.py - LLM provider · Centralizes model provider selection and generation/embedding access.
src/llm_provider.py - Runtime config · Loads environment-driven settings for providers, retrieval, and modes.
src/config.py - Cache · Supports reuse in the faster execution path.
src/cache.py - Tracing · Session-scoped tracing and structured execution records.
src/trace.py - Logging · Configures structured logging for sessions and artifacts.
src/logging_config.py
RAG subsystem
DBIR ingestion, retrieval, and question-answering support.
- DBIR ingest · Ingests and chunks the DBIR corpus for retrieval.
src/rag_system/ingest.py - Retriever · Builds the parent-document retrieval stack and reranking path.
src/rag_system/retriever_factory.py - DBIR tool · Tool wrapper for DBIR-backed retrieval and QA.
src/tools/dbir_rag_tool.py
Tool adapters
MITRE and external MCP integrations used by the analyzers.
- MITRE tool · Local MITRE ATT&CK lookup and normalization logic.
src/tools/mitre_tool.py - MCP client · Connects to the external MITRE MCP service.
src/tools/mcp_external.py
Frontend
Static operator UI served by the API.
- UI shell · Minimal operator console served by the API.
frontend/index.html
Operations
Dockerized runtime and supporting service definitions.
- Compose stack · Defines the API, vector store, Redis, and MCP service stack.
docker-compose.yml - MCP image · Builds the container for the external MITRE MCP service.
docker/Dockerfile.mitre-mcp
Data and artifacts
Source corpus, sample inputs, and example outputs.
- DBIR corpus · Source PDF used as the knowledge base.
data/input/2025-dbir-data-breach-investigations-report.pdf - Example report · Sample structured output for regression and reference.
data/examples/security_report_output.json
Evaluation
Benchmarking and validation scripts for the pipeline.
- RAG validation · Measures faithfulness and context precision against the pipeline.
evaluation/validate_rag.py
Connections 32
- CLI entry → Crew pipeline: run analysis · CLI invokes the core analysis pipeline.
- CLI entry → DBIR tool: run RAG · CLI can exercise retrieval-backed workflows.
- API entry → App wiring: start app · HTTP entrypoint constructs the FastAPI app.
- App wiring → Analysis API: mount · Registers analysis routes.
- App wiring → RAG API: mount · Registers retrieval routes.
- App wiring → UI shell: serve UI · Serves the static operator interface.
- Analysis API → Crew service: delegate · Routes analysis requests to the service layer.
- RAG API → RAG service: delegate · Routes RAG requests to the service layer.
- Crew service → Crew pipeline: analyze · Service executes the multi-agent or turbo analysis path.
- Crew service → Turbo pipeline: fast path · Service selects the lighter pipeline for turbo mode.
- Crew pipeline → Agents: orchestrate · Pipeline coordinates the agent stages.
- Crew pipeline → Report schema: shape output · Final report is validated against the structured schema.
- Turbo pipeline → Report schema: shape output · Turbo mode emits the same report contract.
- Crew pipeline → LLM provider: generate · Uses provider abstraction for reasoning and synthesis.
- Turbo pipeline → LLM provider: generate · Uses provider abstraction for lightweight generation.
- Crew pipeline → Tracing: trace · Records workflow events and tool calls.
- Crew pipeline → Logging: log · Emits structured session logs.
- Turbo pipeline → Cache: reuse · Caches repeated work in the fast path.
- RAG service → DBIR tool: query · Service queries the DBIR retrieval tool.
- DBIR tool → Retriever: build retrieval · Tool uses the retriever stack for candidate context and reranking.
- Retriever → DBIR ingest: index corpus · Retrieval stack depends on ingested DBIR chunks.
- DBIR ingest → DBIR corpus: source · Ingestion starts from the DBIR PDF corpus.
- DBIR tool → LLM provider: answer · Retrieval results are fed to the model provider for responses.
- Crew pipeline → MITRE tool: local ATT&CK · Analyzer can use local MITRE mapping logic.
- Crew pipeline → MCP client: remote ATT&CK · Analyzer can prefer the external MCP-backed MITRE service.
- MCP client → Compose stack: run in stack · External MCP service is deployed as part of the compose stack.
- MCP image → MCP client: build image · Container build produces the MCP service image.
- Compose stack → App wiring: deploy · Compose stack includes the API service.
- Compose stack → UI shell: serve UI · API container serves the static frontend.
- Compose stack → Retriever: backing services · Retrieval depends on vector and document-store services.
- RAG validation → DBIR tool: measure · Validation script evaluates the live retrieval pipeline.
- RAG validation → Example report: compare · Validation can compare against reference artifacts.