# alexkay/spek architecture

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

- Interactive diagram: https://gitdiagram.com/alexkay/spek
- Repository: https://github.com/alexkay/spek

## Overview

##### Project type and purpose
- Spek is a native desktop application written in C++.
- Purpose: perform acoustic spectrum analysis of audio files, using FFmpeg for decoding and wxWidgets for GUI.

##### File structure
- Top-level:
- src/ – C++ source: core engine, FFT, pipeline, UI, platform abstraction
- po/ – translations
- tests/ – unit and performance tests
- dist/ – packaging scripts for Debian, FreeBSD, macOS, Windows
- build scripts: autogen.sh, configure.ac, Makefile.am
- Naming conventions reveal modules: “spek-audio”, “spek-fft”, “spek-pipeline”, “spek-window”, etc.

##### README for architecture clues
- Dependencies: FFmpeg (decoding) + wxWidgets (GUI)

##### Main components and interactions
a. External libraries
- FFmpeg libavcodec/libavformat – audio decoding
- wxWidgets – cross-platform GUI, event loop
b. Core engine modules (src/)
- AudioDecoder (spek-audio.cc/h)
- FFTProcessor (spek-fft.cc/h)
- Utils (spek-utils): file I/O, format detection
c. UI modules
- MainWindow (spek-window.cc/h)
- SpectrogramView (spek-spectrogram.cc/h)
- Ruler / Artwork (spek-ruler, spek-artwork)
- PreferencesDialog (spek-preferences-dialog) + Preferences backend
- EventDispatcher (spek-events)
d. Platform abstraction
- spek-platform: file paths, config location (XDG_CONFIG_HOME), thread primitives
e. Assets & configuration
- web/ (man pages), INSTALL.md, MANUAL.md
f. Testing
- tests/test-*.cc, tests/perf.cc verify decoding, FFT, pipeline, utils

##### Relationships and data flow
- User opens audio file → MainWindow sends request to Pipeline
- Pipeline calls AudioDecoder → raw PCM frames
- PCM frames → FFTProcessor → power spectrum data
- Bitmap → SpectrogramView → rendered in MainWindow
- Preferences feed into Pipeline (window size, function) and PaletteManager
- EventDispatcher routes UI events (file open, prefs change)

##### Architectural patterns and design principles
- MVC-like separation:
- Model = core engine (decoder, FFT, pipeline)
- View = SpectrogramView + MainWindow
- Controller = EventDispatcher + UI dialogs
- Modular design: each functionality in its own cc/h pair
- Cross-platform abstraction layer isolates OS-specific code
- Build system: autoconf/automake enables multi-platform packaging
- Internationalization with gettext (po/)

##### Final checklist
- All major components (decoding, FFT, pipeline, palette, UI, platform)
- External services/libraries (FFmpeg, wxWidgets)
- Version/build system note (Autotools)

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        FFmpeg["FFmpeg (libavcodec/libavformat)"]:::external
        WxWidgets["wxWidgets"]:::external
    end

    %% Core Engine
    subgraph "Core Engine" 
        direction TB
        AD["AudioDecoder\n(spek-audio)"]:::core
        FP["FFTProcessor\n(spek-fft)"]:::core
        PL["Pipeline\n(spek-pipeline)"]:::core
        PM["PaletteManager\n(spek-palette)"]:::core
        UT["Utils\n(spek-utils)"]:::core
    end

    %% UI Presentation
    subgraph "Presentation/UI"
        direction TB
        MW["MainWindow\n(spek-window)"]:::ui
        SV["SpectrogramView\n(spek-spectrogram)"]:::ui
        RU["Ruler\n(spek-ruler)"]:::ui
        AR["Artwork\n(spek-artwork)"]:::ui
        PD["PreferencesDialog\n(spek-preferences-dialog)"]:::ui
        PB["PreferencesBackend\n(spek-preferences)"]:::ui
        ED["EventDispatcher\n(spek-events)"]:::ui
    end

    %% Platform Abstraction
    subgraph "Platform Abstraction"
        direction TB
        PA["PlatformAbstraction\n(spek-platform)"]:::platform
    end

    %% Resources & Config
    subgraph "Resources"
        direction TB
        IC["Icons"]:::res
        DF["DesktopFileTemplate\n(spek.desktop.in)"]:::res
        MI["AppMetadata\n(spek.metainfo.xml.in)"]:::res
    end

    %% Build System
    subgraph "Build System (Autotools)"
        direction TB
        AC["configure.ac"]:::build
        MA["Makefile.am"]:::build
        AG["autogen.sh"]:::build
    end

    %% Testing
    subgraph "Testing Suite"
        direction TB
        TS["tests/"]:::test
    end

    %% Data Flow
    MW -->|"open file"| PL
    PL -->|decoding| AD
    AD -->|"PCM frames"| FP
    FP -->|"power spectrum data"| PM
    PM -->|"colored bitmap"| SV
    SV -->|"render"| MW

    %% UI Control Flow
    MW <-->|"UI events"| ED
    ED -->|"route open"| PL
    ED -->|"route prefs"| PD
    PD -->|"save settings"| PB
    PB -->|"config parameters"| PL
    PB -->|"color settings"| PM

    %% Dependencies
    PL --> FFmpeg
    MW --> WxWidgets
    ED --> WxWidgets
    AD --> FFmpeg
    PA --- AD
    PA --- FP
    PA --- PL
    PA --- PM
    PA --- UT
    PA --- MW
    PA --- SV
    PA --- ED
    PA --- PD

    %% Resources linkage
    MW --> IC
    MW --> DF
    MW --> MI

    %% Build and Packaging
    PL --> AC
    PL --> MA
    PL --> AG

    %% Testing connections
    TS --> AD
    TS --> FP
    TS --> UT
    TS --> PL

    %% Legend
    subgraph "Legend"
        direction TB
        E[("External")]:::external
        C[("Core")]:::core
        U[("UI")]:::ui
        P[("Platform")]:::platform
        R[("Resources")]:::res
        B[("Build")]:::build
        T[("Testing")]:::test
    end

    %% Click Events
    click AD "https://github.com/alexkay/spek/blob/master/src/spek-audio.cc"
    click FP "https://github.com/alexkay/spek/blob/master/src/spek-fft.cc"
    click PL "https://github.com/alexkay/spek/blob/master/src/spek-pipeline.cc"
    click PM "https://github.com/alexkay/spek/blob/master/src/spek-palette.cc"
    click UT "https://github.com/alexkay/spek/blob/master/src/spek-utils.cc"
    click MW "https://github.com/alexkay/spek/blob/master/src/spek-window.cc"
    click SV "https://github.com/alexkay/spek/blob/master/src/spek-spectrogram.cc"
    click RU "https://github.com/alexkay/spek/blob/master/src/spek-ruler.cc"
    click AR "https://github.com/alexkay/spek/blob/master/src/spek-artwork.cc"
    click PD "https://github.com/alexkay/spek/blob/master/src/spek-preferences-dialog.cc"
    click PB "https://github.com/alexkay/spek/blob/master/src/spek-preferences.cc"
    click ED "https://github.com/alexkay/spek/blob/master/src/spek-events.cc"
    click PA "https://github.com/alexkay/spek/blob/master/src/spek-platform.cc"
    click AppEntry "https://github.com/alexkay/spek/blob/master/src/spek.cc"
    click IC "https://github.com/alexkay/spek/tree/master/data/icons/"
    click DF "https://github.com/alexkay/spek/blob/master/data/spek.desktop.in"
    click MI "https://github.com/alexkay/spek/blob/master/data/spek.metainfo.xml.in"
    click TS "https://github.com/alexkay/spek/tree/master/tests/"
    
    %% Styles
    classDef external fill:#bfdefa,stroke:#2271b1,color:#000
    classDef core fill:#b8e6a3,stroke:#3e8e41,color:#000
    classDef ui fill:#fcd38a,stroke:#ce8c18,color:#000
    classDef platform fill:#e0e0e0,stroke:#808080,color:#000
    classDef res fill:#d3d3f9,stroke:#6b6bcc,color:#000
    classDef build fill:#f2dede,stroke:#d9534f,color:#000
    classDef test fill:#f5f5f5,stroke:#999,color:#000
```
