# p33tr/minstances architecture

> Architecture diagram of the GitHub repository p33tr/minstances, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/p33tr/minstances
- Repository: https://github.com/p33tr/minstances

## Overview

##### Main Components

a. Presentation Layer:
- MVC Components
- Controllers (BskyController, HomeController, TextSearchController)
- Views (Razor Pages in the Views directory)
- Models (Instance, InstX, Search, etc.)
- Static Content (wwwroot folder with CSS, JS, and client-side libraries)

b. Business Layer:
- Services
- InstancesService
- MastodonService

c. Data Layer:
- Repository Pattern Implementation
- IMinstancesRepository (interface)
- MinstancesRepository (concrete implementation)
- Database Context (MinstancesContext)
- Entity Models

**┌─────────────────────────────────────────────┐**
- Client Browser                 │
- ┬───┘
- ↕ HTTP
**┌─────────────────────────────────────────┴───┐**
- Presentation Layer            │
- ┌─────────────┐  ┌─────────────┐  ┌─────┐ │
- Controllers │  │    Views    │  │Models│ │
- ┘  └─────────────┘  └─────┘ │
- ┬───────────────────┘
- ↕
**┌─────────────────────────┴───────────────────┐**
- Business Layer                 │
- ┌─────────────┐      ┌──────────────────┐  │
- Instances   │      │    Mastodon      │  │
- Service    │      │    Service       │  │
- ┘      └──────────────────┘  │
- ┬───────────────────┘
- ↕
**┌─────────────────────────┴───────────────────┐**
- Data Layer                    │
- ┌─────────────┐      ┌──────────────────┐  │
- Repository  │      │    Database      │  │
- Interface   │←────→│    Context       │  │
- ┘      └──────────────────┘  │
- ┬───────────────────┘
- ↕
**┌─────────────────────────┴───────────────────┐**
- Database Storage               │
- ┘

##### Additional Elements

a. External Services:
- A connection to the Mastodon API (since this appears to be a Mastodon instance listing service)
- SSE (Server-Sent Events) connections (noticed from SseClient model)

b. Cross-Cutting Concerns:
- Error handling (ErrorViewModel)
- Configuration (appsettings.json)
- Static file serving (wwwroot)

##### Important Relationships to Highlight
- Controller dependencies on Services
- Repository pattern implementation
- Database context relationships with models
- View models (VM) relationship with views

##### Technical Stack Indicators
- ASP.NET Core MVC
- Entity Framework Core (evident from Migrations folder)
- jQuery and Bootstrap (from wwwroot/lib)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph PresentationLayer
        direction TB
        Controllers["Controllers"]:::controller
        Views["Views"]:::view
        Models["Models"]:::model
        StaticContent["Static Content"]:::static

        Controllers --> Views
        Controllers --> Models
        Views --> Models
        Views --> StaticContent
    end

    subgraph BusinessLayer
        direction TB
        InstancesService["Instances Service"]:::service
        MastodonService["Mastodon Service"]:::service
    end

    subgraph DataLayer
        direction TB
        Repository["Repository Interface"]:::repository
        DbContext["Database Context"]:::dbcontext
        Migrations["Migrations"]:::data
    end

    subgraph Storage
        Database[(Database)]:::database
    end

    subgraph ExternalServices
        MastodonAPI["Mastodon API"]:::external
    end

    subgraph CrossCutting
        ErrorHandling["Error Handling"]:::support
        Configuration["Configuration"]:::support
    end

    Browser <--> Controllers
    Controllers --> InstancesService
    Controllers --> MastodonService
    InstancesService --> Repository
    MastodonService --> MastodonAPI
    Repository --> DbContext
    DbContext --> Database
    DbContext --> Migrations
    ErrorHandling --> Controllers
    Configuration --> BusinessLayer

    %% Component Mappings
    click Controllers "https://github.com/P33tr/minstances/tree/main/minstances/minstances/Controllers"
    click Views "https://github.com/P33tr/minstances/tree/main/minstances/minstances/Views"
    click Models "https://github.com/P33tr/minstances/tree/main/minstances/minstances/Models"
    click StaticContent "https://github.com/P33tr/minstances/tree/main/minstances/minstances/wwwroot"
    click InstancesService "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Services/InstancesService.cs"
    click MastodonService "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Services/MastodonService.cs"
    click Repository "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Data/IMinstancesRepository.cs"
    click DbContext "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Data/MinstancesContext.cs"
    click Migrations "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Migrations/20241124152252_InitialCreate.cs"
    click Configuration "https://github.com/P33tr/minstances/blob/main/minstances/minstances/appsettings.json"
    click ErrorHandling "https://github.com/P33tr/minstances/blob/main/minstances/minstances/Views/Shared/Error.cshtml"

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef view fill:#42A5F5,stroke:#1565C0,color:white
    classDef model fill:#64B5F6,stroke:#1565C0,color:white
    classDef static fill:#90CAF9,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repository fill:#FF9800,stroke:#F57C00,color:white
    classDef dbcontext fill:#FFA726,stroke:#F57C00,color:white
    classDef data fill:#FFB74D,stroke:#F57C00,color:white
    classDef database fill:#757575,stroke:#424242,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef support fill:#78909C,stroke:#546E7A,color:white
```
