# shuncoder/student-manager-webapi architecture

> Architecture diagram of the GitHub repository shuncoder/student-manager-webapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shuncoder/student-manager-webapi
- Repository: https://github.com/shuncoder/student-manager-webapi

## Overview

##### Project Type and Purpose
- This is a **backend-only**, RESTful **ASP.NET Core Web API** (.NET 8) for managing Students, Classes, and their relationships.
- It follows a **layered architecture**: Presentation (Controllers) → Business Logic (Services) → Data Store (InMemory).

##### File Structure
- **Controllers/** – HTTP entrypoints (ClassesController, StudentsController).
- **Services/**
- Interfaces (IClassService, IStudentService) define business operations.
- Implementations (ClassService, StudentService) contain logic and call the Data layer.
- **Data/** – `InMemoryDataStore`: holds Lists of `Student`, `Class`, and `StudentClass`.
- **Models/** – Domain entities (`Student`, `Class`, `StudentClass`).
- **DTOs/** – Request/response payloads and validation rules.
- **Program.cs** – Configures DI, adds services, and sets up Swagger.

##### Main Components
a. API Layer (Controllers)
- StudentsController
- ClassesController
- Swagger UI endpoint
b. Business Layer (Services)
- IStudentService → StudentService
- IClassService → ClassService
c. Data Layer
- InMemoryDataStore (holds three collections)
d. Domain Models & DTOs
- Models: Student, Class, StudentClass
- DTOs: Create/UpdateStudentDto, StudentDto, Create/UpdateClassDto, ClassDto, AddStudentsToClassDto
e. External/Infrastructure
- ASP.NET Core hosting environment
- appsettings.json (configuration)
- Dependency Injection container

##### Relationships & Data Flows
- **Client** → HTTP request → **Controller**
- **Controller** → calls **Service Interface** → concrete **Service Implementation**
- **Service** → reads/writes **InMemoryDataStore** → retrieves/updates **Models**
- **Service** → maps **Models** ↔ **DTOs** → returns to **Controller**
- **Controller** → HTTP response (JSON) → **Client**
- Swagger UI interacts directly with Controllers via HTTP.

##### Architectural Patterns & Principles
- **Layered Architecture** – clear separation of concerns.
- **Dependency Injection** – controllers depend on service interfaces, configured in Program.cs.
- **DTO Pattern** – isolates internal models from external API contracts.
- **In-Memory Repository** – Data store abstraction, easily replaceable by EF Core or another provider later.
- **Exception Handling** – try-catch in Controllers to translate errors into HTTP status codes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client(["Client<br/>(HTTP)"]):::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        StudentsController["StudentsController"]:::api
        ClassesController["ClassesController"]:::api
        SwaggerUI["Swagger UI"]:::api
    end

    %% Business Layer
    subgraph "Business Layer"
        direction TB
        IStudentService["IStudentService"]:::business
        IClassService["IClassService"]:::business
        StudentService["StudentService"]:::business
        ClassService["ClassService"]:::business
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        InMemoryDataStore["InMemoryDataStore"]:::data
    end

    %% Models & DTOs
    subgraph "Models & DTOs"
        direction TB
        StudentModel["Student"]:::model
        ClassModel["Class"]:::model
        StudentClassModel["StudentClass"]:::model
        StudentDTOs["Student DTOs"]:::dto
        ClassDTOs["Class DTOs"]:::dto
    end

    %% Infrastructure & Config
    subgraph "Infrastructure"
        direction TB
        Program["Program.cs"]:::infra
        AppSettings["appsettings.json"]:::infra
        AppSettingsDev["appsettings.Development.json"]:::infra
        LaunchSettings["launchSettings.json"]:::infra
        CSPROJ["StudentManagementAPI.csproj"]:::infra
        SLN["StudentManagementAPI.sln"]:::infra
    end

    %% Connections
    Client -->|HTTP Request| StudentsController
    Client -->|HTTP Request| ClassesController
    Client -->|Open Docs| SwaggerUI
    SwaggerUI -->|HTTP Request| StudentsController
    SwaggerUI -->|HTTP Request| ClassesController

    StudentsController -->|"Validate DTOs"| StudentDTOs
    ClassesController -->|"Validate DTOs"| ClassDTOs

    StudentsController -->|"calls IStudentService"| IStudentService
    ClassesController -->|"calls IClassService"| IClassService

    IStudentService -->|"implemented by"| StudentService
    IClassService -->|"implemented by"| ClassService

    StudentService -->|"CRUD Models"| InMemoryDataStore
    ClassService -->|"CRUD Models"| InMemoryDataStore

    InMemoryDataStore -->|stores| StudentModel
    InMemoryDataStore -->|stores| ClassModel
    InMemoryDataStore -->|stores| StudentClassModel

    StudentService -->|maps| StudentDTOs
    ClassService -->|maps| ClassDTOs

    Program -->|configures DI| StudentsController
    Program -->|configures DI| ClassesController
    Program -->|registers services| IStudentService
    Program -->|registers services| IClassService
    Program -->|sets up| SwaggerUI

    Program --> AppSettings
    Program --> AppSettingsDev
    Program --> LaunchSettings
    Program --> CSPROJ
    Program --> SLN

    %% Click Events
    click StudentsController "https://github.com/shuncoder/student-manager-webapi/blob/main/Controllers/StudentsController.cs"
    click ClassesController "https://github.com/shuncoder/student-manager-webapi/blob/main/Controllers/ClassesController.cs"
    click IStudentService "https://github.com/shuncoder/student-manager-webapi/blob/main/Services/Interfaces/IStudentService.cs"
    click IClassService "https://github.com/shuncoder/student-manager-webapi/blob/main/Services/Interfaces/IClassService.cs"
    click StudentService "https://github.com/shuncoder/student-manager-webapi/blob/main/Services/Implementations/StudentService.cs"
    click ClassService "https://github.com/shuncoder/student-manager-webapi/blob/main/Services/Implementations/ClassService.cs"
    click InMemoryDataStore "https://github.com/shuncoder/student-manager-webapi/blob/main/Data/InMemoryDataStore.cs"
    click StudentModel "https://github.com/shuncoder/student-manager-webapi/blob/main/Models/Student.cs"
    click ClassModel "https://github.com/shuncoder/student-manager-webapi/blob/main/Models/Class.cs"
    click StudentClassModel "https://github.com/shuncoder/student-manager-webapi/blob/main/Models/StudentClass.cs"
    click StudentDTOs "https://github.com/shuncoder/student-manager-webapi/blob/main/DTOs/StudentDtos.cs"
    click ClassDTOs "https://github.com/shuncoder/student-manager-webapi/blob/main/DTOs/ClassDtos.cs"
    click Program "https://github.com/shuncoder/student-manager-webapi/blob/main/Program.cs"
    click AppSettings "https://github.com/shuncoder/student-manager-webapi/blob/main/appsettings.json"
    click AppSettingsDev "https://github.com/shuncoder/student-manager-webapi/blob/main/appsettings.Development.json"
    click LaunchSettings "https://github.com/shuncoder/student-manager-webapi/blob/main/Properties/launchSettings.json"
    click CSPROJ "https://github.com/shuncoder/student-manager-webapi/blob/main/StudentManagementAPI.csproj"
    click SLN "https://github.com/shuncoder/student-manager-webapi/blob/main/StudentManagementAPI.sln"

    %% Styles
    classDef api fill:#cce5ff,stroke:#3399ff,stroke-width:1px;
    classDef business fill:#d4edda,stroke:#28a745,stroke-width:1px;
    classDef data fill:#fff3cd,stroke:#ffc107,stroke-width:1px;
    classDef model fill:#e2e3e5,stroke:#6c757d,stroke-width:1px;
    classDef dto fill:#e2e3e5,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 5 5;
    classDef infra fill:#f8f9fa,stroke:#adb5bd,stroke-width:1px;
    classDef external fill:#f1f1f1,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2;
```
