How marcosnasc/product-management-api works
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!