# ikeem12/prueba_microservicio architecture

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

- Interactive diagram: https://gitdiagram.com/ikeem12/prueba_microservicio
- Repository: https://github.com/ikeem12/prueba_microservicio

## Overview

##### Project type and purpose
- This is a two-microservice backend system (Service-Order and Service-Product), each implemented in Python.
- Each service exposes a REST API (resources), encapsulates business logic (services), persists data (repository), and validates input (schema).
- They are designed to be deployed independently (Dockerfile in service-product, shared pattern in service-order).

##### File structure
Top-level:
- service-order/
– main.py (entry point)
– config.py (configuration)
– requirements.txt
– app/… (layered code)
- service-product/ (same pattern plus Dockerfile)
Inside each app/:
– resources/ (Flask/RESTful resources or controllers)
– services/ (business-rule implementations)
– repository/ (data access classes)
– interfaces/ (abstract interfaces for services + repositories)
– models/ (ORM or domain models)
– schema/ (Pydantic schemas for validation, only in service-order)
– utils/exceptions/extensions/logger (cross-cutting concerns)
This strongly suggests a layered (hexagonal) architecture with clear adapter boundaries.

##### README
- No content provided; our analysis relies on conventions and file organization.

a. Main components
– API Gateway (optional, for routing external clients)
– Service-Order microservice
· Order API (resources)
· Order Service (business logic)
· Order Repository (DB adapter)
· Order Database
– Service-Product microservice
· Product API
· Product Service
· Product Repository
· Product Database
– (Optional) Authentication service, Messaging broker, Monitoring/Logging

b. Relationships and interactions
– External client → API Gateway → Service-Order API
– Service-Order → Order Service → Order Repository → Order Database
– Service-Order may perform HTTP calls to Service-Product API when it needs product details
– Service-Product has analogous internal flow
– (Optional) Async events: new-order → message broker → other consumers

c. Architectural patterns & design principles
– Layered / Hexagonal architecture: Separation of API, business, persistence, and domain model
– Use of interfaces/abstractions to decouple implementation and enable easy mocking/testing
– Pydantic schemas for input validation and clear error handling
– Single Responsibility: each class/folder has a focused concern

d. Technologies & frameworks
– Python 3.x
– Flask (or Flask-RESTful) for resources
– SQLAlchemy or similar ORM in repository layer
– Pydantic for schema validation (service-order)
– Docker for containerization (at least in service-product)
– Logging via custom logger in each service
– requirements.txt for dependency management

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Client["External Client"]:::external
    Gateway["API Gateway"]:::gateway

    %% Service-Order Microservice
    subgraph "Service-Order" 
        direction TB
        SO_Main["main.py"]:::entry
        SO_Config["config.py"]:::config
        subgraph "Resources"
            direction TB
            OrderDetailResource["OrderDetailResource"]:::resource
            OrderListResource["OrderListResource"]:::resource
            ErrorHandler["ErrorHandler"]:::resource
            SuccessResponse["SuccessResponse"]:::resource
        end
        subgraph "Business Logic"
            ServiceOrder["ServiceOrder"]:::service
        end
        subgraph "Repository"
            RepositoryOrder["OrderRepository"]:::repository
        end
        subgraph "Schema/Validation"
            SchemaOrder["SchemaOrder"]:::schema
        end
        subgraph "Interfaces"
            InterfaceServices["InterfacesServices"]:::interface
            InterfaceRepository["InterfacesRepository"]:::interface
        end
        subgraph "Models"
            ModelOrder["Model"]:::model
        end
        subgraph "Exceptions"
            APIExceptions["APIExceptions"]:::exception
            DBExceptions["DBExceptions"]:::exception
            InternalExceptions["InternalExceptions"]:::exception
            PydanticExceptions["PydanticExceptions"]:::exception
        end
        subgraph "Cross-Cutting"
            Extensions["extensions.py"]:::util
            LoggerSO["logger.py"]:::util
            InitComp["initialization_component.py"]:::util
            UtilsSO["utils.py"]:::util
        end
        SO_Requirements["requirements.txt"]:::config
    end

    %% Service-Product Microservice
    subgraph "Service-Product"
        direction TB
        SP_Main["main.py"]:::entry
        SP_Config["config.py"]:::config
        SP_Docker["dockerfile"]:::config
        subgraph "Resources"
            ResourceProd["ProductResource"]:::resource
        end
        subgraph "Business Logic"
            ServiceProd["Service"]:::service
        end
        subgraph "Repository"
            RepositoryProd["ProductRepository"]:::repository
        end
        subgraph "Interfaces"
            InterfaceServiceProd["InterfaceService"]:::interface
            InterfaceRepoProd["InterfacesRepository"]:::interface
        end
        subgraph "Models"
            ModelProd["Model"]:::model
        end
        subgraph "Utilities"
            ExceptionsProd["exceptions.py"]:::exception
            SafeInit["safe_init.py"]:::util
            LoggerSP["logger.py"]:::util
        end
        SP_Requirements["requirements.txt"]:::config
    end

    %% Databases
    DB_Order[(OrderDB)]:::database
    DB_Product[(ProductDB)]:::database

    %% Flows
    Client -->|HTTP Request| Gateway
    Gateway -->|Route to Order| OrderDetailResource
    OrderDetailResource --> ServiceOrder
    OrderListResource --> ServiceOrder
    ServiceOrder --> RepositoryOrder
    RepositoryOrder --> DB_Order
    ServiceOrder -->|HTTP Call| ResourceProd
    ResourceProd --> ServiceProd
    ServiceProd --> RepositoryProd
    RepositoryProd --> DB_Product

    %% Service order startup
    SO_Main --> Extensions
    SO_Main --> LoggerSO
    SO_Main --> InitComp
    SO_Main --> SO_Config

    %% Service product startup
    SP_Main --> LoggerSP
    SP_Main --> SafeInit
    SP_Main --> SP_Config
    SP_Main --> SP_Docker

    %% Click events for Service-Order
    click OrderDetailResource "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/resources/api_v1/OrderDetailResource.py"
    click OrderListResource "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/resources/api_v1/OrderListResource.py"
    click ErrorHandler "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/resources/error_handler.py"
    click SuccessResponse "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/resources/succes_response.py"
    click ServiceOrder "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/services/ServiceOrder.py"
    click RepositoryOrder "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/repository/repository_order.py"
    click SchemaOrder "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/schema/schema_order.py"
    click InterfaceServices "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/interfaces/interfaces_services.py"
    click InterfaceRepository "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/interfaces/interfaces_repository.py"
    click ModelOrder "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/models/model.py"
    click APIExceptions "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/exceptions/api_exceptions.py"
    click DBExceptions "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/exceptions/database_exceptions.py"
    click InternalExceptions "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/exceptions/internal_exceptions.py"
    click PydanticExceptions "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/exceptions/pydantic_exceptions.py"
    click Extensions "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/extensions.py"
    click LoggerSO "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/logger.py"
    click InitComp "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/utils/initialization_component.py"
    click UtilsSO "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/app/utils/utils.py"
    click SO_Main "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/main.py"
    click SO_Config "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/config.py"
    click SO_Requirements "https://github.com/ikeem12/prueba_microservicio/blob/main/service-order/requirements.txt"

    %% Click events for Service-Product
    click ResourceProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/resources/resource.py"
    click ServiceProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/services/service.py"
    click RepositoryProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/repository/repository.py"
    click InterfaceServiceProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/interfaces/interface_service.py"
    click InterfaceRepoProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/interfaces/interfaces_repository.py"
    click ModelProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/models/model.py"
    click ExceptionsProd "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/utils/exceptions.py"
    click SafeInit "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/utils/safe_init.py"
    click LoggerSP "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/app/logger.py"
    click SP_Main "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/main.py"
    click SP_Config "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/config.py"
    click SP_Docker "https://github.com/ikeem12/prueba_microservicio/tree/main/service-product/dockerfile"
    click SP_Requirements "https://github.com/ikeem12/prueba_microservicio/blob/main/service-product/requirements.txt"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:2px
    classDef gateway fill:#bbf,stroke:#333,stroke-width:2px
    classDef entry fill:#cff,stroke:#333,stroke-width:1px
    classDef config fill:#fcf,stroke:#333,stroke-width:1px
    classDef resource fill:#cfc,stroke:#333,stroke-width:1px
    classDef service fill:#ccf,stroke:#333,stroke-width:1px
    classDef repository fill:#ffc,stroke:#333,stroke-width:1px
    classDef schema fill:#fcc,stroke:#333,stroke-width:1px
    classDef interface fill:#eef,stroke:#333,stroke-width:1px
    classDef model fill:#efe,stroke:#333,stroke-width:1px
    classDef exception fill:#fee,stroke:#333,stroke-width:1px
    classDef util fill:#ddf,stroke:#333,stroke-width:1px
    classDef database fill:#333,stroke:#333,stroke-width:2px,shape:cylinder
```
