# noor-fatima-afzal/eeg-emotion-detection architecture

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

- Interactive diagram: https://gitdiagram.com/noor-fatima-afzal/eeg-emotion-detection
- Repository: https://github.com/noor-fatima-afzal/eeg-emotion-detection

## Overview

##### Main components
- User Interface (Streamlit frontend)
- Data Ingestion (EDF upload & temp file handler)
- Preprocessing Pipeline (notch filter, bandpass filter, re-reference)
- Epoching Module (windowing with length/overlap, optional resample)
- Feature Extraction Engine (band powers, ratios, Hjorth, entropy, aggregate stats)
- Inference Engine
- Optional scikit-learn classifier (.pkl)
- Heuristic fallback
- Visualization Module
- Channel explorer (raw trace)
- Spectrogram
- PSD (Welch)
- Bandpower bar charts
- Topographic maps
- Export Module (CSV download of per-epoch predictions & probabilities)
- Configuration Store (sidebar controls)

##### Relationships and data flow
- User interacts with the Streamlit UI →
- UI invokes the Data Ingestion component →
- Raw EDF data flows into Preprocessing →
- Preprocessed signal passed to Epoching →
- Each epoch → Feature Extraction → Feature vectors →
- Vectors feed into the Inference Engine → Predictions →
- Results sent both to Visualization Module and Export Module →
- UI renders visuals and provides download link.
- Configuration Store feeds parameters into Preprocessing, Epoching, Visualization.

##### Architectural patterns & design principles
- Pipeline pattern: distinct, ordered stages (Ingestion → Preprocessing → …)
- Separation of concerns: UI vs. processing vs. inference vs. export
- Dependency injection via configuration sidebar
- Pluggable model: external scikit-learn .pkl or internal heuristic

##### Key technologies & libraries
- Streamlit: UI & app server
- MNE: EDF ingestion, montage handling
- SciPy signal: notch, bandpass, spectrogram, Welch PSD
- NumPy / pandas: array manipulation, CSV export
- scikit-learn: optional classifier
- Matplotlib / Plotly: plots & topographic maps

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        UI["User Interface\n(Streamlit)"]:::uiLayer
    end

    subgraph "Processing Layer"
        Ing["Data Ingestion\n(MNE)"]:::processing
        Pre["Preprocessing\n(SciPy)"]:::processing
        Epi["Epoching"]:::processing
        FE["Feature Extraction"]:::processing
    end

    subgraph "Inference Layer"
        Inf["Inference Engine\n(scikit-learn / heuristic)"]:::inference
    end

    subgraph "Visualization & Export Layer"
        Viz["Visualization\n(Plotly/Matplotlib)"]:::vizExport
        Exp["Export Module\n(CSV)"]:::vizExport
    end

    Config["Configuration Store\n(Streamlit sidebar)"]:::config

    UI -->|"raw EDF upload"| Ing
    Ing -->|"raw EDF"| Pre
    Pre -->|"preprocessed signal"| Epi
    Epi -->|"epochs"| FE
    FE -->|"feature vectors"| Inf
    Inf -->|"predictions & probs"| Viz
    Inf -->|"predictions & probs"| Exp
    Viz -->|"render visuals"| UI
    Exp -->|"download link"| UI
    Config -->|"parameters"| Pre
    Config -->|"parameters"| Epi
    Config -->|"parameters"| Viz

    click UI "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Ing "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Pre "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Epi "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click FE "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Inf "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Viz "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Exp "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"
    click Config "https://github.com/noor-fatima-afzal/eeg-emotion-detection/blob/main/app.py"

    classDef uiLayer fill:#e0f7ff,stroke:#333,stroke-width:1px
    classDef processing fill:#e0ffe0,stroke:#333,stroke-width:1px
    classDef inference fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef vizExport fill:#f3e5ff,stroke:#333,stroke-width:1px
    classDef config fill:#eeeeee,stroke:#333,stroke-width:1px
```
