# daohainam/lets-learn-aspnet architecture

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

- Interactive diagram: https://gitdiagram.com/daohainam/lets-learn-aspnet
- Repository: https://github.com/daohainam/lets-learn-aspnet

## Overview

##### Project type and purpose
- This repo is a teaching/learning repository containing multiple small ASP.NET Core applications:
– JwtDemo: MVC site with JWT-based API calls
– MiddlewareDemo: custom middleware pipelines (ClientInfo, HTTPS redirection)
– MyOidcServer + OidcWebClient: a custom OIDC identity server and a protected client app
– MySession: demo of custom session storage via middleware/DI
– SecurityDemo: account management MVC site with pluggable user-storage
– TodoApi: minimal Web API with repository abstractions and MongoDB implementation
– TodoList: classic MVC To-Do List with layered design (Entities, UseCases, Infrastructure, Web UI)

##### File structure
- Top-level “Projects” folder holds each sample as its own ASP.NET Core project or solution.
- Each project follows the standard ASP.NET Core layout:
– Program.cs → host and configure middleware
– Controllers folder → HTTP endpoints (MVC actions or API controllers)
– Models → view- or data-transfer models
– Views/wwwroot → Razor views and static assets
– Custom folders (Middleware, Repositories, UseCases, Entities) → business logic & data access
- Configuration files (appsettings.json, launchSettings.json) define environment settings.

##### Key insights from README
- The repo is a course covering ASP.NET MVC, Web API, middleware, session, authentication/authorization, OIDC, testing, Docker/NGINX.
- There is no single database—some samples use in-memory storage, some use MongoDB, some are stateless.

a. Main components (generic template for an ASP.NET Core app):
1. Client (Browser or HTTP client)
2. Reverse Proxy (optional NGINX/Docker)
3. ASP.NET Core Host (Kestrel)
4. Middleware Pipeline (built-in + custom middleware)
5. Routing to Controllers / Endpoints
6. Controllers → call into:
– Business Logic / UseCases
– Session or Token Services
– Repositories (In-memory, MongoDB, JSON file, custom session store)
7. Data stores (In-memory, MongoDB, JSON files)
8. Views + Static Files (wwwroot)

b. Relationships & interactions:
– HTTP request flows: Browser → (NGINX) → Kestrel → Middleware Pipeline
– Pipeline invokes custom middleware (e.g., HTTPS redirect, ClientInfo, session handling)
– Router dispatches to Controller Actions
– Controllers use injected services (UseCases, JwtGenerator, SessionStorage, Repositories)
– Services perform business logic, then read/write to repository → Data store
– Controller returns View or JSON response → back through pipeline → Client

c. Architectural patterns & design principles:
– Layered architecture (Presentation → Application → Domain → Infrastructure)
– Middleware pipeline pattern in ASP.NET Core
– Dependency injection for repositories & services
– Repository pattern with abstractions (e.g., IToDoRepository, IUserRepository)
– Separation of concerns (custom OIDC server vs. client vs. API demos)
– Pluggable storage engines (e.g., MySessionStorageEngine, JsonFileUserRepository, MongoDbToDoRepository)

d. Key technologies & libraries:
– ASP.NET Core MVC & Web API
– Razor Views, static files (wwwroot)
– Custom middleware (classes under Middleware folder)
– JWT (JwtDemo), OIDC (MyOidcServer), session storage (MySession)
– DI container (built into .NET)
– MongoDB driver (in TodoApi)
– Integration testing (XUnit, TestServer)

## Diagram (Mermaid)

```mermaid
flowchart TB
    Browser["Browser / HTTP Client"]:::external
    NGINX["Reverse Proxy (NGINX)"]:::infra
    Kestrel["Kestrel Host"]:::infra

    Browser -->|"HTTP Request"| NGINX -->|"Forward to Kestrel"| Kestrel

    subgraph "Middleware Pipeline"
        direction TB
        Https["HttpsRedirection"]:::middleware
        Auth["Authentication"]:::middleware
        Session["Session Handling"]:::middleware
        Routing["Routing"]:::middleware
    end

    Kestrel -->|"Invoke Pipeline"| Https --> Auth --> Session --> Routing

    Controller["Controller Actions"]:::app
    UseCases["Use Cases / Services"]:::domain
    Repo["Repositories"]:::infra
    Data["Data Stores"]:::infra
    Views["Views / Static Files"]:::frontend

    Routing -->|"Dispatch to Controller"| Controller
    Controller -->|"Calls Services"| UseCases
    UseCases -->|"DI Injection"| Repo
    Repo -->|"Read/Write"| Data
    Controller -->|"Renders"| Views

    subgraph "Projects Catalog"
        direction TB
        JwtDemo["JwtDemo"]:::sample
        MiddlewareDemo["MiddlewareDemo"]:::sample
        MyOidcServer["MyOidcServer"]:::sample
        OidcWebClient["OidcWebClient"]:::sample
        MySession["MySession"]:::sample
        SecurityDemo["SecurityDemo"]:::sample
        TodoApi["TodoApi"]:::sample
        TodoList["TodoList"]:::sample
    end

    JwtDemo -->|uses template| Kestrel
    MiddlewareDemo -->|uses template| Kestrel
    MyOidcServer -->|uses template| Kestrel
    OidcWebClient -->|uses template| Kestrel
    MySession -->|uses template| Kestrel
    SecurityDemo -->|uses template| Kestrel
    TodoApi -->|uses template| Kestrel
    TodoList -->|uses template| Kestrel

    click JwtDemo "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/JwtDemo"
    click MiddlewareDemo "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MiddlewareDemo/Middleware"
    click MiddlewareDemo "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MiddlewareDemo/Controllers"
    click MyOidcServer "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcServer"
    click MyOidcServer "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcServer/Controllers"
    click MyOidcServer "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcServer/Helpers"
    click MyOidcServer "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcServer/Repositories"
    click MyOidcServer "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcServer/OidcDiscovery"
    click OidcWebClient "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcWebClient"
    click OidcWebClient "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MyOidcServer/OidcWebClient/Controllers"
    click MySession "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/MySession/MySession/MySession"
    click SecurityDemo "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/SecurityDemo/AccountDemo"
    click SecurityDemo "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/SecurityDemo/UserStorage"
    click TodoApi "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoApi/TodoApi"
    click TodoApi "https://github.com/daohainam/lets-learn-aspnet/blob/main/Projects/TodoApi/ToDoRepository.Abstractions"
    click TodoApi "https://github.com/daohainam/lets-learn-aspnet/blob/main/Projects/TodoApi/ToDoRepository.MongoDb"
    click TodoApi "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoApi/IntegrationTests"
    click TodoApi "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoApi/RepositoryTests"
    click TodoList "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoList/TodoList/TodoList"
    click TodoList "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoList/Entities"
    click TodoList "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoList/UseCases"
    click TodoList "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoList/Infratructure"
    click TodoList "https://github.com/daohainam/lets-learn-aspnet/tree/main/Projects/TodoList/TestProject"

    classDef external fill:#D6E9FF,stroke:#0366D6,color:#0366D6
    classDef infra fill:#E8E8E8,stroke:#999,color:#333
    classDef middleware fill:#DFF0D8,stroke:#3C763D,color:#3C763D
    classDef app fill:#FCF8E3,stroke:#8A6D3B,color:#8A6D3B
    classDef domain fill:#F2DEDE,stroke:#A94442,color:#A94442
    classDef frontend fill:#D9EDF7,stroke:#31708F,color:#31708F
    classDef sample fill:#F5F5F5,stroke:#CCC,color:#333
```
