How mayorgacdev/stock-master-api works
Main Architectural Components
a. Presentation Layer (Web API)
• Located in the “src/Training.WebApi” folder.
• Contains Controllers (e.g., CustomersController.cs, WarehouseController.cs), Middleware (TrainingMiddleware.cs), configuration files (appsettings.json), and the Program.cs startup logic.
• Purpose: Expose endpoints for clients to interact with the system.
b. Application Layer
• Found under “src/Training.Application.”
• Organizes business logic including service classes (CustomerService, WarehouseService), request classes (create and validation requests for Customers, Products, Warehouse, etc.), mappings, attributes, validators, and extension methods.
• Purpose: Implement use cases, validations, and orchestrate transactions. This layer acts as the intermediary between the UI (Web API) and the Domain/Infrastructure layers.
c. Domain Layer
• Present in “src/Training.Domain.”
• Contains the core business entities and domain models (e.g., Customer, Product, ProductBrand, Warehouse, etc.), along with common domain value objects (Money, Currency) and utility classes.
• Purpose: Represent the core business logic and rules independent of external concerns.
d. Infrastructure Layer
• Found in “src/Training.Infraestructure.”
• Handles data access through the repository pattern, Entity Framework configurations (including DbContext, configurations for Inventory and Sales entities, migrations), and other system integrations.
• Purpose: Provide implementations for persistence, external data communication, and interface adherence (e.g., IRepository, IUnitOfWork).
e. Common/Shared Layer
• Located under “src/Training.Common.”
• Contains shared utilities such as extension methods, common response formats (Response, PagedResponse, ErrorResponse), pagination, and filtering functionality.
• Purpose: Reduce duplication and centralize logic that is used across multiple layers.
Establish Relationships and Data Flow
• The Web API (Presentation Layer) serves as the entry point. It receives HTTP requests and routes them to the appropriate controllers.
• These controllers interact with the Application Layer (via services and requests) to execute business logic.
• The Application Layer uses domain entities defined in the Domain Layer to enforce business rules.
• For data persistence or external data operations, the Application Layer calls upon the Infrastructure Layer, which implements repository interfaces and handles Entity Framework operations.
• The Common Layer is used by all other layers to provide shared functionalities (e.g., handling responses, applying filters).
Architectural Patterns and Design Principles
• Layered/Clean Architecture: The separation of Presentation, Application, Domain, and Infrastructure is a clear indicator of a layered design that decouples concerns.
• Domain-Driven Design (DDD): The existence of a “Training.Domain” with entities, value objects, and domain logic suggests a DDD approach.
• Use of Repository and Unit of Work Patterns: Embedded in the Infrastructure layer are repository base classes, specification patterns, and unit-of-work interfaces.
• Extension and Attribute-Based Programming: The Application layer has custom attributes (e.g., ServiceAttribute, ValidatorAttribute) used presumably for cross-cutting concerns such as logging, validation, or automatic interface generation.
Final Assembly
• Next, partition the layers vertically or horizontally following the dependency rule – inner layers (Domain, Common) at the core, with external layers (Application, Infrastructure, Web API) branching outward.
• That every key sub-component from the file tree is captured as part of its corresponding layer. For instance, note that “Training.Application/Requests” contains specific requests, and “Training.Infraestructure/Data” includes data access and specification logic.