# jesusferru/morenos-seguros-project architecture

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

- Interactive diagram: https://gitdiagram.com/jesusferru/morenos-seguros-project
- Repository: https://github.com/jesusferru/morenos-seguros-project

## Overview

##### Main Components
- Core (Domain Layer):
– Contains fundamental domain objects such as BaseEntity, IAggregateRoot, domain entities (like User), ValueObjects (UserRole), and any domain constants.
– Represents business rules, domain logic, and modeling techniques (e.g., SmartEnum for UserRole).

- Infrastructure (Data & Persistence Layer):
– Hosts the AppDbContext, repositories (EfRepository based on Ardalis.Specification), data configurations (e.g., UserConfiguration), migrations management, and service registration (InfrastructureServiceExtensions).
– Handles data mapping, configuration, and communication with the actual database.

- API/Web/Endpoints Layer:
– The MorenoSeguros.Api project provides API endpoints (e.g., Login endpoints, User endpoints) which expose the functionality of the backend.
– Includes middleware (e.g., HandleException), page views (Razor pages like Error, Index, Privacy), static assets (in wwwroot with CSS, JS, and libraries).

- Migration Module:
– The Migration project, which contains API DB initialization and migration commands. This module ensures that database schema changes are tracked and applied.

- Frontend (Client Side):
– Although details are sparse here, include it as a separate client component that might interact with backend APIs.

##### Out the Relationships and Interactions
- How the Web/API layer communicates with the Core via Use Cases and how controllers (or endpoints) call services defined in the Core.
- Dependency inversion where the Core (domain) is independent, while the Infrastructure layer provides implementations (like repositories) that the Core uses.
- How the Infrastructure layer connects with the database (via AppDbContext using EF Core) and how migrations are used to update schema.
- For the frontend, indicate that it interacts with the backend API through HTTP calls (exposing endpoints like Login and Users operations).

##### Architectural Patterns and Design Principles
- Clean Architecture / Onion Architecture:
– Layers (Core, Use Cases, Infrastructure, and API/Web) should be depicted concentrically with clear boundaries.
- Domain-Driven Design (DDD) patterns:
– Note the use of IAggregateRoot to mark aggregate boundaries, domain entities in the Core, and Value Objects.
- Repository Pattern:
– Show the generic repository (EfRepository<T>) for data access.
- Separation of Concerns and Dependency Inversion:
– Ensure that core business logic does not depend on external frameworks (e.g., EF Core details are isolated in the Infrastructure).

- “Core” block: List BaseEntity, Entities (User), Domain Interfaces, ValueObjects.
- “Infrastructure” block: Include AppDbContext, Repository (EfRepository), Service Registration, Migrations.
- “API/Web Endpoints” block: Represent endpoints for Login, Users, middleware, and static assets.
- “Frontend” (if necessary): Mark the client code interacting with the API.
- Data flow from the API to the Core (via service methods and use cases).
- Dependency from Infrastructure to Core (for domain models).
- Communication from the API layer to the database via the Infrastructure.
- The migration process updating the database.
- Annotations that mention key tools and libraries:
- EF Core (for AppDbContext and migrations).
- Ardalis.Specification-based repository.
- .NET (C# Razor pages) are used in the API layer.
- Dependency Injection (as seen with service extensions).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Domain Layer (Core)"
        Core["Core: Domain Logic\n(BaseEntity, IAggregateRoot, User, UserRole)"]:::domain
    end

    subgraph "Infrastructure Layer"
        Infra["Infrastructure: Data Persistence\n(AppDbContext, EfRepository, Configurations, DI)"]:::infra
    end

    subgraph "API/Web Endpoints"
        API["API/Web: Endpoints\n(Login, Users, Middleware, Razor Pages, Static Assets)"]:::api
    end

    subgraph "Migration Module"
        Migration["Migration: DB Schema Changes\n(Migration Commands, DB Initialization)"]:::migration
    end

    subgraph "Frontend (Client)"
        Frontend["Frontend: Client Interaction\n(HTTP calls to API)"]:::frontend
    end

    API -->|"callsDomainLogic"| Core
    API -->|"usesRepository"| Infra
    Infra -->|"dependsOnDomain"| Core
    Migration -->|"updatesSchemaVia"| Infra
    Frontend -->|"callsAPI"| API

    click Core "https://github.com/jesusferru/morenos-seguros-project/blob/production/backend/MorenoSeguros/MorenoSeguros.Core"
    click Infra "https://github.com/jesusferru/morenos-seguros-project/blob/production/backend/MorenoSeguros/MorenoSeguros.Infrastructure"
    click API "https://github.com/jesusferru/morenos-seguros-project/blob/production/backend/MorenoSeguros/MorenoSeguros.Api"
    click Migration "https://github.com/jesusferru/morenos-seguros-project/blob/production/backend/MorenoSeguros/MorenoSeguros.Migration"
    click Frontend "https://github.com/jesusferru/morenos-seguros-project/tree/production/frontend"

    classDef domain fill:#a3c1da,stroke:#000,stroke-width:1px;
    classDef infra fill:#b4eeb4,stroke:#000,stroke-width:1px;
    classDef api fill:#f5a623,stroke:#000,stroke-width:1px;
    classDef migration fill:#d8b4ff,stroke:#000,stroke-width:1px;
    classDef frontend fill:#ffd1dc,stroke:#000,stroke-width:1px;
```
