# cgaritac/expropriation_management_system architecture

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

- Interactive diagram: https://gitdiagram.com/cgaritac/expropriation_management_system
- Repository: https://github.com/cgaritac/expropriation_management_system

## Overview

This project is an ASP.NET Core MVC web application developed in C#. Its purpose is to manage various aspects of property expropriation and appraisal, as indicated by controllers such as AppraisalController, ExpropiatedPropertyController, OwnerController, and others. The project uses a layered architecture with clear separation of responsibilities, and it relies on Entity Framework Core for data access (as seen in the Migrations and DBContext files) and dependency injection for configuration.

##### Overall Structure and Main Components
- Frontend Presentation Layer: Represented by the Views (Razor pages, e.g., in the Views folder) and static assets (wwwroot with CSS, JS, and libraries like Bootstrap and jQuery). This is the user interface level.
- Controllers (API / UI Controllers): These are found in the Controllers folder. They handle incoming HTTP requests, process data via the service layer, and return responses (HTML in many cases due to Razor views).
- Service Layer: Implemented in the Services folder and interfaced in the Interfaces/IServices folder. This layer encapsulates business logic and orchestrates operations between the controllers and repository layers.
- Repository/Data Access Layer: Located in the Repositories folder with corresponding interfaces in the Interfaces/IRepositories folder. This layer interacts with the database using EF Core, as configured in the Data folder (with DBContext.cs) and Migrations.
- Domain Models and Common Components: Found in the Models folder and the Common directory (which includes application settings, constants, helper methods, enums, and exception classes). These support both the business logic and data persistence.
- Middleware Components: Custom middleware like EmailDomainMiddleware and InvalidateCookiesMiddleware are used to process requests and responses, enforcing cross-cutting concerns.
- Dependency Injection/Configuration: The Configurations folder (DependencyInjection.cs) sets up the DI container to wire up controllers, services, and repositories at runtime.

##### Relationships and Data Flow
- The user interacts with the Frontend (Views and static assets), which triggers HTTP requests routed to the Controllers.
- Controllers use the Service Layer to process business logic. This ensures that business rules are enforced, and any validations or exception handling (using custom exceptions in the Common folder) are applied.
- The Service Layer communicates with the Repository/Data Access Layer to retrieve or persist domain Models via EF Core’s DBContext.
- Any external dependencies (like authentication in the AuthController or file handling in FilesController) should be noted, as well as middleware that intercepts the HTTP pipeline.
- Dependency Injection is used to bind implementations (services, repositories) to their interfaces, ensuring loose coupling.

##### Architectural Patterns and Technologies
- MVC Architectural Pattern: Separation into Models, Views, and Controllers.
- Layered Architecture: Distinct separation between presentation, business logic (services), and data access (repositories).
- Dependency Injection: Centralized in the Configurations (DependencyInjection.cs) to promote modularity and testability.
- Use of Entity Framework Core: Evident in the presence of migrations, DBContext, and repository implementations.
- Custom Middleware and Interceptors: Handling cross-cutting concerns such as soft deletes (in SoftDeleteInterceptor) and cookie invalidation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level External Actor
    User["User Request"]:::external

    %% Frontend Presentation Layer
    subgraph "Frontend Presentation"
        Views["Views (Razor pages)"]:::frontend
        Static["Static Assets (wwwroot)"]:::frontend
    end

    %% Middleware & Pipeline
    subgraph "Middleware & Pipeline"
        Middleware["Custom Middleware"]:::middleware
        Interceptor["Interceptors"]:::middleware
    end

    %% Controller Layer
    subgraph "Controller Layer"
        Controllers["Controllers"]:::controller
    end

    %% Business Logic / Service Layer
    subgraph "Business Logic / Service Layer"
        Services["Services"]:::service
        ServiceIF["Service Interfaces"]:::service
    end

    %% Data Access / Repository Layer
    subgraph "Data Access / Repository Layer"
        Repositories["Repositories"]:::repository
        RepositoryIF["Repository Interfaces"]:::repository
        DBContext["DBContext (EF Core)"]:::repository
        Migrations["Migrations"]:::repository
    end

    %% Domain & Common Components
    subgraph "Domain & Common"
        DomainModels["Domain Models"]:::domain
        Common["Common Components"]:::domain
    end

    %% Dependency Injection / Configuration
    subgraph "Configuration"
        DI["DI Configuration"]:::di
    end

    %% Data Flow / Relationships
    User -->|"sends request"| Middleware
    Middleware -->|"processes"| Controllers
    Controllers -->|"calls"| Services
    Services -->|"uses"| Repositories
    Repositories -->|"accesses"| DBContext
    DBContext -->|"based on"| Migrations

    %% UI Rendering Flow
    Controllers -->|"renders view"| Views
    Views -->|"delivers interface to"| User

    %% Service and Domain Interactions
    Services -->|"manipulates"| DomainModels
    DomainModels -->|"leveraged by"| Common

    %% Dependency Injection Wiring (dotted lines)
    DI -.-> Controllers
    DI -.-> Services
    DI -.-> Repositories

    %% Middleware Advanced Flow
    Middleware -->|"invokes"| Interceptor

    %% Click Events
    click Views "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Views"
    click Static "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/wwwroot"
    click Controllers "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Controllers"
    click Services "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Services"
    click ServiceIF "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Interfaces/IServices"
    click Repositories "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Repositories"
    click RepositoryIF "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Interfaces/IRepositories"
    click DBContext "https://github.com/cgaritac/expropriation_management_system/blob/main//GestionExpropaciones/Data/DBContext.cs"
    click Migrations "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Migrations"
    click DomainModels "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Models"
    click Common "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Common"
    click Middleware "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Middleware"
    click Interceptor "https://github.com/cgaritac/expropriation_management_system/tree/main//GestionExpropaciones/Interceptors"
    click DI "https://github.com/cgaritac/expropriation_management_system/blob/main//GestionExpropaciones/Configurations/DependencyInjection.cs"

    %% Class Definitions for styling
    classDef external fill:#FFFACD,stroke:#FFD700,stroke-width:2px;
    classDef frontend fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef controller fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef service fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef repository fill:#98FB98,stroke:#32CD32,stroke-width:2px;
    classDef middleware fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;
    classDef domain fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef di fill:#F0E68C,stroke:#BDB76B,stroke-width:2px;
```
