# alibahmanyar/simon architecture

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

- Interactive diagram: https://gitdiagram.com/alibahmanyar/simon
- Repository: https://github.com/alibahmanyar/simon

## Overview

##### Main Components
- Backend (Rust Application):
- Core modules under the src/ directory (alerts.rs, auth.rs, collect_info.rs, config.rs, db.rs, endpoints.rs, logging.rs, models.rs, and main.rs).
- Handles API endpoints (using axum) to serve system monitoring data, process user authentication, and manage alerts.
- Integrates with external services such as the Docker engine (using the bollard crate) and gathers system metrics (via sysinfo) in real time.
- Manages persistence through a SQLite database (the database path is configured via environment variables/CLI).

- Frontend (Web Application):
- Located in the web/ directory, it is built using Svelte, along with supporting files for configuration (vite.config.ts, tsconfig.json) and tests.
- Contains various routes (e.g., main, docker insights, graphs, network, storage, settings, alerts, notification methods) that together form the responsive UI.
- Communicates with the backend over HTTP (and potentially WebSockets for real-time updates).

- External Integrations and Deployment:
- Docker: The Dockerfile and Docker Compose setup indicate that the application is containerized. Docker is used not only for deployment but also to monitor containerized environments.
- Reverse Proxies (Nginx/Traefik): As outlined, Simon is deployable behind a reverse proxy for production setups.
- Alerting/Notification System: Module for setting thresholds and sending alert messages (to messaging services like Slack, Telegram, or Discord via webhooks).

##### Relationships and Data Flows
- User Browser -> Web Frontend:
- The client browser accesses the web UI. This UI is built in Svelte and is responsible for rendering the system monitoring dashboards.
- Routes for different facets such as system metrics, Docker insights, and alert settings.

- Web Frontend -> Backend API:
- Authentication flows should be noted, wherein authentication is managed through bcrypt hashes.

- Backend Data Collection and Processing:
- The backend gathers system data (CPU, memory, disk I/O, network, etc.) and Docker statistics by interacting with the underlying OS and Docker socket.
- Modules like collect_info.rs and docker-related endpoints to represent that system information is fed into the process flow.

- Database Layer:
- The backend writes to/reads from an SQLite database (configured via SIMON_DB_PATH) to record historical data and maintain state.

- Alerting and Notification:
- Data modules feed into an alerts system that processes threshold conditions.
- From here, notifications are sent to external webhooks or services when configured conditions are met.

##### Architectural Patterns & Design Principles
- Clear Separation: Emphasize the separation between the frontend (UI, presentation layer) and backend (business logic, monitoring, persistence).
- Modular Components: Each module (authentication, metrics collection, Docker integration, alerting, database access) is encapsulated. This helps in scaling, testing, and future extensions.
- Real-Time Monitoring: Show how the data flows continuously from system modules to the user interface using periodic updates (like a timer for SIMON_UPDATE_INTERVAL) or WebSockets if applicable.

##### Relevant Technologies and Tools
- For the Backend: Rust, axum, tokio, sysinfo, bollard, clap, and serde.
- For the Frontend: Svelte, Chart.js, Bun, and associated build tools (Vite).
- Others: Docker (for deployment and containerized monitoring), SQLite (for persistent storage), and optional reverse proxy services (Nginx/Traefik).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    subgraph "User Interaction"
        Browser("User Browser"):::user
        Frontend("Svelte Web Frontend"):::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        Backend("Rust Backend (axum API)"):::backend
        Metrics("System Metrics Collector (sysinfo)"):::backend
        DockerInt("Docker Integration (bollard)"):::backend
        Auth("Authentication Module"):::backend
        Alerts("Alerting Module"):::backend
        DB("SQLite Database"):::db
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        Docker("Docker Container"):::infra
        ReverseProxy("Reverse Proxy (Nginx/Traefik)"):::infra
        ExtNotif("External Notification Services"):::infra
    end

    %% Frontend Alerts Configuration (grouped as a subgraph for clarity)
    subgraph "Frontend Alerts Configuration"
        FEAlerts("Alerts Page"):::frontend
        FENotif("Notification Methods Page"):::frontend
    end

    %% Data Flows
    Browser -->|"accesses"| Frontend
    Frontend -->|"REST/WebSocket Calls"| Backend
    Backend -->|"Collects Metrics"| Metrics
    Backend -->|"Integrates with"| DockerInt
    Backend -->|"Manages"| Auth
    Backend -->|"Processes Alerts"| Alerts
    Backend -->|"Persists Data"| DB
    Alerts -->|"Sends Notifications"| ExtNotif

    DockerInt -->|"Monitors Docker"| Docker
    ReverseProxy -->|"Routes to"| Frontend
    ReverseProxy -->|"Routes to"| Backend

    Frontend -->|"Contains"| FEAlerts
    Frontend -->|"Contains"| FENotif

    %% Click Events
    click Backend "https://github.com/alibahmanyar/simon/tree/main/src/"
    click Metrics "https://github.com/alibahmanyar/simon/blob/main/src/collect_info.rs"
    click DockerInt "https://github.com/alibahmanyar/simon/tree/main/src/"
    click Auth "https://github.com/alibahmanyar/simon/blob/main/src/auth.rs"
    click Alerts "https://github.com/alibahmanyar/simon/blob/main/src/alerts.rs"
    click DB "https://github.com/alibahmanyar/simon/blob/main/src/db.rs"
    click Frontend "https://github.com/alibahmanyar/simon/tree/main/web/"
    click FEAlerts "https://github.com/alibahmanyar/simon/blob/main/web/src/routes/(settings)/alerts/+page.svelte"
    click FENotif "https://github.com/alibahmanyar/simon/blob/main/web/src/routes/(settings)/notif_methods/+page.svelte"
    click Docker "https://github.com/alibahmanyar/simon/tree/main/Dockerfile"

    %% Styles
    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef db fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef user fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
