# youseefnoaman/planet-task architecture

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

- Interactive diagram: https://gitdiagram.com/youseefnoaman/planet-task
- Repository: https://github.com/youseefnoaman/planet-task

## Overview

##### Main Components
- API Layer (Controllers): Represented by the various controllers (BookController, ReservationController, UserController, and ControllerExceptionHandler). These are responsible for handling HTTP requests, invoking business logic, and returning responses.
- Service Layer: Contains business logic using services (BookService, ReservationService, UserService, and the ReservationScheduler which likely handles scheduled tasks such as reservation clean-up or notifications).
- Data Access Layer (Repositories): Composed of interfaces like BookRepository, ReservationRepository, and UserRepository that likely use Spring Data JPA to interact with the underlying database.
- Domain/Model Entities: Consist of domain classes (Book, Reservation, User, BaseEntity) and DTOs (BookDTO, ReservationDTO, UserDTO) used for data transfer, encapsulating the business model.
- Configuration and Utilities: Includes configuration classes such as SwaggerConfig (for API documentation) and utility classes like NotFoundException.
- External Components/Infrastructure:
- Database: Even though the actual database service isn’t explicitly visible in the file tree, it will be part of the configuration (likely defined in application.yml and managed by Spring Boot).
- Docker: Presence of dockerfile and docker-compose.yml suggest containerization and possibly orchestration with external services (like a database or other microservices).
- Maven Build Tool: pom.xml and Maven wrapper files indicate the management of dependencies and build configuration.

##### Relationships and Interactions
- Controllers invoke corresponding Service components to handle business logic.
- Services rely on Repositories for data access (CRUD operations against the database).
- Domain models and DTOs are used to pass data between layers, with controllers possibly converting between DTOs and domain entities.
- The Swagger configuration integrates with the controllers to provide interactive API documentation.
- Docker tools allow for application containerization and eventual deployment, where components like the application runtime and the database could be visualized as separate containers interacting together.

##### Key Architectural Patterns and Principles
- Layered (n-tier) architecture: Each layer (Controller, Service, Repository) has clear responsibilities.
- MVC conventions (in terms of how the controllers and views are separated, even though it’s an API-only application).
- Exception Handling: There is a dedicated ControllerExceptionHandler to manage error responses and maintain a clean separation of concerns.
- Separation of concerns: Each package (domain, model, service, repos) encapsulates specific responsibilities.
- Use of DTOs for decoupling internal domain models from client-facing API objects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        BC["BookController"]:::api
        RC["ReservationController"]:::api
        UC["UserController"]:::api
        CEH["ControllerExceptionHandler"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        BS["BookService"]:::service
        RS["ReservationService"]:::service
        US["UserService"]:::service
        RSch["ReservationScheduler"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        BR["BookRepository"]:::repo
        RR["ReservationRepository"]:::repo
        UR["UserRepository"]:::repo
    end

    %% Domain/Model Layer
    subgraph "Domain/Model Layer"
        BE["BaseEntity"]:::domain
        B["Book"]:::domain
        R["Reservation"]:::domain
        U["User"]:::domain
        BDTO["BookDTO"]:::dto
        RDTO["ReservationDTO"]:::dto
        UDTO["UserDTO"]:::dto
        RStat["ReservationStatus"]:::dto
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        SC["SwaggerConfig"]:::config
        AY["application.yml"]:::config
        NFE["NotFoundException"]:::config
    end

    %% External Components
    subgraph "External Components"
        DB["Database"]:::external
        DC["docker-compose.yml"]:::external
        DF["dockerfile"]:::external
        MB["pom.xml / mvnw / .mvn/"]:::external
        SU["Swagger UI"]:::external
    end

    %% Relationships
    %% Controllers to Services
    BC -->|"calls"| BS
    RC -->|"calls"| RS
    UC -->|"calls"| US
    RSch -->|"triggers"| RS

    %% Services to Repositories
    BS -->|"uses"| BR
    RS -->|"uses"| RR
    US -->|"uses"| UR

    %% Repositories to Database
    BR -->|"persists"| DB
    RR -->|"persists"| DB
    UR -->|"persists"| DB

    %% Global Exception Handling
    CEH -->|"handles"| BC
    CEH -->|"handles"| RC
    CEH -->|"handles"| UC

    %% Swagger Integration
    SC -->|"configures"| SU
    SU -->|"documents"| BC

    %% Styles for clarity
    classDef api fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef service fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef repo fill:#ffcc99,stroke:#000,stroke-width:1px;
    classDef domain fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef dto fill:#fff2cc,stroke:#000,stroke-width:1px;
    classDef config fill:#d8bfd8,stroke:#000,stroke-width:1px;
    classDef external fill:#f5f5f5,stroke:#000,stroke-width:1px;

    %% Click Events for API Layer
    click BC "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/controller/BookController.java"
    click RC "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/controller/ReservationController.java"
    click UC "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/controller/UserController.java"
    click CEH "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/controller/ControllerExceptionHandler.java"

    %% Click Events for Service Layer
    click BS "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/service/BookService.java"
    click RS "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/service/ReservationService.java"
    click US "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/service/UserService.java"
    click RSch "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/service/ReservationScheduler.java"

    %% Click Events for Repository Layer
    click BR "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/repos/BookRepository.java"
    click RR "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/repos/ReservationRepository.java"
    click UR "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/repos/UserRepository.java"

    %% Click Events for Domain/Model Layer
    click BE "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/domain/BaseEntity.java"
    click B "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/domain/Book.java"
    click R "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/domain/Reservation.java"
    click U "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/domain/User.java"
    click BDTO "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/model/BookDTO.java"
    click RDTO "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/model/ReservationDTO.java"
    click UDTO "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/model/UserDTO.java"
    click RStat "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/model/ReservationStatus.java"

    %% Click Events for Configuration & Utilities
    click SC "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/config/SwaggerConfig.java"
    click AY "https://github.com/youseefnoaman/planet-task/blob/master/src/main/resources/application.yml"
    click NFE "https://github.com/youseefnoaman/planet-task/blob/master/src/main/java/planettask/util/NotFoundException.java"

    %% Click Events for External Components
    click DC "https://github.com/youseefnoaman/planet-task/blob/master/docker-compose.yml"
    click DF "https://github.com/youseefnoaman/planet-task/tree/master/dockerfile"
    click MB "https://github.com/youseefnoaman/planet-task/blob/master/pom.xml"
```
