# crisbrav/desafio2 architecture

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

- Interactive diagram: https://gitdiagram.com/crisbrav/desafio2
- Repository: https://github.com/crisbrav/desafio2

## Overview

##### Project Type and Purpose
- This is a desktop C++ Qt application that simulates the core features of a music-streaming app.
- It uses object-oriented design (POO) to model songs, albums, artists, users, in-app ads, credits, and basic playback queues.
- The system reads and writes flat files (text data and OGG audio assets) in a local “data” directory.

##### File Structure Analysis
Top-level “Desafio-2” directory:
- Domain model classes (.cpp/.h):
– Album, Artista, Cancion, Usuario, Anuncio, Creditos, Plataforma
- Utility data structures: ArregloDinamico (dynamic array), PilaSimple (simple stack), Metricas
- UI boundary: UiReproductor.h (Qt user interface definitions)
- Entry point: main.cpp
- Build output:
– audio/ (OGG files)
– covers/ (album images)
– data/ (albums.txt, artistas.txt, canciones.txt, anuncios.txt, usuarios.txt, favoritos.txt)
– compiled objects, Makefiles, executable

##### Key Architectural Roles
a. Presentation Layer
– Qt UI definitions in UiReproductor.h
– main.cpp initializes QApplication and launches the UI.
b. Application/Service Layer
– Plataforma class orchestrates startup, data loading, event handling and exposes playback APIs to the UI.
c. Domain Model Layer
– Cancion, Album, Artista, Usuario, Anuncio, Creditos
– Relationships:
· Cancion has metadata (duration, bitrate) and belongs to an Album/Artista.
· Usuario has a list of favorite songs.
· Plataforma maintains collections of domain objects.
d. Data Access Layer (Flat-file persistence)
– Plataforma uses ArregloDinamico to load arrays of objects from TXT files in data/.
– Favorites are read/written via archivos favoritos.txt.
e. Playback Engine / Asset Layer
– OGG audio files in audio/
– UI layer calls into Plataforma to queue songs, advertisements (Anuncio), credits (Creditos).

a. Main Components
– UI Layer (Qt Reproductor)
– Service/Controller: Plataforma
– Domain Objects: Cancion, Album, Artista, Usuario, Anuncio, Creditos
– Data Structures: ArregloDinamico, PilaSimple, Metricas
– Persistence: File System (data/*.txt)
– Asset Store: audio/*.ogg, covers/
b. Relationships and Interactions
1. UI ➔ Plataforma
- Playback commands, navigation, user input
2. Plataforma ➔ Domain Objects
- Loads models into ArregloDinamico collections
- Applies business rules (e.g., insert Anuncio every N songs, show Creditos at end)
3. Plataforma ➔ Persistence (data files)
- Read on startup, write favorites on user action
4. Plataforma ➔ Playback Engine
- Streams OGG files from audio/ in ordered sequence
5. Domain Objects ↔ Utility Structures
- Cancion, Album, Artista stored in dynamic arrays
- Creditos pushed onto PilaSimple for end-of-session display
6. Metricas collects runtime statistics from Plataforma
c. Architectural Patterns & Principles
– Layered Architecture: UI, Service, Domain, Persistence, Assets
– Single Responsibility: each class has clear domain focus
– Dependency Inversion: high-level Plataforma depends on abstractions (file format)
– Composition: Plataforma composes dynamic arrays and stacks
d. Key Technologies & Frameworks
– C++17, Qt 6 GUI framework
– Standard I/O streams for file operations
– Custom templates for dynamic arrays and stacks

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        Ui["UiReproductor.h"]:::presentation
        Main["main.cpp"]:::presentation
    end

    subgraph "Service/Controller Layer"
        Plataforma["Plataforma"]:::service
    end

    subgraph "Domain Model Layer"
        Album["Album"]:::domain
        Artista["Artista"]:::domain
        Cancion["Cancion"]:::domain
        Usuario["Usuario"]:::domain
        Anuncio["Anuncio"]:::domain
        Creditos["Creditos"]:::domain
    end

    subgraph "Utility Structures"
        Arreglo["ArregloDinamico"]:::utils
        Pila["PilaSimple"]:::utils
        Metricas["Metricas"]:::utils
        Tipos["Tipos"]:::utils
    end

    subgraph "Persistence Layer"
        AlbumsTxt["albums.txt"]:::persistence
        AnunciosTxt["anuncios.txt"]:::persistence
        ArtistasTxt["artistas.txt"]:::persistence
        CancionesTxt["canciones.txt"]:::persistence
        FavoritosTxt["favoritos.txt"]:::persistence
        UsuariosTxt["usuarios.txt"]:::persistence
    end

    subgraph "Asset Layer"
        Audio["audio/ (OGG files)"]:::assets
        Covers["covers/"]:::assets
    end

    Ui -->|"user events"| Plataforma
    Main -->|"init QApplication"| Plataforma

    Plataforma -->|"loadModels()"| Album
    Plataforma -->|"loadModels()"| Artista
    Plataforma -->|"loadModels()"| Cancion
    Plataforma -->|"loadModels()"| Usuario
    Plataforma -->|"loadModels()"| Anuncio
    Plataforma -->|"loadModels()"| Creditos

    Album --> Arreglo
    Artista --> Arreglo
    Cancion --> Arreglo
    Usuario --> Arreglo
    Creditos --> Pila

    Plataforma -.->|"readTXT"| AlbumsTxt
    Plataforma -.->|"readTXT"| AnunciosTxt
    Plataforma -.->|"readTXT"| ArtistasTxt
    Plataforma -.->|"readTXT"| CancionesTxt
    Plataforma -.->|"readTXT"| FavoritosTxt
    Plataforma -.->|"readTXT"| UsuariosTxt

    Plataforma -.->|"stream(ogg)"| Audio
    Plataforma -.->|"loadImage()"| Covers

    Plataforma -.->|"collectStats()"| Metricas

    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef domain fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef utils fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef persistence fill:#FFA500,stroke:#333,stroke-width:1px
    classDef assets fill:#DDA0DD,stroke:#333,stroke-width:1px

    click Ui "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/UiReproductor.h"
    click Main "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/main.cpp"
    click Plataforma "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Plataforma.h"
    click Plataforma "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Plataforma.cpp"
    click Album "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Album.h"
    click Album "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Album.cpp"
    click Artista "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Artista.h"
    click Artista "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Artista.cpp"
    click Cancion "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Cancion.h"
    click Cancion "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Cancion.cpp"
    click Usuario "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Usuario.h"
    click Usuario "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Usuario.cpp"
    click Anuncio "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Anuncio.h"
    click Anuncio "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Anuncio.cpp"
    click Creditos "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Creditos.h"
    click Creditos "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Creditos.cpp"
    click Arreglo "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/ArregloDinamico.h"
    click Pila "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/PilaSimple.h"
    click Metricas "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Metricas.h"
    click Tipos "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/Tipos.h"
    click AlbumsTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/albums.txt"
    click AnunciosTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/anuncios.txt"
    click ArtistasTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/artistas.txt"
    click CancionesTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/canciones.txt"
    click FavoritosTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/favoritos.txt"
    click UsuariosTxt "https://github.com/crisbrav/desafio2/blob/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/data/usuarios.txt"
    click Audio "https://github.com/crisbrav/desafio2/tree/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/audio/"
    click Covers "https://github.com/crisbrav/desafio2/tree/main/Desafio-2/build/Desktop_Qt_6_9_2_MinGW_64_bit-Debug/covers/"
```
