# szluk133/csdl_dpt architecture

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

- Interactive diagram: https://gitdiagram.com/szluk133/csdl_dpt
- Repository: https://github.com/szluk133/csdl_dpt

## Overview

##### Project type and purpose
- This is a small full-stack Python web application for speech processing.
- It provides a web UI (in templates/index.html + static/css/style.css) served by FastAPI (web.py), accepts or triggers audio embedding extraction (ex_ebd.py using SpeechBrain and Torch), and persists or queries data in MySQL.

##### Analysis of the file structure
- Top-level scripts:
- ex_ebd.py – the audio embedding extraction module (SpeechBrain + PyTorch + SciPy).
- web.py – the FastAPI HTTP server exposing routes for the UI and for upload/processing endpoints.
- Static assets (static/css/style.css) and a Jinja-style template (templates/index.html).
- No separate “backend” or “frontend” folders, but responsibilities are clearly divided:
- Templates + static → frontend
- web.py + ex_ebd.py → backend
- Configuration is minimal; dependencies are managed via virtualenv and pip.

##### Key insights from the README
- Tech stack: Python, FastAPI, Uvicorn, SpeechBrain, PyTorch, MySQL.
- Run flow:
1. Activate venv
2. pip install dependencies
3. python ex_ebd.py (can be used standalone or imported)
4. python web.py (starts the HTTP server)

##### Main components
a. Frontend
- Browser UI (templates/index.html + CSS)
- HTTP(S) client
b. API Server (Backend)
- FastAPI app (web.py)
- Uvicorn ASGI server
- Routes:
- GET / → serves index.html
- POST /upload or /embed → accepts audio files (python-multipart)
c. Audio Processing Module
- ex_ebd.py logic
- Libraries: SpeechBrain, NumPy, SciPy, PyTorch, torchaudio, PySoundFile
d. Database
- MySQL instance
- Connector: mysql-connector-python
e. (Optional) External integrations
- flack (Slack?) if used for notifications

##### Relationships and data flows
- Browser → HTTP POST to FastAPI → uploads audio
- FastAPI route handler → calls audio processing functions in ex_ebd.py
- ex_ebd.py → loads model weights (SpeechBrain/Torch), computes embeddings → returns arrays
- API handler → uses mysql-connector to INSERT or SELECT embeddings in MySQL
- API handler → returns JSON result → Browser renders response

##### Architectural patterns/design principles
- Separation of concerns:
- Static + template = presentation layer
- FastAPI = application layer (HTTP, request validation)
- ex_ebd.py = domain layer (audio processing business logic)
- MySQL = persistence layer
- Single-process, monolithic architecture (no microservices); but clear module boundaries
- Dependency injection via import of ex_ebd in web.py
- Async or sync endpoints (can be extended to async for I/O)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser UI<br/>(HTTP Client)"]:::frontend
        Template["templates/index.html"]:::frontend
        CSS["static/css/style.css"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        API["FastAPI Server<br/>(web.py)<br/>FastAPI + Uvicorn"]:::api
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Audio["Audio Processing Module<br/>(ex_ebd.py)<br/>SpeechBrain, PyTorch"]:::processor
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DB["MySQL Database"]:::db
    end

    %% Documentation
    Doc["README.md"]:::doc

    %% Connections
    Browser -->|"HTTP GET / POST"| API
    Template -->|served as UI| Browser
    CSS -->|styling assets| Browser
    API -->|"function call / model inference"| Audio
    API -->|"SQL INSERT / SELECT"| DB
    DB -->|"query results"| API
    API -->|"JSON / HTML response"| Browser
    Doc -.->|documentation| API

    %% Click Events
    click Template "https://github.com/szluk133/csdl_dpt/blob/dpt/templates/index.html"
    click CSS "https://github.com/szluk133/csdl_dpt/blob/dpt/static/css/style.css"
    click API "https://github.com/szluk133/csdl_dpt/blob/dpt/web.py"
    click Audio "https://github.com/szluk133/csdl_dpt/blob/dpt/ex_ebd.py"
    click Doc "https://github.com/szluk133/csdl_dpt/blob/dpt/README.md"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,stroke-width:2px;
    classDef api fill:#FFF3E0,stroke:#E65100,stroke-width:2px;
    classDef processor fill:#FFFDE7,stroke:#F9A825,stroke-width:2px;
    classDef db fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px;
    classDef doc fill:#F3E5F5,stroke:#6A1B9A,stroke-width:2px;
```
