# sleep-revolution/sleepscorergray architecture

> Architecture diagram of the GitHub repository sleep-revolution/sleepscorergray, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sleep-revolution/sleepscorergray
- Repository: https://github.com/sleep-revolution/sleepscorergray

## Overview

##### Main Components Identification

a) Web Layer
- Represents the frontend (web/index.html, web/download.html)

b) API Layer
- In the middle
- FastAPI application (indicated by uvicorn server usage)
- Entry point through main.py

c) GrayAreaDL Core
- At the bottom
- Contains the machine learning and signal processing components

##### Detailed Component Breakdown

a) Data Processing Pipeline:
- Data Input
- Preprocessing (preprocessing/ directory)
- Signal Filters (bpfilter, chebyhpfilter)
- Signal Processing (harmonisation, resample, reshape)
- Feature Extraction (spectrograms)

b) Model Components:
- Model Architecture (model/model.py)
- Mixture Models (model/mixturemodels.py)
- Custom Callbacks (model/callbacks.py)

c) Prediction Flow:
- Flow through:
- Data Generator (data/datagenerator.py)
- Predictors (data/predictors.py)
- Prediction Processing (data/prediction.py)

##### Data Flow Representation

- Client Request → Web Interface
- Web Interface → FastAPI Endpoint
- FastAPI → GrayAreaDL Core
- Within GrayAreaDL: Input → Preprocessing → Model → Prediction → Response

##### Configuration and Utilities

- Configuration Management (conf/ directory)
- Utility Services (utils/ directory)
- Logging System (logs/ directory)

##### Technical Details

Annotations for:
- FastAPI running on uvicorn
- Port 8002 specification
- Supported file formats
- Key dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef web fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef processing fill:#e74c3c,stroke:#c0392b,color:white
    classDef model fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#34495e,stroke:#2c3e50,color:white
    classDef utils fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Web Layer
    subgraph Web
        WebUI["Web Interface"]
        Download["Download Page"]
    end
    click WebUI "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/web/index.html"
    click Download "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/web/download.html"

    %% API Layer
    subgraph API
        FastAPI["FastAPI Server (Port 8002)"]
        MainEntry["API Entry Point"]
    end
    click MainEntry "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/main.py"

    %% Data Processing Pipeline
    subgraph Processing
        DataInput["Data Input"]
        subgraph SignalFilters["Signal Filters"]
            BPFilter["Bandpass Filter"]
            ChebyFilter["Chebyshev Filter"]
        end
        subgraph SignalProcessing["Signal Processing"]
            Harmonisation["Harmonisation"]
            Resample["Resampling"]
            Reshape["Reshape"]
        end
        FeatureExtraction["Spectrogram Generation"]
    end
    click BPFilter "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/bpfilter.py"
    click ChebyFilter "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/chebyhpfilter.py"
    click Harmonisation "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/harmonisation.py"
    click Resample "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/resample.py"
    click Reshape "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/reshape.py"
    click FeatureExtraction "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/preprocessing/spectrograms.py"

    %% Model Components
    subgraph ModelSystem
        CoreModel["Core Model"]
        MixtureModels["Mixture Models"]
        Callbacks["Model Callbacks"]
    end
    click CoreModel "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/model/model.py"
    click MixtureModels "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/model/mixturemodels.py"
    click Callbacks "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/model/callbacks.py"

    %% Data Pipeline
    subgraph DataPipeline
        DataGen["Data Generator"]
        Predictors["Predictors"]
        PredictionProc["Prediction Processing"]
    end
    click DataGen "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/data/datagenerator.py"
    click Predictors "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/data/predictors.py"
    click PredictionProc "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/data/prediction.py"

    %% Configuration
    subgraph Config
        PSGConf["PSG Configuration"]
        SASConf["SAS Configuration"]
        PredictConf["Prediction Configuration"]
        EnsembleConf["Ensemble Configuration"]
    end
    click PSGConf "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/conf/testConfPSG.yaml"
    click SASConf "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/conf/testConfSAS.yaml"
    click PredictConf "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/conf/testPredict.yaml"
    click EnsembleConf "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/conf/testPredictEnsemble.yaml"

    %% Utilities
    subgraph Utils
        YAMLUtils["YAML Utils"]
        ExpSave["Experiment Saving"]
        SysIntrospect["System Introspection"]
        Logging["Logging System"]
    end
    click YAMLUtils "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/utils/yamlutils.py"
    click ExpSave "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/utils/save_xp.py"
    click SysIntrospect "https://github.com/Sleep-Revolution/SleepScorerGray/blob/main/api/GrayAreaDL/src/utils/introspection.py"
    click Logging "https://github.com/Sleep-Revolution/SleepScorerGray/tree/main/api/GrayAreaDL/logs/Test_Sleep_Stage_Classification/"

    %% Relationships
    WebUI --> FastAPI
    Download --> FastAPI
    FastAPI --> MainEntry
    MainEntry --> DataInput
    DataInput --> SignalFilters
    SignalFilters --> SignalProcessing
    SignalProcessing --> FeatureExtraction
    FeatureExtraction --> DataGen
    DataGen --> CoreModel
    CoreModel --> MixtureModels
    MixtureModels --> Predictors
    Predictors --> PredictionProc
    Config --> ModelSystem
    Utils --> ModelSystem
    Utils --> Processing
    Callbacks --> CoreModel

    %% Styling
    class WebUI,Download web
    class FastAPI,MainEntry api
    class DataInput,SignalFilters,SignalProcessing,FeatureExtraction processing
    class CoreModel,MixtureModels,Callbacks model
    class DataGen,Predictors,PredictionProc data
    class PSGConf,SASConf,PredictConf,EnsembleConf config
    class YAMLUtils,ExpSave,SysIntrospect,Logging utils
```
