# marcosnasc/product-management-api architecture

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

- Interactive diagram: https://gitdiagram.com/marcosnasc/product-management-api
- Repository: https://github.com/marcosnasc/product-management-api

## Overview

##### Project Type and Purpose
- This project is a backend REST API designed for product management. It implements Clean Architecture using Domain-Driven Design (DDD) principles. The API handles operations such as creating, updating, and querying products and categories.
- Key responsibilities also include handling image uploads through a simulated AWS S3 (using LocalStack) and persisting data in PostgreSQL, with Entity Framework Core as the ORM.

##### Analyzing the File Structure
- The solution is divided into clear layers:
- ProductManagement.API – Contains Controllers, dependency injection configurations, API-specific DTOs, and startup setup.
- ProductManagement.Application – Contains UseCases (Commands, Queries, and their Handlers), service interfaces, and common result/wrapper types.
- ProductManagement.Domain – Defines core entities like Product and Category, along with domain logic.
- ProductManagement.Infrastructure – Manages database persistence (AppDbContext, EF Core configurations, migrations) and external services (e.g., StorageService simulating S3 via LocalStack) along with repository implementations.
- Additional files such as Dockerfile, docker-compose.yml, and shell scripts (database-init.sh, localstack-init.sh) indicate containerization and automated environment initialization.

##### Key Architectural Components
a. Main Components:
- API Layer: Represented by “ProductManagement.API” which includes Controllers and configuration (e.g., program startup, dependency injection).
- Application Layer: Contains UseCase Handlers (for Commands and Queries) and interfaces that abstract business logic.
- Domain Layer: Hosts the core Entities (Product, Category) encapsulating business rules.
- Infrastructure Layer: Contains EF Core repositories, database context (AppDbContext & migrations), and external service integrations like the StorageService.
- External Systems:
- PostgreSQL Database – for relational data persistence.
- AWS S3/LocalStack – for handling product image uploads.
- Docker Containers – representing the containerized deployment including the API service, PostgreSQL, and LocalStack.

b. Relationships and Interactions:
- Controllers receive HTTP requests.
- Controllers delegate processing to UseCase Handlers.
- UseCase Handlers invoke domain operations and interact with Repository Interfaces.
- Repository Interfaces are implemented in the Infrastructure layer which, in turn, communicate with PostgreSQL and external storage services.
- That dependency injection is used to invert control: The API layer depends on interfaces (like IProductRepository, IStorageService) while the concrete implementations reside in the Infrastructure layer.
- Command-Query Separation: Separate flows for commands (action-based operations) and queries (data fetching) even if not full-blown CQRS.

c. Architectural Patterns & Design Principles:
- Clean Architecture / Layered Architecture: Emphasizing the separation of concerns across API, Application, Domain, and Infrastructure.
- SOLID Principles: Point out that Single-Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles govern the design.
- Dependency Injection: Note that components are loosely coupled through DI.
- Command-Query Separation: Clarify the distinction between handling commands (e.g., CreateProductCommand) and queries (e.g., GetProductsWithFiltersQuery).

d. Relevant Technologies:
- .NET 8 for API development.
- Entity Framework Core for ORM and migrations.
- PostgreSQL as the relational database.
- LocalStack (simulated AWS S3) for file storage.
- Docker & Docker Compose for containerized deployment.
- Swagger for API documentation.

##### Essential Elements
- Each component should be clearly labeled.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        API["API Layer - Controllers & Startup"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        APP["Application Layer - Use Cases & Service Interfaces"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DOMAIN["Domain Layer - Core Entities (Product, Category)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        INFRA["Infrastructure Layer"]:::infra
        PERSIST["Database Context & Migrations"]:::infra
        REPOS["Repository Implementations"]:::infra
        STORAGE["Storage Service (S3 Simulation)"]:::infra
    end

    %% External Systems
    subgraph "External Systems"
        DB["PostgreSQL Database"]:::external
        LOCALSTACK["LocalStack (S3 Simulation)"]:::external
    end

    %% Containerization & Environment Initialization
    subgraph "Containerization & Environment"
        DOCKER["Dockerfile (API Setup)"]:::container
        DOCKER_COMPOSE["docker-compose.yml"]:::container
        DB_INIT["database-init.sh"]:::container
        LOCALSTACK_INIT["localstack-init.sh"]:::container
    end

    %% Flow Connections
    API -->|"delegates"| APP
    APP -->|"invokes"| DOMAIN
    APP -->|"usesInterfaces"| INFRA
    INFRA -->|"manages"| PERSIST
    INFRA -->|"manages"| REPOS
    INFRA -->|"utilizes"| STORAGE
    PERSIST -->|"persistsData"| DB
    REPOS -->|"persistsData"| DB
    STORAGE -->|"uploadsImages"| LOCALSTACK

    %% Containerization Connections
    DOCKER -->|"containerizes"| API
    DOCKER_COMPOSE -->|"orchestrates"| DOCKER
    DOCKER_COMPOSE -->|"orchestrates"| DB_INIT
    DOCKER_COMPOSE -->|"orchestrates"| LOCALSTACK_INIT
    DOCKER_COMPOSE -->|"orchestrates"| DB
    DOCKER_COMPOSE -->|"orchestrates"| LOCALSTACK

    %% Click Events
    click API "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/ProductManagement.API"
    click APP "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/ProductManagement.Application"
    click DOMAIN "https://github.com/marcosnasc/product-management-api/tree/develop/ProductManagement/src/ProductManagement.Domain/Entities"
    click INFRA "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/ProductManagement.Infrastructure"
    click PERSIST "https://github.com/marcosnasc/product-management-api/tree/develop/ProductManagement/src/ProductManagement.Infrastructure/Persistence"
    click REPOS "https://github.com/marcosnasc/product-management-api/tree/develop/ProductManagement/src/ProductManagement.Infrastructure/Repositories"
    click STORAGE "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/ProductManagement.Infrastructure/Services/StorageService.cs"
    click DOCKER "https://github.com/marcosnasc/product-management-api/tree/develop/ProductManagement/src/ProductManagement.API/Dockerfile"
    click DOCKER_COMPOSE "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/docker-compose.yml"
    click DB_INIT "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/database-init.sh"
    click LOCALSTACK_INIT "https://github.com/marcosnasc/product-management-api/blob/develop/ProductManagement/src/localstack-init.sh"

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef app fill:#c3e6cb,stroke:#155724,stroke-width:2px;
    classDef domain fill:#d6d8d9,stroke:#1b1e21,stroke-width:2px;
    classDef infra fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef container fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
