# jgmelon22/fileuploaderdocspider architecture

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

- Interactive diagram: https://gitdiagram.com/jgmelon22/fileuploaderdocspider
- Repository: https://github.com/jgmelon22/fileuploaderdocspider

## Overview

##### Project type and purpose
- This is a full-stack ASP.NET Core MVC application (“FileUploaderDocspider”) that implements CRUD operations for uploading and managing documents.
- It follows a clean, layered architecture (Web → Application → Core → Infrastructure), backed by PostgreSQL, and uses Entity Framework Core plus MediatR for command/query handling.

##### File structure
- **FileUploaderDocspider.Web**: ASP.NET Core MVC project (Controllers, Views, static assets, DI setup in Startup/Program).
- **FileUploaderDocspider.Application**: Mediator-based command/query definitions and handlers (Create, Update, Delete, GetAll, GetById).
- **FileUploaderDocspider.Core**: Domain models (Document), view-models, mapping extensions, shared Result<T> type.
- **FileUploaderDocspider.Infrastructure**: EF Core DbContext, entity configuration, repository & service implementations, database migrations.
- **UnitTests**: xUnit/Moq tests for Application layer handlers and Web controllers.

##### Architectural patterns & design principles
- **Layered/Clean Architecture**: Clear separation of concerns across Web, Application, Core, Infrastructure.
- **Mediator Pattern** (via NetDevPack.SimpleMediator): decouples controllers from business logic by sending commands/queries to handlers.
- **Repository Pattern**: IDocumentRepository abstracts data access behind EF Core.
- **Dependency Injection**: Wired in Startup, all components registered via IocExtensions.

##### Main components & their interactions
a. **Presentation Layer** (Web MVC)
- Controllers (DocumentController, HomeController) accept HTTP requests.
- Controllers call IMediator.Send(Create/Update/DeleteDocumentCommand or GetAll/GetByIdDocumentQuery).
- Views render HTML and include Bootstrap, jQuery for client-side behavior and file uploads.
b. **Application Layer**
- Command/Query objects define operations.
- Handlers implement business rules (e.g., unique title, file type validation, max length).
- Handlers call domain-agnostic services (`IDocumentService`) or repositories.
c. **Domain/Core Layer**
- `Document` aggregate (ID, Title, Description, FileName, CreatedAt).
- ViewModels for data transfer to/from the UI.
- MappingExtensions to map between Domain and ViewModels.
d. **Infrastructure Layer**
- `AppDbContext` with DbSet<Document> and Fluent API configurations (DocumentConfiguration).
- `DocumentRepository` implements IDocumentRepository using EF Core.
- `DocumentService` implements IDocumentService to encapsulate higher-level data operations.
- Migrations target PostgreSQL.
e. **Database**
- PostgreSQL for persistence, accessed via Npgsql provider in EF Core.
f. **External/Supporting**
- NetDevPack.SimpleMediator, EF Core NuGet packages, coverlet/xUnit/Moq for tests.

- Clear component labels (e.g., DocumentController, CreateDocumentCommandHandler).
- UI (Views, Controllers)
- Application (Mediators, Handlers)
- Domain (Models, Mappings)
- Infrastructure (Repositories, DbContext)
- Database
- Call out major NuGet/technologies at each layer boundary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Views["Views (cshtml)"]:::views
        Static["Static Assets & Uploads"]:::static
        Startup["Startup / Program"]:::di
        Ioc["Ioc Extensions"]:::di
        HomeCtrl["HomeController"]:::controller
        DocCtrl["DocumentController"]:::controller
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        CreateCmd["CreateDocumentCommand"]:::command
        UpdateCmd["UpdateDocumentCommand"]:::command
        DeleteCmd["DeleteDocumentCommand"]:::command
        GetAllQry["GetAllDocumentsQuery"]:::query
        GetByIdQry["GetDocumentByIdQuery"]:::query
        CreateHandler["CreateDocumentCommandHandler"]:::handler
        UpdateHandler["UpdateDocumentCommandHandler"]:::handler
        DeleteHandler["DeleteDocumentCommandHandler"]:::handler
        GetAllHandler["GetAllDocumentsQueryHandler"]:::handler
        GetByIdHandler["GetDocumentByIdQueryHandler"]:::handler
    end

    %% Domain/Core Layer
    subgraph "Domain/Core Layer"
        direction TB
        Document["Document Model"]:::domain
        ViewModels["ViewModels"]:::domain
        Mappings["MappingExtensions"]:::domain
        ResultT["Result<T>"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        DbContext["AppDbContext"]:::infra
        Configuration["DocumentConfiguration"]:::infra
        IRepository["IDocumentRepository"]:::infra
        IService["IDocumentService"]:::infra
        Repository["DocumentRepository"]:::infra
        Service["DocumentService"]:::infra
        Migrations["Migrations"]:::infra
    end

    %% Database
    Database["PostgreSQL"]:::database

    %% Mediator
    Mediator["NetDevPack.SimpleMediator"]:::mediator

    %% Presentation Flow
    Views --> HomeCtrl
    Views --> DocCtrl
    Static --> Views
    Startup --> HomeCtrl
    Startup --> DocCtrl
    Ioc --> Startup
    HomeCtrl -->|"IMediator.Send"| Mediator
    DocCtrl -->|"IMediator.Send"| Mediator

    %% Mediator to Application
    Mediator --> CreateCmd
    Mediator --> UpdateCmd
    Mediator --> DeleteCmd
    Mediator --> GetAllQry
    Mediator --> GetByIdQry

    %% Commands/Queries to Handlers
    CreateCmd --> CreateHandler
    UpdateCmd --> UpdateHandler
    DeleteCmd --> DeleteHandler
    GetAllQry --> GetAllHandler
    GetByIdQry --> GetByIdHandler

    %% Handlers to Infrastructure
    CreateHandler --> Service
    UpdateHandler --> Service
    DeleteHandler --> Service
    GetAllHandler --> Service
    GetByIdHandler --> Service

    Service --> Repository
    Repository --> DbContext
    DbContext --> Database
    DbContext --> Configuration
    Repository --> IRepository
    Service --> IService
    Handlers ---|returns Result<T>| DocCtrl

    %% Click Events
    click DocCtrl "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Web/Controllers/DocumentController.cs"
    click HomeCtrl "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Web/Controllers/HomeController.cs"
    click Views "https://github.com/jgmelon22/fileuploaderdocspider/tree/main/FileUploaderDocspider.Web/Views"
    click Static "https://github.com/jgmelon22/fileuploaderdocspider/tree/main/FileUploaderDocspider.Web/wwwroot"
    click Startup "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Web/Startup.cs"
    click Ioc "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Web/Extensions/IocExtensions.cs"
    click CreateCmd "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/CreateDocumentCommand.cs"
    click UpdateCmd "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/UpdateDocumentCommand.cs"
    click DeleteCmd "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/DeleteDocumentCommand.cs"
    click CreateHandler "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/Handlers/CreateDocumentCommandHandler.cs"
    click UpdateHandler "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/Handlers/UpdateDocumentCommandHandler.cs"
    click DeleteHandler "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Commands/Handlers/DeleteDocumentCommandHandler.cs"
    click GetAllQry "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Queries/GetAllDocumentsQuery.cs"
    click GetByIdQry "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Queries/GetDocumentByIdQuery.cs"
    click GetAllHandler "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Queries/Handlers/GetAllDocumentsQueryHandler.cs"
    click GetByIdHandler "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Application/Queries/Handlers/GetDocumentByIdQueryHandler.cs"
    click Document "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Core/Domains/Models/Document.cs"
    click ViewModels "https://github.com/jgmelon22/fileuploaderdocspider/tree/main/FileUploaderDocspider.Core/Domains/ViewModels"
    click Mappings "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Core/Domains/Mappings/MappingExtensions.cs"
    click ResultT "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Core/Shared/Result.cs"
    click DbContext "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Data/AppDbContext.cs"
    click Configuration "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Configuration/DocumentConfiguration.cs"
    click IRepository "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Interfaces/Repositories/IDocumentRepository.cs"
    click IService "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Interfaces/Services/IDocumentService.cs"
    click Repository "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Repositories/DocumentRepository.cs"
    click Service "https://github.com/jgmelon22/fileuploaderdocspider/blob/main/FileUploaderDocspider.Infrastructure/Services/DocumentService.cs"
    click Migrations "https://github.com/jgmelon22/fileuploaderdocspider/tree/main/FileUploaderDocspider.Infrastructure/Migrations"

    %% Styles
    classDef controller fill:#D6EAF8,stroke:#1B4F72
    classDef views fill:#EBDEF0,stroke:#6C3483
    classDef static fill:#FDEBD0,stroke:#7E5109
    classDef di fill:#D1F2EB,stroke:#0E6655
    classDef command fill:#FADBD8,stroke:#922B21
    classDef query fill:#FCF3CF,stroke:#7D6608
    classDef handler fill:#D5F5E3,stroke:#196F3D
    classDef domain fill:#E8DAEF,stroke:#6C3483
    classDef infra fill:#D4E6F1,stroke:#1F618D
    classDef database fill:#F9E79F,stroke:#B7950B
    classDef mediator fill:#E8F8F5,stroke:#117A65
```
