# avicted/social-platform-2000-backend architecture

> Architecture diagram of the GitHub repository avicted/social-platform-2000-backend, 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/avicted/social-platform-2000-backend
- Repository: https://github.com/avicted/social-platform-2000-backend

## Overview

##### Main Components
- API Layer (sp2000.API): This is the entry point for the application. It contains the controllers (e.g., AuthenticationController, CategoriesController, CommentsController, PostsController), Program.cs, and configuration files. It is responsible for handling HTTP requests, routing them to the appropriate services, and managing authentication.
- Application Layer (sp2000.Application): This layer holds the business logic. It includes Data Transfer Objects (DTOs), service interfaces and implementations (like CategoriesService, CommentsService, PostService), dependency injection setup, mapping configurations, and utility helpers. This layer abstracts the domain logic from infrastructure concerns.
- Infrastructure Layer (sp2000.Infrastructure): This layer is focused on persistence and external integrations. It contains the ApplicationDbContext, Entity Framework Core migrations, repository implementations (e.g., ApplicationUsersRepository, CategoriesRepository, etc.), identity management (JWT, cookies, IdentityService), and additional services (such as the DateTimeService). Its purpose is to handle data access and platform-specific implementations.
- Unit Test Project (sp2000.UnitTests): This project contains tests for controllers and services, ensuring the components work as expected.

##### Relationships and Interactions
- The sp2000.API (controllers) interacts with the sp2000.Application layer by calling its services and using DTOs to send/receive data.
- The sp2000.Application layer defines interfaces for repositories and business services, which are implemented by sp2000.Infrastructure. Dependency Injection (configured within both Application and Infrastructure projects) creates loose coupling.
- The Infrastructure layer manages database connections, migrations, and interactions with the persistence layer through Entity Framework Core.
- Unit tests validate the functionality of both the API controllers and the Application services, simulating and asserting real-world flows.

##### Architectural Patterns and Design Principles
- Layered (or Clean) Architecture: Each project (API, Application, Infrastructure) encapsulates distinct concerns, simplifying maintenance and testing.
- Dependency Injection: The Application and Infrastructure layers both have DI configurations to inject dependencies (e.g., repositories, current user services) into consuming classes.
- Repository Pattern: Abstracts database operations behind repository interfaces (defined in Application) and implemented in Infrastructure.
- DTO and Mapping: The Application layer consistently uses Data Transfer Objects and mapping configurations to decouple internal domain models from external representations.

##### Incorporate Relevant Technologies and Frameworks
- .NET (C#) with ASP.NET Core for the API.
- Entity Framework Core for data access and migrations.
- Docker for development container configurations (see .devcontainer folder).
- GitHub Actions for CI/CD (workflows in .github/workflows).
- VSCode remote development environment setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Nodes
    HTTP_REQ["HTTP Request"]:::external
    HTTP_RESP["HTTP Response"]:::external
    CI["CI/CD (GitHub Actions)"]:::external
    DC["Docker (.devcontainer)"]:::external

    %% sp2000.API Layer
    subgraph "sp2000.API"
        API1["Controllers (Auth, Categories, Comments, Posts)"]:::api
        API2["EntryPoint & Configurations (Program.cs, appsettings)"]:::api
    end

    %% sp2000.Application Layer
    subgraph "sp2000.Application"
        A1["DTOs"]:::application
        A2["Service Interfaces"]:::application
        A3["Service Implementations"]:::application
        A4["Mapping Configurations"]:::application
        A5["Utility Helpers"]:::application
        A6["DI Setup"]:::application
    end

    %% sp2000.Infrastructure Layer
    subgraph "sp2000.Infrastructure"
        I1["Persistence (ApplicationDbContext, Repositories, Migrations)"]:::infra
        I2["Identity Management (JWT, IdentityService)"]:::infra
        I3["Additional Services (DateTimeService)"]:::infra
        I4["DI Setup"]:::infra
    end

    %% sp2000.UnitTests
    subgraph "sp2000.UnitTests"
        UT["Unit Tests (Controllers & Services)"]:::tests
    end

    %% Main Flow Arrows
    HTTP_REQ -->|"sends"| API1
    API1 -->|"calls"| A2
    A2 -->|"delegates to"| A3
    A3 -->|"uses"| I1
    A3 -->|"uses"| I2
    A3 -->|"uses"| I3
    I1 -->|"returns result to"| A3
    I2 -->|"returns result to"| A3
    I3 -->|"returns result to"| A3
    A3 -->|"responds via"| API1
    API1 -->|"sends"| HTTP_RESP

    %% Dependency Injection Connections
    A6 -->|"injects"| A2
    I4 -->|"injects"| I1

    %% External Development & CI/CD Integration
    DC ---|"provides dev environment to"| API2
    CI ---|"triggers deployments for"| API2

    %% Unit Test Relationships (dashed lines)
    UT ---|"tests"| API1
    UT ---|"tests"| A3

    %% Click Events
    click API1 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.API/Controllers"
    click API2 "https://github.com/avicted/social-platform-2000-backend/blob/main/sp2000.API/Program.cs"
    click A1 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Application/DTO"
    click A2 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Application/Interfaces"
    click A3 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Application/Services"
    click A4 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Application/Mappings"
    click A5 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Application/Helpers"
    click A6 "https://github.com/avicted/social-platform-2000-backend/blob/main/sp2000.Application/DependencyInjection.cs"
    click I1 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Infrastructure/Persistance"
    click I2 "https://github.com/avicted/social-platform-2000-backend/tree/main/sp2000.Infrastructure/Identity"
    click I3 "https://github.com/avicted/social-platform-2000-backend/blob/main/sp2000.Infrastructure/services/DateTimeService.cs"
    click I4 "https://github.com/avicted/social-platform-2000-backend/blob/main/sp2000.Infrastructure/DependencyInjection.cs"
    click UT "https://github.com/avicted/social-platform-2000-backend/blob/main/sp2000.UnitTests"

    %% Styles
    classDef api fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef application fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef tests fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
