# deyvisonborges/mach-catalog-graphql architecture

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

- Interactive diagram: https://gitdiagram.com/deyvisonborges/mach-catalog-graphql
- Repository: https://github.com/deyvisonborges/mach-catalog-graphql

## Overview

##### Main Components Identification
- API Layer: Represent the GraphQL API that forms the public interface. Indicate the endpoints for operations related to categories, products, simple products, and virtual products.
- Application Layer: Include the core business logic, as represented by the various modules under src/app and src/core. These handle use cases such as creating, updating, or fetching product-related data.
- Database Layer: Show integration with Postgres (the primary persistent store) and Redis (for caching or quick-access scenarios). Also highlight Prisma as the ORM that bridges the application logic and the database.
- External Integrations: Mark external components like AWS services (S3, as seen in the aws integration folders), RabbitMQ for messaging, and any other third-party integrations.
- Security & Access Control: Indicate components for JWT implementation and RBAC using guards and decorators.
- Infrastructure & Deployment: Illustrate Docker containerization layers along with orchestrated Kubernetes deployments (supported by the .k8s directory and deployment scripts), as well as CI/CD pipelines via GitHub workflows.

##### Relationships and Interactions
- That security components (e.g., JWT modules, guards, and filters) intercept requests before they reach the business logic layer.
- That external integrations (such as AWS and RabbitMQ) interact with relevant services that either push data (i.e., events) or retrieve data.

##### Architectural Patterns and Design Principles
- Modularization: Emphasize how the project separates concerns by dividing the codebase into clear bounded contexts (e.g., different modules for API, core business logic, integrations, and database).
- Layered Architecture: The system follows a separation between the presentation (GraphQL API), application/core (services, repositories, domain models), and infrastructure (databases and external services).
- Domain-Driven Design Elements: Items in src/core/artifacts indicate the use of domain models, value objects, and repository contracts.
- Microservice-style Organizational Concepts: Though this is a monorepo, the clear separation of modules suggests that each artifact could potentially be a microservice.

##### Incorporating Relevant Technologies
- Nest.js as the primary framework.
- Denote GraphQL and Apollo Client for handling API requests.
- Prisma, Postgres, and Redis as parts of the persistence and caching layers.
- Docker and Kubernetes for containerization and orchestration.
- CI/CD components (GitHub workflows) that help with continuous integration, testing, and deployment.
- Security elements (JWT, RBAC) that secure the API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Request"]:::client

    subgraph "API Layer (GraphQL API)"
        API["GraphQL API (Nest.js & Apollo)"]:::api
        Cat["Category Module"]:::api
        Prod["Product Module"]:::api
        ProdType["Product-Type Module"]:::api
        SimpleProd["Simple Product Module"]:::api
        VirtualProd["Virtual Product Module"]:::api
    end

    subgraph "Security & Access Control"
        Sec["Security (JWT,RBAC)"]:::sec
        SecFilter["Prisma Exception Filter"]:::sec
    end

    subgraph "Application Layer (Business Logic & Domain Services)"
        App["Business Logic / Domain Services"]:::app
        Artifacts["Domain Artifacts"]:::app
    end

    subgraph "Database Layer"
        Prisma["Prisma ORM"]:::db
        PrismaSrv["Prisma Service"]:::db
        RedisDeploy["Redis Deployment"]:::db
        RedisNode["Redis NodePort"]:::db
    end

    subgraph "External Integrations"
        AWSMod["AWS Module"]:::ext
        AWSS3["AWS S3 Service"]:::ext
        RabbitMQ["RabbitMQ Integration"]:::ext
    end

    subgraph "Infrastructure & Deployment"
        Docker["Docker & Compose"]:::infra
        K8s["Kubernetes Configurations"]:::infra
        CICD["CI/CD Pipelines"]:::infra
    end

    Client -- "sendsRequest" --> API
    API -- "routesTo" --> Sec
    Sec -- "validatesAndForwards" --> App
    Sec -- "triggers" --> SecFilter
    App -- "uses" --> Artifacts
    App -- "queriesUpdates" --> Prisma
    App -- "callsORM" --> PrismaSrv
    App -- "cachesWith" --> RedisDeploy
    App -- "cachesWith" --> RedisNode
    App -- "integratesWith" --> AWSMod
    AWSMod -- "uses" --> AWSS3
    App -- "sendsMessagesTo" --> RabbitMQ
    App -- "deployedVia" --> Docker
    Docker -- "orchestratedBy" --> K8s
    K8s -- "monitoredBy" --> CICD

    %% API Layer internal module relations
    API -- "includes" --> Cat
    API -- "includes" --> Prod
    API -- "includes" --> ProdType
    API -- "includes" --> SimpleProd
    API -- "includes" --> VirtualProd

    %% Click Events for API Layer
    click API "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql"
    click Cat "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql/category"
    click Prod "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql/product"
    click ProdType "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql/product-type"
    click SimpleProd "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql/simple-product"
    click VirtualProd "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/api-graphql/virtual-product"

    %% Click Events for Application Layer
    click App "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/core"
    click Artifacts "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/core/artifacts"

    %% Click Events for Database Layer
    click Prisma "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/prisma"
    click PrismaSrv "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/database/prisma"
    click RedisDeploy "https://github.com/deyvisonborges/mach-catalog-graphql/blob/main/.k8s/redis-deployment.yaml"
    click RedisNode "https://github.com/deyvisonborges/mach-catalog-graphql/blob/main/.k8s/redis-nodeport.yaml"

    %% Click Events for External Integrations
    click AWSMod "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/app/integrations/aws"
    click AWSS3 "https://github.com/deyvisonborges/mach-catalog-graphql/blob/main/src/integrations/aws/services/s3.service.ts"
    click RabbitMQ "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/integrations/rabbitmq"

    %% Click Events for Security & Access Control
    click Sec "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/src/external"
    click SecFilter "https://github.com/deyvisonborges/mach-catalog-graphql/blob/main/src/app/filters/prisma-exception.filter.ts"

    %% Click Events for Infrastructure & Deployment
    click Docker "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/Dockerfile"
    click K8s "https://github.com/deyvisonborges/mach-catalog-graphql/blob/main/.k8s"
    click CICD "https://github.com/deyvisonborges/mach-catalog-graphql/tree/main/.github/workflows"

    %% Styles
    classDef client fill:#F0B27A,stroke:#7D3C98,stroke-width:2px;
    classDef api fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef sec fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef app fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef db fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef ext fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
