# jordanchendev/system_guardian architecture

> Architecture diagram of the GitHub repository jordanchendev/system_guardian, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jordanchendev/system_guardian
- Repository: https://github.com/jordanchendev/system_guardian

## Overview

##### Project Overview
- System Guardian is a real-time, incident management system. It automates incident ingestion from various sources (Datadog, GitHub, Jira, etc.), processes events, and uses AI-driven services (with GPT-4o based engines and a Qdrant vector database) to suggest remediation steps and resolutions.
- It is built using FastAPI with a microservice-like internal modular structure. It integrates with external messaging systems (RabbitMQ), a relational database (PostgreSQL), and a vector DB (Qdrant). The project also includes integrations for Slack notifications and Jira ticketing.

##### Key Components
- External Integrations:
- Webhooks from services such as Datadog, GitHub, and Jira.
- Slack for notifications (via system_guardian/services/slack).
- Possibly other external inputs (e.g., Datadog alerts).
- Ingestion Layer:
- Endpoints under system_guardian/web/api/ingest handle incoming webhook payloads.
- These endpoints further channel events to the internal processing pipelines.
- Messaging/Queueing:
- RabbitMQ is used as the primary message broker (as seen in system_guardian/services/rabbit and described in the documentation).
- Event Consumer Service:
- The event_consumer_service (system_guardian/event_consumer_service.py) listens to the RabbitMQ queues.
- It picks up events for further processing.
- Database and Persistence:
- PostgreSQL holds core incident and event data.
- The project’s DB directory (system_guardian/db) shows scripts to create, drop, or reset tables and models (e.g., incidents and events).
- AI and Analysis Engine:
- Under system_guardian/services/ai, several modules handle incident detection, similarity search, severity classification, and report/resolution generation.
- The AI engine utilizes retrieval techniques and possibly GPT-based models.
- Vector Database:
- Qdrant is integrated for vector search; system_guardian/services/vector_db and its client (qdrant_client.py) handle this.
- Configuration and Rules:
- The config services (system_guardian/services/config) load incident rules and other configuration settings.
- Web/API Interface:
- The FastAPI application (system_guardian/web) exposes endpoints with various submodules (e.g., API endpoints for echo, incidents, ai_engine, config, etc.).
- It also provides auto-generated Swagger documentation.
- Logging & Monitoring:
- There’s a dedicated logging configuration (system_guardian/logging and logging_config.py).
- The README also mentions integration with Datadog and use of ELK for logging and monitoring.

##### Architectural Patterns and Design Principles
- Microservices and modular architecture: Even though the codebase is organized as a single package, its internal structure (services, ingestion, AI, DB logic) suggests modular separation of concerns.
- Event-driven architecture: Use of RabbitMQ for queueing and asynchronous processing.
- Separation of Presentation, Logic, and Data layers: The FastAPI endpoints are separated from the processing (AI, logging) and persistence services.
- Extensibility: Modular design in the AI engine and integration modules (slack, jira, vector_db) points to a pluggable, extendable platform.

- Review the documentation and file structure to confirm the identified modules and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integrations Layer
    subgraph "External Integrations"
        DATADOG["Datadog"]:::external
        GITHUB["GitHub"]:::external
        JIRA_EXT["Jira"]:::external
        SLACK["Slack"]:::external
    end

    %% Ingestion Layer
    subgraph "Ingestion Layer"
        INGEST["Ingestion API Endpoints"]:::ingestion
    end

    %% Messaging & Processing Layer
    subgraph "Messaging & Processing"
        RABBIT["RabbitMQ"]:::messaging
        EVENT_CONSUMER["Event Consumer Service"]:::consumer
    end

    %% AI & Analysis Engine Layer
    subgraph "AI & Analysis Engine"
        INCIDENT_DETECTION["Incident Detection"]:::ai
        INCIDENT_ANALYZER["Incident Analyzer"]:::ai
        SEVERITY_CLASSIFIER["Severity Classifier"]:::ai
        RESOLUTION_GENERATOR["Resolution Generator"]:::ai
        SIMILARITY_SEARCH["Incident Similarity Search"]:::ai
    end

    %% Database & Persistence Layer
    subgraph "Database & Persistence"
        POSTGRES["PostgreSQL"]:::database
        QDRANT["Qdrant Vector DB"]:::database
    end

    %% API & UI Layer
    subgraph "API & UI Layer"
        FASTAPI["FastAPI Web Interface"]:::api
    end

    %% Configuration & Logging Layer
    subgraph "Configuration & Logging"
        CONFIG["Configuration & Rules"]:::config
        LOGGING["Logging & Monitoring"]:::logging
    end

    %% Data Flow Connections
    %% External integrations send webhooks to ingestion layer
    DATADOG -->|"webhook"| INGEST
    GITHUB  -->|"webhook"| INGEST
    JIRA_EXT -->|"webhook"| INGEST
    %% Ingestion may also forward notifications to Slack
    INGEST -->|"notify"| SLACK

    %% Ingestion publishes events to RabbitMQ
    INGEST -->|"publishes_event"| RABBIT

    %% RabbitMQ sends events to Event Consumer Service
    RABBIT -->|"delivers_event"| EVENT_CONSUMER

    %% Event Consumer persists events and triggers analysis
    EVENT_CONSUMER -->|"persists_event"| POSTGRES
    EVENT_CONSUMER -->|"triggers_analysis"| INCIDENT_DETECTION

    %% AI Engine internal processing flow
    INCIDENT_DETECTION -->|"analyzes"| INCIDENT_ANALYZER
    INCIDENT_ANALYZER -->|"classifies"| SEVERITY_CLASSIFIER
    SEVERITY_CLASSIFIER -->|"generates"| RESOLUTION_GENERATOR
    RESOLUTION_GENERATOR -->|"searches"| SIMILARITY_SEARCH

    %% AI Engine interactions with persistence components
    INCIDENT_DETECTION ---|"reads/writes"| POSTGRES
    SIMILARITY_SEARCH ---|"queries_vectors"| QDRANT

    %% AI Engine sends analysis results to API layer
    SIMILARITY_SEARCH -->|"sends_results"| FASTAPI

    %% API layer interactions for ticketing and notifications
    FASTAPI -->|"create_ticket"| JIRA_EXT
    FASTAPI -->|"send_notification"| SLACK

    %% Configuration and Logging integrations
    INGEST ---|"loads_rules"| CONFIG
    INCIDENT_DETECTION ---|"loads_rules"| CONFIG
    EVENT_CONSUMER ---|"logs"| LOGGING
    FASTAPI ---|"logs"| LOGGING

    %% Click Events
    click SLACK "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/slack"
    click JIRA_EXT "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/jira"
    click INGEST "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/web/api/ingest"
    click RABBIT "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/rabbit"
    click EVENT_CONSUMER "https://github.com/jordanchendev/system_guardian/blob/main/system_guardian/event_consumer_service.py"
    click POSTGRES "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/db"
    click INCIDENT_DETECTION "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/ai"
    click QDRANT "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/vector_db"
    click CONFIG "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/services/config"
    click FASTAPI "https://github.com/jordanchendev/system_guardian/tree/main/system_guardian/web"
    click LOGGING "https://github.com/jordanchendev/system_guardian/blob/main/system_guardian/logging.py"

    %% Styles
    classDef external fill:#ffd1dc,stroke:#333,stroke-width:2px;
    classDef ingestion fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef messaging fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef consumer fill:#ffe5b4,stroke:#333,stroke-width:2px;
    classDef ai fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef database fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef api fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef config fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef logging fill:#f5c6cb,stroke:#333,stroke-width:2px;
```
