# 0xroguex/watchlistapplication architecture

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

- Interactive diagram: https://gitdiagram.com/0xroguex/watchlistapplication
- Repository: https://github.com/0xroguex/watchlistapplication

## Overview

##### And Label Main Components
- Frontend (Presentation Layer):
- Thymeleaf templates (home.html, watchlist.html, watchlistItemForm.html) as the user interface.
- That these views render HTML pages which are served by the backend.

- Backend (Application Layer):
- Controllers: Include MovieController.java which handles incoming HTTP requests (e.g., form submissions, displaying the watchlist, etc.).
- The DatabaseService coordinates data persistence and retrieval (via JPA).
- The RatingService is responsible for external API integration with services such as OMDB.
- Entities: Highlight the Movie.java entity along with its custom validations in sub-packages (Rating and Priority validations).
- That these enforce business rules, ensuring valid movie data (rating between 5–10, priority as 'L', 'M', or 'H').
- Repository: Include MovieRepo.java, which abstracts the CRUD operations using Spring Data JPA.
- Application Entry Point: Mark WatchlistApplication.java as the bootstrap class for Spring Boot.

- Data Persistence Layer:
- Mention that application.properties configures the required connection parameters.

- External Services:
- OMDB API: Include an external block for the OMDB API.
- Call from the RatingService to OMDB, illustrating how external data enhances the movie data.

##### Relationships and Interactions
- Beginning at the user’s browser where HTTP requests are initiated.

- Dependency directions:
- The controller depends on both services.
- Services invoke the repository and/or external API calls.
- The application startup (WatchlistApplication) initializes the entire context.

##### Architectural Patterns and Design Principles
- Use the MVC (Model-View-Controller) pattern:
- Model: Movie entity (and its validations).
- View: Thymeleaf templates.
- Controller: MovieController for routing and handling user actions.
- Layered architecture:
- Separation of concerns between presentation (views), business logic (services), data access (repositories), and configuration.
- Integration of custom validation logic:
- “validations” folder under the entity component, showing how Priority and Rating validations are applied.
- Mention dependency injection provided by Spring Boot and configurations centralized in application.properties.

##### Specific Technologies, Frameworks, and Tools
- Spring Boot for application configuration and bootstrapping.
- Spring Data JPA and Hibernate for ORM.
- Thymeleaf for server-side view rendering.
- PostgreSQL as the production database.
- Maven for build automation and dependency management.
- (Optionally) OMDB API for external movie rating integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User and Systems
    UB("User Browser"):::external

    omdb("OMDB API"):::external
    db("PostgreSQL"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        thHome("Thymeleaf - Home (index.html)"):::frontend
        thWatchlist("Thymeleaf - Watchlist (watchlist.html)"):::frontend
        thForm("Thymeleaf - WatchlistItemForm (watchlistItemForm.html)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        app("WatchlistApplication"):::bootstrap
        ctrl("MovieController"):::controller
        dbService("DatabaseService"):::service
        ratingService("RatingService"):::service
        repo("MovieRepo"):::repository
        config("application.properties"):::config

        subgraph "Entity Layer"
            movieEntity("Movie Entity (Movie.java)"):::entity
            priority("Priority Validation (Priority.java)"):::entity
            priorityLogic("PriorityAnnotationLogic (PriorityAnnotationLogic.java)"):::entity
            ratingVal("Rating Validation (Rating.java)"):::entity
            ratingLogic("RatingAnnotationLogic (RatingAnnotationLogic.java)"):::entity
        end
    end

    %% Arrows: Frontend Interactions
    UB -->|"views"| thHome
    UB -->|"views"| thWatchlist
    UB -->|"views"| thForm

    thHome -->|"submits request"| ctrl
    thWatchlist -->|"submits request"| ctrl
    thForm -->|"submits form"| ctrl

    %% Bootstrapping and Controller Routing
    app -->|"initializes"| ctrl
    ctrl -->|"handles CRUD"| dbService
    ctrl -->|"fetches ratings"| ratingService

    %% Service to Repository and Entity
    dbService -->|"persists data via"| repo
    dbService -->|"validates using"| movieEntity

    %% Repository to Database
    repo -->|"CRUD operations"| db

    %% External API Interaction
    ratingService -->|"calls"| omdb
    omdb -->|"returns data"| ratingService

    %% Configuration Usage
    config -->|"configures"| dbService

    %% Click Events
    click thHome "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/resources/templates/index.html"
    click thWatchlist "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/resources/templates/watchlist.html"
    click thForm "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/resources/templates/watchlistItemForm.html"
    click ctrl "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/controller/MovieController.java"
    click dbService "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/service/DatabaseService.java"
    click ratingService "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/service/RatingService.java"
    click movieEntity "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/entity/Movie.java"
    click priority "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/entity/validations/Priority.java"
    click priorityLogic "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/entity/validations/PriorityAnnotationLogic.java"
    click ratingVal "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/entity/validations/Rating.java"
    click ratingLogic "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/entity/validations/RatingAnnotationLogic.java"
    click repo "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/repository/MovieRepo.java"
    click app "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/java/com/example/spring/watchlist/WatchlistApplication.java"
    click config "https://github.com/0xroguex/watchlistapplication/blob/main/src/main/resources/application.properties"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef controller fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef entity fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef repository fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef bootstrap fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#F0E68C,stroke:#000,stroke-width:2px;
```
