# rebeldecuantico/online-store-ddd architecture

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

- Interactive diagram: https://gitdiagram.com/rebeldecuantico/online-store-ddd
- Repository: https://github.com/rebeldecuantico/online-store-ddd

## Overview

##### Main Components
- Catalog Service: This is the core business module where products and categories are managed. It includes:
- API layer (CategoryController.cs, ProductController.cs) that exposes endpoints.
- Application layer (commands, queries, DTOs, and event handlers) responsible for business use cases.
- Domain layer (entities such as Category, Product, available stock, Price, etc.) encapsulating business logic.
- Infrastructure layer (repositories, Entity Framework context, entity type configurations, diagnostics, and database migrations) that implements persistence and integration with PostgreSQL and Redis (as indicated in the Settings files).
- Workers (like CatalogWorker.cs) which may perform background tasks.

- Reverse Proxy Service: This acts as the API gateway for the Online Store.
- It contains routing extensions, security components for token handling, service discovery integrations, and a worker (ServiceDiscoveryWorker.cs) for dynamic configurations.
- Its configuration and settings (e.g., OpenIdConnectSettings) are critical for managing authentication, likely integrating with IDP/SSO components.

- Config Server:
- Located under src/configserver, this is a Java-based service (Maven project with pom.xml) that serves as a central configuration management system, delivering configuration settings to the other services.
- This is an example of externalized configuration in a microservices ecosystem.

- Common Library:
- Shared code, contracts, and abstractions that support DDD practices (e.g., Domain/ Entity, AggregateRoot, UnitOfWork) across the solution.
- Contains shared infrastructure pieces (Kafka producer/consumer, service bus implementations, logging facilities, service discovery integration via Consul, etc.).

- Docker and DevOps Components:
- Docker-compose and configuration files in the docker folder indicate that the project is containerized.
- Configuration files such as fluent-bit.conf, grafana-datasources.yaml, loki-config.yaml, otel-collector-config.yaml, parsers.conf, and prometheus.yml suggest integrated logging, monitoring (Prometheus, Grafana), and observability (OpenTelemetry) features.

##### Relationships and Interactions
- Frontend requests (not explicitly shown, but assumed to come via the Reverse Proxy) are accepted by the Reverse Proxy service which handles routing and security verification.
- Reverse Proxy routes incoming API calls to the appropriate backend service – mainly the Catalog service for product and category-related operations.
- The Catalog service’s API layer then orchestrates application logic by invoking the Application layer, which executes commands/queries.
- Domain events (e.g., CategoryAdded, PriceChanged, etc.) trigger side effects and are managed internally to ensure business rules adhere to the DDD model.
- Persistence is handled by the Infrastructure layer via a database context with migrations—for example, PostgreSQL for data storage and Redis for caching.
- The Common library facilitates reusable abstractions (like service discovery, messaging through Kafka, and unit-of-work patterns) that underpin service-to-service communications and distributed system concerns.
- The Config server supplies centralized configurations to the various services, enabling consistent and dynamic configuration management.
- Docker and associated configuration files serve as the bridge for container orchestration, ensuring that logging, metrics, and monitoring are available for operational insights.

##### Architectural Patterns and Design Principles
- Domain-Driven Design is the most obvious guiding principle with clearly separated layers – Domain, Application, and Infrastructure.
- Microservices (or at least service separation): Catalog, Reverse Proxy, and Config Server appear as autonomous components.
- API Gateway pattern is implemented by the Reverse Proxy for centralized request routing.
- Infrastructure concerns (logging, caching, message queuing, service discovery) are abstracted into shared components in the Common library.
- Containerization with Docker ensures that each service can be developed, deployed, and scaled independently with the help of external configuration management, observability, and monitoring tools.

##### Final Recommendations for the Principal Software Engineer
- Client → Reverse Proxy → Catalog API
- Domain events internally in the Catalog service.
- Persistence flows between the Catalog service and PostgreSQL/Redis.
- Configuration flows from Config Server to all services.

This approach will help capture the full stack architecture of the online store project and provide detailed insight into how the system is organized with a focus on DDD principles and modern distributed system design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client Browser"]:::external

    %% Reverse Proxy Service Subgraph
    subgraph "Reverse Proxy Service"
        ReverseProxyAPI["API Gateway & Security"]:::reverse
        ReverseProxyWorker["Service Discovery Worker"]:::reverse
    end

    %% Catalog Service Subgraph
    subgraph "Catalog Service"
        %% API Layer Subgraph
        subgraph "API Layer"
            CatalogCategory["CategoryController.cs"]:::catalog
            CatalogProduct["ProductController.cs"]:::catalog
        end
        %% Application Layer Subgraph
        subgraph "Application Layer"
            CatalogApplication["Application Layer"]:::catalog
        end
        %% Domain Layer Subgraph
        subgraph "Domain Layer"
            CatalogDomain["Domain Layer"]:::catalog
        end
        %% Infrastructure Layer Subgraph
        subgraph "Infrastructure Layer"
            CatalogInfrastructure["Infrastructure Layer"]:::catalog
        end
        %% Workers Subgraph
        subgraph "Workers"
            CatalogWorker["CatalogWorker.cs"]:::catalog
        end
    end

    %% Config and DevOps Subgraph
    subgraph "Config & DevOps"
        ConfigServer["Config Server"]:::config
        DockerDevOps["Docker & DevOps"]:::docker
    end

    %% External Systems Subgraph
    subgraph "External Systems"
        PostgreSQL["PostgreSQL"]:::external
        Redis["Redis"]:::external
        Kafka["Kafka"]:::external
        Grafana["Grafana"]:::external
        Prometheus["Prometheus"]:::external
        OpenTelemetry["OpenTelemetry"]:::external
    end

    %% Flow Connections
    Client -->|"HTTP_Request"| ReverseProxyAPI
    ReverseProxyAPI -->|"Routes_Request"| CatalogCategory
    ReverseProxyAPI -->|"Routes_Request"| CatalogProduct

    CatalogCategory -->|"Forwards"| CatalogApplication
    CatalogProduct -->|"Forwards"| CatalogApplication
    CatalogApplication -->|"Executes"| CatalogDomain
    CatalogDomain -->|"Persists"| CatalogInfrastructure

    CatalogInfrastructure -->|"Stores_Data"| PostgreSQL
    CatalogInfrastructure -->|"Caches_Data"| Redis

    CatalogDomain -->|"Publishes_Event"| CommonLibrary["Common Library"]:::common

    %% Common Library as external shared component
    click CommonLibrary "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/Common/"

    %% Inter-service Configuration
    ReverseProxyAPI -->|"Config_Update"| ConfigServer
    CatalogInfrastructure -->|"Config_Update"| ConfigServer

    %% Docker orchestration connections
    DockerDevOps -->|"Orchestrates"| ReverseProxyAPI
    DockerDevOps -->|"Orchestrates"| CatalogInfrastructure
    DockerDevOps -->|"Orchestrates"| ConfigServer
    DockerDevOps -->|"Logs/Metrics"| Grafana
    DockerDevOps -->|"Logs/Metrics"| Prometheus
    DockerDevOps -->|"Logs/Metrics"| OpenTelemetry

    %% Common Library messaging connection
    CommonLibrary ---|"Messaging"| Kafka
    CommonLibrary ---|"ServiceDiscovery"| ReverseProxyWorker

    %% Click Events for Catalog Service Components
    click CatalogCategory "https://github.com/rebeldecuantico/online-store-ddd/blob/main/src/Catalog/Api/CategoryController.cs"
    click CatalogProduct "https://github.com/rebeldecuantico/online-store-ddd/blob/main/src/Catalog/Api/ProductController.cs"
    click CatalogApplication "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/Catalog/Application/"
    click CatalogDomain "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/Catalog/Domain/"
    click CatalogInfrastructure "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/Catalog/Infrastructure/"
    click CatalogWorker "https://github.com/rebeldecuantico/online-store-ddd/blob/main/src/Catalog/Workers/CatalogWorker.cs"

    %% Click Events for Reverse Proxy Components
    click ReverseProxyAPI "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/ReverseProxy/"
    click ReverseProxyWorker "https://github.com/rebeldecuantico/online-store-ddd/blob/main/src/ReverseProxy/Workers/ServiceDiscoveryWorker.cs"

    %% Click Events for Config & DevOps
    click ConfigServer "https://github.com/rebeldecuantico/online-store-ddd/tree/main/src/configserver/"
    click DockerDevOps "https://github.com/rebeldecuantico/online-store-ddd/tree/main/docker/"

    %% Styles
    classDef catalog fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef reverse fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef common fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef docker fill:#D5DBDB,stroke:#566573,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#943126,stroke-width:2px;
```
