# gracielacontreras/crud-springboot-mongo-back architecture

> Architecture diagram of the GitHub repository gracielacontreras/crud-springboot-mongo-back, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gracielacontreras/crud-springboot-mongo-back
- Repository: https://github.com/gracielacontreras/crud-springboot-mongo-back

## Overview

This project is a Spring Boot application designed to implement CRUD operations backed by a MongoDB database. The application is structured using a layered architecture, with clearly separated concerns including controllers, services, repositories, and global error handling. The use of Maven for project management and a Docker Compose configuration for running MongoDB adds to the overall clarity and modularity of the design.

##### Main Components
- Client/Request Origin: Although not explicitly detailed in the project, consider the API consumer (e.g., Postman or frontend client).
- Controller Layer: Illustrated by the ProductController class in the "crud/controller" directory – this exposes REST endpoints.
- Service Layer: Represented by the ProductService class in the "crud/service" folder. This layer contains business logic.
- Repository Layer: Shown by ProductRepository inside "crud/repository" – it interfaces with MongoDB.
- Domain/Data Transfer Objects: Include the Product entity, ProductDTO, and global DTO (like MessageDto) for data transmission.
- Exception Handling: The "global/exceptions" package contains several exception classes that capture errors in a centralized manner.
- Database: MongoDB, which is configured to run via Docker (as indicated by docker-compose.yml and README instructions for creating a database named “tutorial” with a “products” collection).

##### Architectural Relationships and Data Flow
- Incoming requests (HTTP) hit the Controller (ProductController), which then calls the Service (ProductService) layer.
- The Service layer performs business logic and delegates data access requests to the Repository (ProductRepository).
- The Repository interacts with MongoDB to perform CRUD operations.
- Global exception handling is integrated across the layers to capture and handle errors, providing standardized error responses.

##### Important Architectural Patterns/Principles
- Layered (or N-tier) architecture.
- Clear separation of concerns (Controller, Service, Repository).
- Exception Handling through centralized global exceptions.
- Use of DTOs to decouple internal data models from external representations.
- The integration of a Docker-based external service (MongoDB) emphasizes a containerized approach.

##### Technologies and Frameworks Highlighted
- Spring Boot for building the REST API.
- Maven for project and dependency management.
- MongoDB as the primary data store.
- Docker and Docker Compose for deployment and environment setup.
- JUnit or similar (as hinted by the tests directory) for unit testing.

- Docker as an encapsulated external service, labeling it (e.g., “MongoDB Docker Container”).
- Optionally, include supplementary information such as testing components and configuration files (like application.yml and pom.xml) if needed to emphasize build and deployment details.
- Global components such as exception handling and DTO utilities, as these are crucial for proper error management and data transformation in the application.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Top-Level Layer: Client
    subgraph "Client Layer"
        API["API Consumer"]:::client
    end

    %% Controller Layer
    subgraph "Controller Layer"
        PC["ProductController"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        PS["ProductService"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        PR["ProductRepository"]:::repository
    end

    %% Database Layer
    subgraph "Database"
        DB["MongoDB Docker Container<br/>(tutorial DB, products collection)"]:::database
    end

    %% Domain & DTOs
    subgraph "Domain & DTOs"
        E["Product Entity"]:::domain
        DTO["ProductDTO"]:::domain
        GDTO["Global Message DTO"]:::domain
    end

    %% Global Exception Handling
    subgraph "Global Exception Handling"
        AE["AttibuteException"]:::exception
        GE["GlobalException"]:::exception
        RNF["ResourceNotFoundException"]:::exception
    end

    %% Configuration and Deployment
    subgraph "Configuration/Deployment"
        CONF["application.yml"]:::config
        DOCKER["docker-compose.yml"]:::config
        MAVEN["pom.xml"]:::config
    end

    %% Main Data Flow
    API -->|"HTTP Request"| PC
    PC -->|"calls"| PS
    PS -->|"delegates CRUD"| PR
    PR -->|"performs operations"| DB

    %% Supporting Data Mapping and Exception Flow
    PC -.->|"maps errors"| GE
    PC -.->|"handles exceptions"| AE
    PC -.-> RNF
    PS -.-> DTO
    PS -.-> E

    %% Configuration Support
    DOCKER --- DB
    CONF --- PC
    CONF --- PS
    CONF --- PR
    MAVEN --- PS

    %% Click Events
    click PC "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/crud/controller/ProductController.java"
    click PS "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/crud/service/ProductService.java"
    click PR "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/crud/repository/ProductRepository.java"
    click E "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/crud/entities/Product.java"
    click DTO "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/crud/dto/ProductDTO.java"
    click GDTO "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/global/dto/MessageDto.java"
    click AE "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/global/exceptions/AttibuteException.java"
    click GE "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/global/exceptions/GlobalException.java"
    click RNF "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/java/com/tutorial/crudspringbootmongoback/global/exceptions/ResourceNotFoundException.java"
    click CONF "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/src/main/resources/application.yml"
    click DOCKER "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/docker-compose.yml"
    click MAVEN "https://github.com/gracielacontreras/crud-springboot-mongo-back/blob/main/pom.xml"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#bfb,stroke:#333,stroke-width:2px;
    classDef repository fill:#ffb,stroke:#333,stroke-width:2px;
    classDef database fill:#fdd,stroke:#333,stroke-width:2px;
    classDef domain fill:#dfd,stroke:#333,stroke-width:2px;
    classDef exception fill:#fdd,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;
    classDef config fill:#ddd,stroke:#333,stroke-width:2px,stroke-dasharray: 2,2;
```
