# mauriciofrc/shop architecture

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

- Interactive diagram: https://gitdiagram.com/mauriciofrc/shop
- Repository: https://github.com/mauriciofrc/shop

## Overview

##### Main Components
- Frontend: The "shop-front" directory represents the client-side application built with Next.js. This is the user-facing interface.
- Backend API Server: The "Shop.Server" directory contains controllers, middleware, and the main Program.cs that bootstraps the service. This component exposes RESTful endpoints and handles HTTP requests.
- Domain/Core Layer: The “Core” directory contains domain models, DTOs, interfaces (both for repositories and services), and request models. This layer represents the business logic contracts and data transfer objects.
- Data persistence: AplicationDbContext.cs, EF Core migrations, and configurations.
- Repository implementations: Repositories for Category, Order, Payment, etc.
- Service implementations: Concrete services that implement interfaces defined in the Core.
- Mappings and validations: For translating between entities and DTOs, and ensuring correctness of data.
- Database: A relational database (configured in appsettings.Development.json) which is used by EF Core.
- External Services & Deployment Artifacts: While not explicitly listed as external services, tools like Docker (with Dockerfile provided) are used to build and run the application.

##### Interactions and Relationships
- The Frontend sends HTTP requests to the Backend API Server.
- The API server (Shop.Server) employs middleware (like the ExceptionHandlerMiddleware) to intercept and handle errors.
- Controllers in Shop.Server use dependency injection to interact with service classes in Infrastructure.
- The Infrastructure layer encapsulates business logic for CRUD operations and applies validations and mapping between Domain Entities (Core/Entities) and Data Transfer Objects (DTOs in Core/DTOs).
- Repository interfaces in the Core are implemented by repository classes in Infrastructure, abstracting access to the database.
- The EF Core’s ApplicationDbContext (in Infrastructure/Context) manages the connection to the relational database and mediates data operations.

##### Architectural Patterns and Design Principles
- Layered (N-tier) architecture: There is a clear separation between the presentation (Frontend, Controllers), business layer (Domain/Core), and persistence layer (Infrastructure).
- Repository pattern: Notice how repository interfaces (defined in Core/Interfaces/Repository) are implemented in Infrastructure/Repositories.
- Dependency Injection: Seen in Infrastructure/DependencyInjection.cs that configures services and repositories.
- Use of DTOs and mapping: There is a clear mechanism to transform domain entities to DTOs (and vice versa) using mapping classes in Infrastructure/Mapping.
- Validation logic: Found in Infrastructure/Validations, ensures data integrity during create/update operations.
- Containerization: Docker support indicates modern deployment strategies.

##### Relevant Technologies, Frameworks, and Libraries
- .NET (Core/Shop.Server and Core classes)
- Entity Framework Core (in Infrastructure for data persistence)
- Next.js (in shop-front)
- Docker for containerizing the application.
- Middleware for cross-cutting concerns like error handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        F["Frontend (Next.js)"]
        subgraph "API Server (Shop.Server)"
            C["Controllers"]
            M["Middleware"]
            P["Program.cs"]
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        subgraph "Domain/Core Layer"
            E["Entities"]
            D["DTOs"]
            I["Interfaces"]
            Rq["Requests"]
        end
        subgraph "Infrastructure Layer"
            DBCTX["ApplicationDbContext"]
            Repo["Repositories"]
            Srv["Services"]
            Map["Mappings"]
            Val["Validations"]
            DI["DependencyInjection"]
            Mig["Migrations"]
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["Relational Database"]
    end

    %% Deployment
    subgraph "Deployment"
        Dock["Dockerfile"]
    end

    %% Connections
    F -->|"sendsRequest"| C
    C -->|"calls"| Srv
    I -->|"contracts"| Srv
    Srv -->|"uses"| Repo
    Repo -->|"accesses"| DBCTX
    DBCTX -->|"manages"| DB
    DI -.->|"wires"| Srv
    DI -.->|"wires"| Repo
    Map -.->|"supports"| Srv
    Val -.->|"validates"| Srv
    Mig -->|"updates"| DB
    P -->|"containerizes"| Dock

    %% Click Events
    click F "https://github.com/mauriciofrc/shop/tree/master/shop-front"
    click C "https://github.com/mauriciofrc/shop/tree/master/Shop.Server/Controllers"
    click M "https://github.com/mauriciofrc/shop/tree/master/Shop.Server/Middleware"
    click P "https://github.com/mauriciofrc/shop/blob/master/Shop.Server/Program.cs"
    click E "https://github.com/mauriciofrc/shop/tree/master/Core/Entities"
    click D "https://github.com/mauriciofrc/shop/tree/master/Core/DTOs"
    click I "https://github.com/mauriciofrc/shop/tree/master/Core/Interfaces"
    click Rq "https://github.com/mauriciofrc/shop/tree/master/Core/Request"
    click DBCTX "https://github.com/mauriciofrc/shop/blob/master/Infrastructure/Context/AplicationDbContext.cs"
    click Repo "https://github.com/mauriciofrc/shop/tree/master/Infrastructure/Repositories"
    click Srv "https://github.com/mauriciofrc/shop/tree/master/Infrastructure/Services"
    click Map "https://github.com/mauriciofrc/shop/tree/master/Infrastructure/Mapping"
    click Val "https://github.com/mauriciofrc/shop/tree/master/Infrastructure/Validations"
    click DI "https://github.com/mauriciofrc/shop/blob/master/Infrastructure/DependencyInjection.cs"
    click Mig "https://github.com/mauriciofrc/shop/tree/master/Infrastructure/Migrations"
    click DB "https://github.com/mauriciofrc/shop/blob/master/Shop.Server/appsettings.Development.json"
    click Dock "https://github.com/mauriciofrc/shop/tree/master/Dockerfile"

    %% Styles
    classDef frontend fill:#c6e5ff,stroke:#036,stroke-width:2px;
    classDef backend fill:#ffddab,stroke:#d17,stroke-width:2px;
    classDef core fill:#d3c0eb,stroke:#844,stroke-width:2px;
    classDef infra fill:#d5f5e3,stroke:#2a7,stroke-width:2px;
    classDef db fill:#f8d7da,stroke:#842,stroke-width:2px;
    classDef deploy fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    class F frontend;
    class C,M,P backend;
    class E,D,I,Rq core;
    class DBCTX,Repo,Srv,Map,Val,DI,Mig infra;
    class DB db;
    class Dock deploy;
```
