# alberth527/commonapi architecture

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

- Interactive diagram: https://gitdiagram.com/alberth527/commonapi
- Repository: https://github.com/alberth527/commonapi

## Overview

##### Main Components

A. API Layer
- Controllers (Entry Points)
- AuthController (Authentication/Authorization)
- WeatherForecastController (Sample/Demo functionality)
- BaseController (Common controller functionality)

B. Middleware Layer
- ErrorHandlerMiddleware (Global error handling)
- JWT Authentication (JwtHelper)

C. Data Access Layer
- DbContext (Database connection handling)
- SqlBuilder & SqlQuery (SQL generation and execution)
- BaseRepository & IRepository (Repository pattern implementation)

D. Model Layer
- Entity folder (Domain models)
- APIResult (Standardized response format)
- WeatherForecast (Sample entity)

E. Configuration
- MyAppConfig (Application configuration)
- NLog (Logging infrastructure)

**┌─────────────────────────────────────────────────────────┐**
- Client Requests                       │
- ┬───────────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Middleware Layer                      │
- ┌─────────────────┐        ┌────────────────────┐     │
- Error Handler   │        │  JWT Authentication │     │
- ┘        └────────────────────┘     │
- ┬───────────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Controllers                           │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Auth     │  │   Weather    │  │    Base      │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┬───────────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Repository Layer                      │
- ┌─────────────────┐        ┌────────────────────┐     │
- BaseRepository  │        │    IRepository     │     │
- ┘        └────────────────────┘     │
- ┬───────────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Data Access Layer                     │
- ┌─────────────────┐        ┌────────────────────┐     │
- DbContext    │        │    SQL Builders    │     │
- ┘        └────────────────────┘     │
- ┘

##### Important Relationships to Highlight
- How ErrorHandlerMiddleware intercepts all requests
- Demonstrate the inheritance relationship between BaseController and other controllers
- Implementation of IRepository by BaseRepository
- How DbContext is used by the Repository layer
- How JwtHelper integrates with the Auth flow

##### Technical Stack Indicators
- .NET Core Web API
- JWT Authentication
- SQL Database (implied by SqlBuilder and DbContext)
- NLog logging framework

Remember to:
- Use consistent styling
- Brief descriptions for key components
- Both synchronous and asynchronous flows where applicable

This architecture represents a typical layered application with clear separation of concerns, following common enterprise patterns like Repository Pattern and Middleware Pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CR[Client Requests]
    end

    subgraph Middleware
        EHM["Error Handler"]:::middleware
        JWT["JWT Authentication"]:::middleware
    end

    subgraph Controllers
        BC["Base Controller"]:::controller
        AC["Auth Controller"]:::controller
        WC["Weather Controller"]:::controller
    end

    subgraph Repository
        BR["Base Repository"]:::repository
        IR["IRepository"]:::interface
    end

    subgraph "Data Access"
        DBC["Database Context"]:::data
        SB["SQL Builder"]:::data
        SQ["SQL Query"]:::data
    end

    subgraph Configuration
        MAC["MyAppConfig"]:::config
        NLC["NLog Config"]:::config
        APS["App Settings"]:::config
        APD["Dev Settings"]:::config
    end

    subgraph Testing
        AT["API Tests"]:::test
    end

    subgraph Entry
        PE["Program Entry"]:::entry
    end

    CR --> EHM
    EHM --> JWT
    JWT --> BC
    BC --> AC
    BC --> WC
    AC --> BR
    WC --> BR
    BR -.-> IR
    BR --> DBC
    BR --> SB
    BR --> SQ
    
    %% Click Events
    click BC "https://github.com/alberth527/CommonApi/blob/main/Controllers/BaseController.cs"
    click AC "https://github.com/alberth527/CommonApi/blob/main/Controllers/AuthController.cs"
    click WC "https://github.com/alberth527/CommonApi/blob/main/Controllers/WeatherForecastController.cs"
    click EHM "https://github.com/alberth527/CommonApi/blob/main/WebUtil/ErrorHandlerMiddleware.cs"
    click JWT "https://github.com/alberth527/CommonApi/blob/main/WebUtil/JwtHelper.cs"
    click DBC "https://github.com/alberth527/CommonApi/blob/main/WebUtil/DbContext.cs"
    click SB "https://github.com/alberth527/CommonApi/blob/main/WebUtil/SqlBuilder.cs"
    click SQ "https://github.com/alberth527/CommonApi/blob/main/WebUtil/SqlQuery.cs"
    click BR "https://github.com/alberth527/CommonApi/blob/main/Model/BaseRepository.cs"
    click IR "https://github.com/alberth527/CommonApi/blob/main/Model/IRepository.cs"
    click MAC "https://github.com/alberth527/CommonApi/blob/main/MyAppConfig.cs"
    click NLC "https://github.com/alberth527/CommonApi/blob/main/nlog.config"
    click APS "https://github.com/alberth527/CommonApi/blob/main/appsettings.json"
    click APD "https://github.com/alberth527/CommonApi/blob/main/appsettings.Development.json"
    click AT "https://github.com/alberth527/CommonApi/blob/main/Tests/ApiTests.cs"
    click PE "https://github.com/alberth527/CommonApi/blob/main/Program.cs"

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef middleware fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repository fill:#FF9800,stroke:#EF6C00,color:white
    classDef data fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef test fill:#795548,stroke:#4E342E,color:white
    classDef entry fill:#607D8B,stroke:#37474F,color:white
    classDef interface fill:none,stroke:#FF9800,color:#FF9800,stroke-dasharray: 5 5
```
