# analogj/scrutiny architecture

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

- Interactive diagram: https://gitdiagram.com/analogj/scrutiny
- Repository: https://github.com/analogj/scrutiny

## Overview

##### Main Components Overview

a) Collector Component
- Location: /collector directory
- Purpose: Gathers S.M.A.R.T metrics from physical drives
- Interfaces with smartd daemon
- Contains device detection and metrics collection logic

b) Web Application (Frontend)
- Location: /webapp/frontend directory
- Angular-based dashboard UI
- Displays drive health status and metrics
- Contains visualization components for S.M.A.R.T data

c) Backend API
- Location: /webapp/backend directory
- Handles data storage and retrieval
- Manages device registration and metrics
- Provides notification services

##### Data Flow Architecture

**[Physical Drives] → [Collector] → [Backend API] → [InfluxDB]**
- ↑
- [Web Frontend]

##### Component Details

For the Collector:
- Subcomponents: device detection, metrics collection, and configuration
- Connection to smartd daemon
- Supported device types (RAID, NVMe, SCSI, etc.)

For the Backend:
- Database migrations and models
- API endpoints (/api/health, /api/devices, etc.)
- Notification services (multiple providers)
- Configuration management

For the Frontend:
- Dashboard components
- Device monitoring views
- Settings management
- Real-time updates

##### Deployment Options
Two deployment scenarios:

a) Omnibus (All-in-one):
**[Docker Container]**
- Collector
- Web Frontend
- Backend API
- InfluxDB

b) Hub/Spoke:
**[Collector Container 1] ─┐**
**[Collector Container 2] ─┼→ [Web Container] ← [InfluxDB Container]**
**[Collector Container n] ─┘**

##### Cross-Cutting Concerns
Following aspects:
- Security capabilities (SYS_RAWIO, SYS_ADMIN)
- Configuration management
- Logging and debugging
- Notification system
- Device detection and monitoring

##### Additional Details
- Version information
- Supported architectures
- Configuration file locations
- Cron scheduling
- Notification endpoints

This system design should help developers understand both the overall architecture and the specific implementation details of Scrutiny's drive monitoring solution.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        L1[Component]:::component
        L2[(Database)]:::database
        L3([External System]):::external
        L4[/API Endpoint/]:::api
        L5{{Notification Service}}:::notification
    end

    subgraph Physical["Physical Layer"]
        HD([Physical Drives]):::external
        SMART([SMARTD Daemon]):::external
    end

    subgraph Collector["Collector Layer"]
        COL[Collector Main]:::component
        DD[Device Detection]:::component
        MC[Metrics Collection]:::component
        CC[Collector Config]:::component
        
        DD --> COL
        MC --> COL
        CC --> COL
    end

    subgraph Backend["Backend Layer"]
        API[API Server]:::component
        DBL[Database Layer]:::component
        HAND[API Handlers]:::component
        NOTIF{{Notification Service}}:::notification
        DM[Device Models]:::component
        MM[Metrics Models]:::component
        BCONF[Backend Config]:::component
        
        API --> DBL
        HAND --> API
        DM --> DBL
        MM --> DBL
        BCONF --> API
        API --> NOTIF
    end

    subgraph Frontend["Frontend Layer"]
        DASH[Dashboard]:::component
        DEV[Device Details]:::component
        DCOMP[Device Components]:::component
        SET[Settings UI]:::component
        FCONF[Frontend Config]:::component
        
        DCOMP --> DASH
        DEV --> DASH
        SET --> DASH
        FCONF --> DASH
    end

    subgraph Storage["Storage Layer"]
        DB[(InfluxDB)]:::database
        MIGR[Database Migrations]:::component
    end

    HD --> SMART
    SMART --> COL
    COL --> API
    API --> DB
    DASH --> API
    MIGR --> DB

    %% Click events for component mapping
    click COL "https://github.com/AnalogJ/scrutiny/blob/master/collector/cmd/collector-metrics/collector-metrics.go"
    click DD "https://github.com/AnalogJ/scrutiny/blob/master/collector/pkg/detect/detect.go"
    click MC "https://github.com/AnalogJ/scrutiny/blob/master/collector/pkg/collector/metrics.go"
    click CC "https://github.com/AnalogJ/scrutiny/blob/master/collector/pkg/config/config.go"
    click DASH "https://github.com/AnalogJ/scrutiny/blob/master/webapp/frontend/src/app/modules/dashboard/dashboard.component.ts"
    click DEV "https://github.com/AnalogJ/scrutiny/blob/master/webapp/frontend/src/app/modules/detail/detail.component.ts"
    click DCOMP "https://github.com/AnalogJ/scrutiny/blob/master/webapp/frontend/src/app/layout/common/dashboard-device/dashboard-device.component.ts"
    click SET "https://github.com/AnalogJ/scrutiny/blob/master/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts"
    click API "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/web/server.go"
    click HAND "https://github.com/AnalogJ/scrutiny/tree/master/webapp/backend/pkg/web/handler"
    click DBL "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/database/scrutiny_repository.go"
    click NOTIF "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/notify/notify.go"
    click DM "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/models/device.go"
    click MM "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/models/measurements/smart.go"
    click MIGR "https://github.com/AnalogJ/scrutiny/tree/master/webapp/backend/pkg/database/migrations"
    click BCONF "https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/config/config.go"
    click FCONF "https://github.com/AnalogJ/scrutiny/blob/master/webapp/frontend/src/app/core/config/scrutiny-config.service.ts"

    classDef component fill:#2374e1,stroke:#164480,color:#fff
    classDef database fill:#439446,stroke:#2d632f,color:#fff
    classDef external fill:#ed8b00,stroke:#a66100,color:#fff
    classDef api fill:#793698,stroke:#4f2162,color:#fff
    classDef notification fill:#d04437,stroke:#a63336,color:#fff
```
