# shonsagoro/valoration_microservice_onwork architecture

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

- Interactive diagram: https://gitdiagram.com/shonsagoro/valoration_microservice_onwork
- Repository: https://github.com/shonsagoro/valoration_microservice_onwork

## Overview

- Client/API Gateway: Although not explicitly shown as a separate frontend, assume clients will communicate with the system via exposed API endpoints.
- Middleware (JWT Middleware): A component that intercepts requests to handle authentication.
- Publication Management Service:
- Application Layer: Contains DTOs (both request and response), mappers, and use cases.
- Domain Layer: Contains core entities (e.g., publication and comment) and domain ports (interfaces).
- Infrastructure Layer: Contains controllers, endpoints, DAOs, mappers for data translation, repository implementations (MongoDB repositories), S3 image upload service, and dependency configurations.
- Reviews Management Service:
- Similarly organized with its own application, domain, and infrastructure layers.
- Contains DTOs, use cases (for creation, deletion, update, and fetching of valorations), domain entities (such as valoration and comment), and infrastructure details like controllers, endpoints, DAOs, repositories, and attached S3 image upload functionality.
- Database: MongoDB is used (shown in src/database/mongodb.py and interacting with repositories).
- External resources: S3 service for image uploads that is integrated into both the publication and reviews management infrastructures.

##### Displaying Relationships and Interactions
- From the middleware, show traffic splitting into the two main services:
- Requests related to publications (creating, updating, listing, or deleting publications/comments) are handled by the Publication Management Service.
- Requests concerning reviews/valorations are handled by the Reviews Management Service.
- Within each service, illustrate:
- A flow from the “endpoint” (exposed API routes/controllers) to the “application layer” where use cases are invoked.
- Interaction between the application layer and the domain layer (with entities and business rules).
- The application layer reaching out to the infrastructure layer for persistence (via repository interfaces and their MongoDB implementations) and external services (like S3 uploads).
- That both services communicate with the MongoDB database (depicted as a shared resource or as separate containers if they are intended to be independent).

##### Architectural Patterns and Design Principles
- Separation of concerns through the layered (or clean) architecture: clearly demarcate the application, domain, and infrastructure layers.
- Dependency inversion: domain ports (interfaces) in both services abstract away the infrastructure details, enabling the use of specific implementations that interact with MongoDB.
- Microservices principle: both Publication Management and Reviews Management are designed as standalone modules, maintaining isolation while sharing common middleware and database access.
- API controllers and endpoint routing to underscore the RESTful design pattern.

##### Relevant Technologies and Frameworks
- Python (as evident from the file types and project structure).
- MongoDB (for data storage).
- JWT for user authentication in the middleware.
- AWS S3 (for image uploads in both modules).
- Docker (containerization of the application).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["API Client/Gateway"]:::client
    B["JWT Middleware"]:::middleware

    A -->|"sends_request"| B

    subgraph "Publication Management Service"
        P1["Application Layer: DTOs,UseCases,Mappers"]:::application
        P2["Domain Layer: Entities,Ports"]:::domain
        P3["Infrastructure Layer: Controllers,Endpoints,DAOs,Repositories,S3Upload"]:::infrastructure
        P1 --> P2
        P1 --> P3
        P2 --> P3
    end

    subgraph "Reviews Management Service"
        R1["Application Layer: DTOs,UseCases,Mappers,Services"]:::application
        R2["Domain Layer: Entities,Ports"]:::domain
        R3["Infrastructure Layer: Controllers,Endpoints,DAOs,Repositories,S3Upload"]:::infrastructure
        R1 --> R2
        R1 --> R3
        R2 --> R3
    end

    B -->|"routes_to_publication"| P1
    B -->|"routes_to_reviews"| R1

    D["Database: MongoDB"]:::database
    S["External Service: AWS S3"]:::external
    DO["Docker Container (Deployment)"]:::container

    P3 -->|"uses_DB"| D
    P3 -->|"uploads_to"| S
    R3 -->|"uses_DB"| D
    R3 -->|"uploads_to"| S

    P3 -->|"deployed_with"| DO
    R3 -->|"deployed_with"| DO

    click B "https://github.com/shonsagoro/valoration_microservice_onwork/blob/main/src/middleware/jwt_middleware.py"
    click P1 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/publication_management/application"
    click P2 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/publication_management/domain"
    click P3 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/publication_management/infraestructure"
    click R1 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/reviews_management/application"
    click R2 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/reviews_management/domain"
    click R3 "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/src/reviews_management/infraestructure"
    click D "https://github.com/shonsagoro/valoration_microservice_onwork/blob/main/src/database/mongodb.py"
    click DO "https://github.com/shonsagoro/valoration_microservice_onwork/tree/main/Dockerfile"

    classDef client fill:#C0C0C0,stroke:#000,stroke-width:2px
    classDef middleware fill:#ffcccb,stroke:#000,stroke-width:2px
    classDef application fill:#add8e6,stroke:#000,stroke-width:2px
    classDef domain fill:#90ee90,stroke:#000,stroke-width:2px
    classDef infrastructure fill:#ffffcc,stroke:#000,stroke-width:2px
    classDef database fill:#d3d3d3,stroke:#000,stroke-width:2px
    classDef external fill:#ffdead,stroke:#000,stroke-width:2px
    classDef container fill:#e6e6fa,stroke:#000,stroke-width:2px
```
