# breinerbatalla/spotify-backend-springboot architecture

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

- Interactive diagram: https://gitdiagram.com/breinerbatalla/spotify-backend-springboot
- Repository: https://github.com/breinerbatalla/spotify-backend-springboot

## Overview

##### Main Components
- Entry Point & Application Layer:
- SpotifyApplication.java as the main entry point.
- Controllers (REST API layer):
- AuthController, SongController, and UserController to represent the different API endpoints.
- Service Layer:
- Services such as AuthService, AuthenticationService, SongService, UserService, FileService, and NotificationService. These components contain the business logic.
- Data Access / Repository Layer:
- SongRepository and UserRepository which interact with the database.
- Domain Model:
- Entities like Song and User.
- DTO packages (for both requests and responses) that transfer data between the client and the application.
- Configuration and Security:
- Configuration classes such as ApplicationConfig and AwsConfig.
- SecurityConfig and other JWT related classes (JwtAuthenticationFilter, JwtService, Role) that form the security layer.
- Exception Handling:
- Exception-related components including HandleException and the custom exceptions (e.g., SongNotFoundException, UserNotFoundException) plus ExceptionDto.
- Additional Components:
- Mapper package, which handles conversions between DTOs and entities.

##### Relationships and Interactions
- Directional data flow:
- From incoming HTTP requests hitting controllers to the service layer.
- From the service layer to the repository layer for database interactions.
- For security:
- A gateway or filter (JwtAuthenticationFilter) that intercepts requests and consults the JwtService.
- Link the SecurityConfig to the overall HTTP filter chain.

##### Architectural Patterns and Technologies
- Layered (n-tier) Architecture:
- Divide components into distinct layers: Controller (presentation), Service (business logic), Repository (data access), and Configuration (infrastructure concerns).
- Security via JWT:
- JWT-based authentication and role management which protects several endpoints.
- Use of Spring Boot capabilities for dependency injection and configuration to wire components together.
- Integration point with external systems (AWS described by AwsConfig) for things like file management or notifications.

##### Final Checklist for the Principal Software Engineer
- Component is clearly labeled.
- Architectural separation between layers to illustrate a clean, maintainable design.
- Verify that any external dependencies (like AWS, CI/CD pipelines) are noted, even if they are not active at runtime, as they impact overall system design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CTR("Client Request"):::external

    subgraph "Entry/Application Layer"
        SA("SpotifyApplication (Entry)"):::entry
    end

    subgraph "Controllers (REST API)"
        A("AuthController (REST)"):::controller
        SC("SongController (REST)"):::controller
        UC("UserController (REST)"):::controller
    end

    subgraph "Service Layer"
        AS("AuthService (Business Logic)"):::service
        ATS("AuthenticationService (Business Logic)"):::service
        SS("SongService (Business Logic)"):::service
        US("UserService (Business Logic)"):::service
        FS("FileService (Business Logic)"):::service
        NS("NotificationService (Business Logic)"):::service
    end

    subgraph "Repository Layer"
        SR("SongRepository (Data Access)"):::repository
        UR("UserRepository (Data Access)"):::repository
    end

    subgraph "Domain Model & DTOs"
        SONG("Song (Entity)"):::domain
        USER("User (Entity)"):::domain
        RDTO("Request DTOs"):::domain
        PDT("Response DTOs"):::domain
    end

    subgraph "Configuration & Security"
        AC("ApplicationConfig"):::config
        AW("AwsConfig"):::config
        SCFG("SecurityConfig"):::security
        JF("JwtAuthenticationFilter"):::security
        JS("JwtService"):::security
        RL("Role"):::security
    end

    subgraph "Exception Handling"
        HE("HandleException"):::exception
        ED("ExceptionDto"):::exception
        SN("SongNotFoundException"):::exception
        UN("UserNotFoundException"):::exception
    end

    subgraph "Mapper Components"
        SM("SongMapper"):::mapper
        UM("UserMapper"):::mapper
    end

    subgraph "CI/CD & Build"
        CICD("azure-pipelines.yml"):::cicd
    end

    CTR -->|"checkAuth"| JF
    JF -->|"routes"| A
    JF -->|"routes"| SC
    JF -->|"routes"| UC

    SA -->|"initializes"| A
    SA -->|"initializes"| SC
    SA -->|"initializes"| UC
    SA -->|"bootstraps"| AC
    SA -->|"bootstraps"| AW

    A -->|"calls"| AS
    A -->|"calls"| ATS
    SC -->|"calls"| SS
    UC -->|"calls"| US

    AS -->|"maps"| SM
    US -->|"maps"| UM
    SS -->|"uses"| FS
    SS -->|"uses"| NS

    SS -->|"accesses"| SR
    US -->|"accesses"| UR

    SCFG -->|"uses"| JS
    SCFG -->|"uses"| RL
    JF -->|"configured_by"| SCFG

    A -->|"error"| HE
    SC -->|"error"| HE
    UC -->|"error"| HE
    HE -->|"returns"| ED

    SM -->|"converts"| RDTO
    SM -->|"converts"| PDT
    UM -->|"converts"| RDTO
    UM -->|"converts"| PDT

    classDef entry fill:#b3cde0,stroke:#000,stroke-width:1px;
    classDef controller fill:#ccebc5,stroke:#000,stroke-width:1px;
    classDef service fill:#ffdd94,stroke:#000,stroke-width:1px;
    classDef repository fill:#fbb4ae,stroke:#000,stroke-width:1px;
    classDef domain fill:#decbe4,stroke:#000,stroke-width:1px;
    classDef config fill:#fdae6b,stroke:#000,stroke-width:1px;
    classDef security fill:#9ecae1,stroke:#000,stroke-width:1px;
    classDef exception fill:#fdd0a2,stroke:#000,stroke-width:1px;
    classDef mapper fill:#c7e9c0,stroke:#000,stroke-width:1px;
    classDef cicd fill:#d9d9d9,stroke:#000,stroke-width:1px;
    classDef external fill:#eeeeee,stroke:#000,stroke-dasharray:5,5;

    click SA "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/SpotifyApplication.java"
    click A "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/rest/AuthController.java"
    click SC "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/rest/SongController.java"
    click UC "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/rest/UserController.java"
    click AS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/AuthService.java"
    click ATS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/AuthenticationService.java"
    click SS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/SongService.java"
    click US "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/UserService.java"
    click FS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/FileService.java"
    click NS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/service/NotificationService.java"
    click SR "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/repository/SongRepository.java"
    click UR "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/repository/UserRepository.java"
    click SONG "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/entity/Song.java"
    click USER "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/entity/User.java"
    click RDTO "https://github.com/breinerbatalla/spotify-backend-springboot/tree/main/src/main/java/com/example/spotify/dto/request/"
    click PDT "https://github.com/breinerbatalla/spotify-backend-springboot/tree/main/src/main/java/com/example/spotify/dto/response/"
    click AC "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/ApplicationConfig.java"
    click AW "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/AwsConfig.java"
    click SCFG "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/security/SecurityConfig.java"
    click JF "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/security/JwtAuthenticationFilter.java"
    click JS "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/security/JwtService.java"
    click RL "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/config/security/Role.java"
    click HE "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/exception/HandleException.java"
    click ED "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/exception/ExceptionDto.java"
    click SN "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/exception/SongNotFoundException.java"
    click UN "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/exception/UserNotFoundException.java"
    click SM "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/mapper/SongMapper.java"
    click UM "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/src/main/java/com/example/spotify/mapper/UserMapper.java"
    click CICD "https://github.com/breinerbatalla/spotify-backend-springboot/blob/main/azure-pipelines.yml"
```
