# toolshive/intrudex architecture

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

- Interactive diagram: https://gitdiagram.com/toolshive/intrudex
- Repository: https://github.com/toolshive/intrudex

## Overview

##### Project type and purpose
- Intrudex is a hybrid, full-stack security monitoring system for Windows.
- It consists of a native C++ client (real-time Sysmon log collector and Sigma rule engine) and a Python/Flask server (centralized REST API, database, and web dashboard).

##### File structure
- Top-level directories:
- Intrudex-Client (C++ WinAPI client)
– config (JSON, XML Sigma rule exports)
– header/*.h and includes/*.{hpp,cpp} (third-party libs: nlohmann/json, pugixml)
– src/*.cpp (HttpClient, SysmonCollector, sysmon_manager, main)
- Intrudex-Server (Python Flask backend + static assets)
– app/ (Flask application package)
- db.py (SQLAlchemy setup)
- models/auth.py, logs.py
- routes/auth.py, logs.py, main.py, errors.py
- static/ (Tailwind CSS, fonts)
- templates/ (Jinja2 HTML pages)
– run.py, init_db.py, requirements.txt, package.json, sample.env
- Configuration/build files: CMakeLists.txt, version.rc (client); .env, npm build scripts (server).

##### README for architecture clues
- C++ client uses Sysmon + Sigma rules → real-time detection → Windows notifications and automatic responses.
- Client can run standalone or connect to Flask server over REST using public/private key authentication.
- Server uses Flask-Migrate, SQLAlchemy (SQLite or PostgreSQL), TailwindCSS, and provides admin panel & log dashboard.

##### Main components and interactions
a. Windows C++ Client
- SysmonManager: installs registry entries & scheduled tasks (self-healing).
- SysmonCollector: reads Windows Event Logs & Sigma rules (YAML) → generates alerts.
- HttpClient: establishes secure REST connection (public/private key) to server.
- Response engine: blocks IPs, kills processes, disables accounts.
b. Python Flask Server
- REST API Endpoints: /auth, /logs, /main, error handlers.
- Database Layer: SQLAlchemy models (users, logs).
- Admin CLI (flask create-admin) & Flask-Migrate migrations.
- Web Dashboard: Jinja2 templates + TailwindCSS static assets.
c. Database
- SQLite (default) or PostgreSQL (configurable via DATABASE_URL).
d. External infrastructure
- Windows Registry & Task Scheduler (client self-healing).
- Optional Docker containerization (indicated by Docker badge).

Data flow:
[Sysmon Event] → SysmonCollector → Sigma rule engine → Alert → HttpClient → Flask REST API (/logs) → DB → Web Dashboard → Admin actions back to client (optional).

##### Architectural patterns & design principles
- Client-Server (two-tier) with clear separation of concerns.
- Modular C++ design (collector, manager, network).
- MVC-like Flask app (models, routes/controllers, templates/views, static assets).
- Self-healing Windows service pattern (registry+scheduled tasks).
- Secure communication: public/private key auth, HTTPS/REST.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer" 
        direction TB
        EL["Windows Event Logs"]:::infra
        SM["SysmonManager"]:::client
        SC["SysmonCollector"]:::client
        SE["Sigma Rule Engine"]:::client
        AL["Alert"]:::client
        HC["HttpClient"]:::client
        RE["Response Engine"]:::client
        CFG["Client Config & Rules"]:::doc
        EL -->|collects events| SC
        SC -->|apply rules| SE
        SE -->|generate| AL
        AL -->|send alert| HC
        HC -->|secure REST| API
        SM -->|self-healing| WR
        SM -->|self-healing| TS
    end

    %% External infra for client
    WR["Windows Registry"]:::infra
    TS["Task Scheduler"]:::infra

    %% API Layer inside Docker
    subgraph "Docker Container" 
        direction TB
        subgraph "REST API Layer"
            direction TB
            API["Flask REST API"]:::api
            API -->|"POST /auth"| AuthAPI
            API -->|"POST /logs"| LogsAPI
            API -->|"GET /main"| MainAPI
            API -->|"error handlers"| ErrorsAPI
        end

        %% Server Layer
        subgraph "Server Layer"
            direction TB
            SI["App Init"]:::server
            DBS["DB Setup & Migrations"]:::server
            subgraph "Models"
                AUTHM["User Model"]:::server
                LOGM["Log Model"]:::server
            end
            subgraph "Routes"
                AuthAPI["/auth endpoints"]:::server
                LogsAPI["/logs endpoints"]:::server
                MainAPI["/main/dashboard"]:::server
                ErrorsAPI["Error Handlers"]:::server
            end
            subgraph "Views & Assets"
                TPL["Jinja2 Templates"]:::view
                STA["Static Assets (TailwindCSS)"]:::view
            end
            CLI["Admin CLI"]:::server
            SI -->|loads config| DBS
            DBS -->|uses models| AUTHM
            DBS -->|uses models| LOGM
            AuthAPI -->|CRUD| AUTHM
            LogsAPI -->|CRUD| LOGM
            MainAPI -->|render| TPL
            TPL -->|styles| STA
            CLI -->|migrations| DBS
        end

        %% Database
        DB["SQLAlchemy DB"]:::db
        DBS -->|connect| DB
        API -->|DB ops| DB
    end

    %% Click Events for Client
    click SM "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/header/sysmon_manager.h"
    click SM "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/src/sysmon_manager.cpp"
    click SC "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/header/SysmonCollector.h"
    click SC "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/src/SysmonCollector.cpp"
    click HC "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/header/HttpClient.h"
    click HC "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/src/HttpClient.cpp"
    click RE "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/src/main.cpp"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/config/client_config.json"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/config/sysmonconfig-export.xml"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/includes/json.hpp"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/includes/pugixml.hpp"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/includes/pugixml.cpp"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/CMakeLists.txt"
    click CFG "https://github.com/toolshive/intrudex/blob/main/Intrudex-Client/version.rc"

    %% Click Events for Server
    click SI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/__init__.py"
    click DBS "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/db.py"
    click DBS "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/init_db.py"
    click AUTHM "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/models/auth.py"
    click LOGM "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/models/logs.py"
    click AuthAPI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/routes/auth.py"
    click LogsAPI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/routes/logs.py"
    click MainAPI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/routes/main.py"
    click ErrorsAPI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/routes/errors.py"
    click CLI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/run.py"
    click STA "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/static/css/input.css"
    click STA "https://github.com/toolshive/intrudex/tree/main/Intrudex-Server/app/static/fonts/"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/base.html"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/index.html"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/login.html"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/403.html"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/404.html"
    click TPL "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/app/templates/500.html"
    click CLI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/sample.env"
    click CLI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/requirements.txt"
    click CLI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/package.json"
    click CLI "https://github.com/toolshive/intrudex/blob/main/Intrudex-Server/package-lock.json"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#0366D6,color:#000
    classDef server fill:#FFDDAA,stroke:#D2691E,color:#000
    classDef infra fill:#E2E2E2,stroke:#999,color:#000
    classDef api fill:#C8E6C9,stroke:#388E3C,color:#000
    classDef db fill:#F3E5F5,stroke:#7B1FA2,color:#000
    classDef view fill:#FFF9C4,stroke:#FBC02D,color:#000
    classDef doc fill:#D7CCC8,stroke:#5D4037,color:#000
```
