# josueomar320/crud-api architecture

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

- Interactive diagram: https://gitdiagram.com/josueomar320/crud-api
- Repository: https://github.com/josueomar320/crud-api

## Overview

##### Main Components
- API Layer: This is represented by the "API" directory which contains the ASP.NET Core controllers (e.g., CategoriesController, ClientController, ProductsController, and WeatherForecastController) and the Program.cs file to configure the application. This layer handles HTTP requests and uses Swagger for endpoint documentation.
- Application Layer: Found in the "Application" directory. It includes the DependencyInjection configuration, interfaces, and services (ClientService, ProductService). This layer encapsulates the business logic and service abstractions.
- DataLayer: Contained in the "DataLayer" directory, it holds the Entity Framework DbContext (AppDbContext), entities (Category, Client, Product, ProductCategory), and migrations. This layer manages the persistence and data access.

##### Relationships and Interactions
- The API layer receives HTTP requests from clients, which are then passed to the appropriate controllers.
- Controllers invoke methods on the services in the Application layer (which follow defined interfaces) to perform business logic.
- Services in the Application layer access, update, or query the data by interacting with the DataLayer (via the AppDbContext).
- Dependency Injection is used to wire up controllers, services, and the data context seamlessly.

##### Architectural Patterns and Design Principles
- Layered Architecture: The clear separation between the API (presentation), Application (business logic), and DataLayer (data access).
- Dependency Injection: Used to inject services and the data context, ensuring loose coupling and easier testing.
- Repository/Unit-of-Work-like Pattern: Although not explicitly defined, the DataLayer encapsulates data access logic.
- Service-Oriented Design: The Application layer defines interfaces and service implementations that abstract the underlying data operations.

##### Relevant Technologies
- ASP.NET Core for the API.
- Entity Framework Core for database operations and migrations.
- Swagger for API documentation.
- C# .NET along with dependency injection containers built into ASP.NET Core.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client Request"):::external

    subgraph "API Layer"
        AP1("Program.cs"):::api
        AP2("Controllers"):::api
        AP1 -->|"Configures_DI"| AP2
    end

    subgraph "Application Layer"
        APP1("DependencyInjection.cs"):::app
        APP2("Interfaces"):::app
        APP3("Services"):::app
        APP1 -->|"Registers"| APP3
    end

    subgraph "DataLayer"
        D1("AppDbContext.cs"):::data
        D2("Entities"):::data
        D3("Migrations"):::data
        D1 -->|"Manages"| D2
    end

    Swagger("Swagger Documentation"):::external

    Client -->|"HTTP_Request"| AP2
    AP2 -->|"Calls_Service"| APP3
    APP3 -->|"Access_Data"| D1
    AP1 -->|"Integrates"| Swagger

    click AP1 "https://github.com/josueomar320/crud-api/blob/master/API/Program.cs"
    click AP2 "https://github.com/josueomar320/crud-api/tree/master/API/Controllers"
    click APP1 "https://github.com/josueomar320/crud-api/blob/master/Application/DependencyInjection.cs"
    click APP2 "https://github.com/josueomar320/crud-api/tree/master/Application/Interfaces"
    click APP3 "https://github.com/josueomar320/crud-api/tree/master/Application/Services"
    click D1 "https://github.com/josueomar320/crud-api/blob/master/DataLayer/Data/AppDbContext.cs"
    click D2 "https://github.com/josueomar320/crud-api/tree/master/DataLayer/Entities"
    click D3 "https://github.com/josueomar320/crud-api/tree/master/DataLayer/Migrations"

    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
