# cr8297408/integrator-core architecture

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

- Interactive diagram: https://gitdiagram.com/cr8297408/integrator-core
- Repository: https://github.com/cr8297408/integrator-core

## Overview

##### Project Type & Purpose
- The service is built with NestJS and is meant to expose an API for product and user management, authentication, and integration with external systems (e.g., financial services).
- The README confirms that it operates as an integrator service with distinct layers (API, Core Domain, Infrastructure) and uses MongoDB for persistence. It also shows evidence of deployment automation (Terraform, Docker, Serverless Framework, GitHub workflows) and AWS Lambda hosting.

##### Analyzing the File Structure
- The project is organized into multiple directories:
- “src”: Contains the main application logic.
- “src/core”: Holds the DDD components – “application” (with its use cases and test files) and “domain” (entities, ports for receiving external service calls, shared error handling, environment configuration).
- “src/infraestructure”: Contains adapters that implement domain interfaces, HTTP controllers & routes, DTOs for requests/responses, interceptors for authorization and logging, MongoDB-related modules/adapters, and environment configuration.
- “infra/terraform”: Contains scripts, configuration files, and variables for infrastructure provisioning, hinting at deployment automation and containerized builds.
- Configuration files such as Dockerfile, GitHub workflows, tsconfig, and environment variables are present to support development, testing, and CI/CD.

##### Main Components
a. External Interfaces & Clients:
- API Consumers (e.g., front-end applications, external services)
- AWS Lambda / API Gateway endpoints (as indicated in the README)

b. API / User Interface Layer:
- HTTP controllers (located in src/infraestructure/http/controller)
- DTOs, Interceptors, and Decorators (e.g., auth guards, logger, error interceptors)
- Swagger documentation endpoint (as per README)

c. Core Domain & Application Layer:
- Use Cases (src/core/application/use-cases)
- Domain Entities (src/core/domain/entities for product and user)
- Domain Ports (interfaces for services like authentication, product repository, JWT, etc.)
- Shared domain elements (error definitions, environment configurations)

d. Infrastructure & Adapters:
- Adapters bridging the core and external systems (e.g., auth-service, financial-core, jwt, and password hashing adapters found in src/infraestructure/adapters)
- Database integration mapped through MongoDB modules and adapters (src/infraestructure/mongodb)
- Environment management and configuration resolvers (local vs. remote as seen in the environment/resolver)

e. Deployment & DevOps:
- Infrastructure provisioning using Terraform (infra/terraform)
- CI/CD pipelines via GitHub Workflows
- Containerization with Docker, and deployment on AWS Lambda, illustrated by the provided Dockerfile and deployment scripts.

##### Architectural Patterns & Design Principles
- Clear separation of concerns: API layer, Core Domain, and Infrastructure.
- Use of DDD with ports and adapters: the core domain defines interfaces while the adapters provide concrete implementations.
- Modularization to support scalability and testability: the “application” and “domain” code are segregated from “infrastructure” concerns.
- Provisioning and CI/CD as integral parts of the design to ensure smooth deployment (via Terraform, Docker, GitHub Workflows, and Serverless Framework).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interfaces
    ExtClients["API Clients & AWS Lambda/API Gateway"]:::external

    %% API / User Interface Layer
    subgraph "API Layer"
        API1["HTTP Controllers"]:::api
        API2["DTOs & Decorators"]:::api
        API3["Interceptors"]:::api
    end

    %% Core Domain & Application Layer
    subgraph "Core Domain"
        C1["Use Cases"]:::core
        C2["Domain Entities"]:::core
        C3["Domain Ports"]:::core
        C4["Shared Domain (Errors & Config)"]:::core
    end

    %% Infrastructure & Adapters
    subgraph "Infrastructure Layer"
        I1["Adapters for External Systems"]:::infra
        I2["MongoDB Integration"]:::database
        I3["Environment Management"]:::infra
    end

    %% Deployment & DevOps
    subgraph "DevOps"
        D1["Terraform Scripts"]:::devops
        D2["CI/CD Pipelines"]:::devops
        D3["Dockerfile"]:::devops
        D4["Image Build & Push Script"]:::devops
    end

    %% Connections from External to API
    ExtClients -->|"sends request"| API1

    %% API Layer to Core Domain
    API1 -->|"invokes"| C1

    %% Core Domain internal interactions
    C1 -->|"uses"| C3
    C1 -->|"processes"| C2
    C3 -->|"refers"| C4

    %% Core Domain to Infrastructure Layer
    C3 -->|"implemented by"| I1
    C3 -->|"persists data"| I2
    C4 -->|"configures"| I3

    %% Click Events for API Layer
    click API1 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/http/controller"
    click API2 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/http/dto"
    click API3 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/http/interceptors"

    %% Click Events for Core Domain Layer
    click C1 "https://github.com/cr8297408/integrator-core/tree/master/src/core/application/use-cases"
    click C2 "https://github.com/cr8297408/integrator-core/tree/master/src/core/domain/entities"
    click C3 "https://github.com/cr8297408/integrator-core/tree/master/src/core/domain/ports"
    click C4 "https://github.com/cr8297408/integrator-core/tree/master/src/core/domain/shared"

    %% Click Events for Infrastructure Layer
    click I1 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/adapters"
    click I2 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/mongodb"
    click I3 "https://github.com/cr8297408/integrator-core/tree/master/src/infraestructure/environment"

    %% Click Events for DevOps Layer
    click D1 "https://github.com/cr8297408/integrator-core/tree/master/infra/terraform"
    click D2 "https://github.com/cr8297408/integrator-core/tree/master/.github/workflows"
    click D3 "https://github.com/cr8297408/integrator-core/tree/master/Dockerfile"
    click D4 "https://github.com/cr8297408/integrator-core/blob/master/infra/terraform/image_build_push.sh"

    %% Styles Definitions
    classDef external fill:#ffe0b2,stroke:#333,stroke-width:2px;
    classDef api fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef core fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef infra fill:#fff9c4,stroke:#333,stroke-width:2px;
    classDef devops fill:#ffcdd2,stroke:#333,stroke-width:2px;
    classDef database fill:#d1c4e9,stroke:#333,stroke-width:2px;
```
