# diegotrejo/libreria.modelos architecture

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

- Interactive diagram: https://gitdiagram.com/diegotrejo/libreria.modelos
- Repository: https://github.com/diegotrejo/libreria.modelos

## Overview

##### Project type and purpose
- This is a full-stack .NET solution implementing a simple library management system (“Libreria”) with:
- A RESTful backend service (Libreria.API)
- A server-rendered web UI (Libreria.MVC)
- A shared domain‐models library (Libreria.Modelos)
- An API consumer helper library (Librerria.API.Consumer)
- A test harness (Libreria.Test)

##### File structure
- Top-level solution (.sln) ties together five projects.
- Libreria.API
- “Controllers” expose CRUD endpoints for entities (Autores, Libros, Editoriales, Paises).
- “Data/AppDbContext” + EF Core migrations → Microsoft SQL Server.
- appsettings.json defines connection strings & environment settings.
- Libreria.MVC
- MVC Controllers & Razor Views under “Views/…” for each entity.
- References the domain models and likely calls the API via the consumer library.
- Static assets (CSS/JS) under wwwroot (Bootstrap, jQuery, validation).
- Libreria.Modelos
- Defines POCO classes for Autor, Libro, Editorial, Pais. Shared by API, MVC, Consumer, and Tests.
- Librerria.API.Consumer
- Contains CRUD.cs: a typed HttpClient wrapper to consume the REST API.
- Libreria.Test
- A console-style Program.cs; likely automates tests against the API or consumer.

##### README
- Minimal (“# Libreria.Modelos”).

a. Main components
- Clients (Browser / User)
- MVC Web App (Libreria.MVC)
- API Consumer Library (Librerria.API.Consumer)
- REST API Service (Libreria.API)
- Database Access (EF Core / AppDbContext / Migrations)
- SQL Server (or another RDBMS)
- Shared Domain Models (Libreria.Modelos)
- Test Harness (Libreria.Test)

b. Relationships & data flow
1. User → HTTP(S) → MVC Controllers
2. MVC Controllers → (in-process) call to API Consumer → HTTP(S) → REST API Controllers
3. REST API Controllers → AppDbContext → SQL Server
4. EF Core Migrations define DB schema; AppDbContextModelSnapshot keeps track.
5. Domain models flow bidirectionally between MVC, Consumer, API, and Tests via the shared library.
6. Test Harness uses the same Consumer/API to verify endpoints and model behavior.

c. Architectural patterns & design principles
- Layered architecture: Presentation (MVC), Application (API + Consumer), Data (EF Core).
- Separation of concerns: UI vs. business logic vs. persistence.
- Shared kernel: domain models in Libreria.Modelos to avoid duplication.
- Single Responsibility: each project handles one responsibility.
- Dependency Injection: built-in .NET Core DI in Program.cs (API & MVC).

d. Key technologies & frameworks
- .NET 8 (or .NET 7+) ASP.NET Core MVC & Web API
- Entity Framework Core + Migrations
- Razor Views, Bootstrap, jQuery (client-side)
- HttpClient wrapper in Consumer library
- Visual Studio solution (.sln), .csproj per project

##### Details
- Migrations folder and ModelSnapshot as part of the persistence sub-component.
- LaunchSettings.json to indicate local vs. production URLs if desired.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Browser["User Browser"]:::external

    %% UI Layer
    subgraph "UI Layer"
        MVCApp["Libreria.MVC"]:::ui
    end

    %% Shared Models
    subgraph "Shared Domain Models"
        Modelos["Libreria.Modelos"]:::shared
    end

    %% Consumer Library
    subgraph "API Consumer"
        Consumer["Librerria.API.Consumer"]:::util
    end

    %% API Layer
    subgraph "REST API Service"
        APIService["Libreria.API"]:::apiLayer
    end

    %% Data Layer
    subgraph "Persistence Layer"
        DbContext["AppDbContext"]:::data
        Migrations["Migrations & Snapshot"]:::data
        SQL["SQL Server"]:::external
    end

    %% Test Harness
    Test["Libreria.Test"]:::util

    %% Relationships
    Browser -->|"HTTP GET/POST"| MVCApp
    MVCApp -->|"in-process call"| Consumer
    Consumer -->|"HTTP GET/POST /api/*"| APIService
    APIService -->|"EF Core usage"| DbContext
    DbContext -->|"SQL queries"| SQL
    Migrations -->|"Schema updates"| SQL
    Modelos --> MVCApp
    Modelos --> Consumer
    Modelos --> APIService
    Modelos --> Test
    Test -->|"uses Consumer"| Consumer
    Test -->|"verifies API endpoints"| APIService

    %% Click Events
    click MVCApp "https://github.com/diegotrejo/libreria.modelos/blob/master/Libreria.MVC/Program.cs"
    click APIService "https://github.com/diegotrejo/libreria.modelos/blob/master/Libreria.API/Program.cs"
    click Consumer "https://github.com/diegotrejo/libreria.modelos/blob/master/Librerria.API.Consumer/Crud.cs"
    click Modelos "https://github.com/diegotrejo/libreria.modelos/blob/master/Libreria.Modelos/Libreria.Modelos.csproj"
    click DbContext "https://github.com/diegotrejo/libreria.modelos/blob/master/Libreria.API/Data/AppDbContext.cs"
    click Migrations "https://github.com/diegotrejo/libreria.modelos/tree/master/Libreria.API/Migrations"
    click Test "https://github.com/diegotrejo/libreria.modelos/blob/master/Libreria.Test/Program.cs"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064,color:#000;
    classDef apiLayer fill:#E8F5E9,stroke:#1B5E20,color:#000;
    classDef data fill:#FFF3E0,stroke:#E65100,color:#000;
    classDef shared fill:#ECEFF1,stroke:#607D8B,color:#000;
    classDef util fill:#F3E5F5,stroke:#6A1B9A,color:#000;
    classDef external fill:#FFEBEE,stroke:#B71C1C,color:#000;
```
