# jonpsmith/authpermissions.aspnetcore architecture

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

- Interactive diagram: https://gitdiagram.com/jonpsmith/authpermissions.aspnetcore
- Repository: https://github.com/jonpsmith/authpermissions.aspnetcore

## Overview

##### Project type and purpose
- This is an open-source .NET library (AuthPermissions.AspNetCore) providing advanced authorization, multi-tenant database support, and JWT-refresh token functionality for ASP.NET Core applications.
- It is organized as a multi-project solution that includes:
- Core business logic (AuthPermissions.BaseCode)
- ASP.NET Core integration (AuthPermissions.AspNetCore)
- Database providers (AuthPermissions.PostgreSql, AuthPermissions.SqlServer)
- Support code for different authentication systems
- Admin and bulk-load services
- Example consumer apps (Razor Pages, Web API, MVC)
- Extensive unit and integration tests

##### File structure
- Top-level solution (`AuthPermissions.AspNetCore.sln`) references multiple class-library projects.
- Key component projects:
- AuthPermissions.BaseCode: Domain models, EF Core context, permission packer/unpacker, multi-tenant support
- AuthPermissions.AspNetCore: ASP-NET Core middleware, attributes, policy providers, JWT and OpenID code, sharding services, startup extensions
- AuthPermissions.PostgreSql / SqlServer: Provider-specific EF Core DbContext factories and migrations
- SupportCode / AdminCode / BulkLoadServices: Utilities for user-invite flows, AzureAD integration, tenant administration, role/user bulk loading
- ExamplesCommonCode: Shared DTOs & helpers for the sample apps
- ExampleN.*: Consumer applications illustrating usage patterns: individual accounts, JWT tokens, multi-tenant, sharding, AzureAD, etc.
- Test: Stubs, DI helpers, TestData and UnitTests covering every layer

##### README insights
- Emphasizes library features: dynamic role-permission management, hierarchical or one-level multi-tenant patterns, JWT refresh tokens.
- Documentation lives on GitHub Wiki; packaging uses a custom `JonPSmith.MultiProjPack` tool.
- Supports cookie or JWT auth, any ASP.NET Core auth provider, with built-in individual and Azure AD versions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Example1["Example1.RazorPages.IndividualAccounts"]:::example
        Example2["Example2.WebApiWithToken.IndividualAccounts"]:::example
        Example3A["Example3.InvoiceCode"]:::example
        Example3B["Example3.MvcWebApp.IndividualAccounts"]:::example
        Example4A["Example4.MvcWebApp.IndividualAccounts"]:::example
        Example4B["Example4.ShopCode"]:::example
        Example5["Example5.MvcWebApp.AzureAdB2C"]:::example
        Example6A["Example6.MvcWebApp.Sharding"]:::example
        Example6B["Example6.SingleLevelSharding"]:::example
        Example7A["Example7.MvcWebApp.ShardingOnly"]:::example
        Example7B["Example7.SingleLevelShardingOnly"]:::example
        Tests["Test Harness & Utilities"]:::example
    end

    %% Integration Layer
    subgraph "Integration Layer" 
        direction TB
        ASPNetCore["AuthPermissions.AspNetCore"]:::integ
    end

    %% Core Domain & Data Layer
    subgraph "Core Domain & Data Layer"
        direction TB
        BaseCode["AuthPermissions.BaseCode"]:::core
    end

    %% Infrastructure Providers
    subgraph "Infrastructure Providers"
        direction TB
        PgSql["AuthPermissions.PostgreSql"]:::infra
        SqlServer["AuthPermissions.SqlServer"]:::infra
    end

    %% Support/Admin Services
    subgraph "Support/Admin Services"
        direction TB
        SupportCode["AuthPermissions.SupportCode"]:::support
        AdminCode["AuthPermissions.AdminCode"]:::support
        BulkLoad["AuthPermissions.BulkLoadServices"]:::support
    end

    %% Packaging Tool
    subgraph "Packaging Workflow"
        direction TB
        MultiProjPack["MultiProjPack.xml"]:::support
    end

    %% External Services
    subgraph "External Services"
        direction TB
        AzureAD["Azure AD / OpenID Connect"]:::external
    end

    %% Dependencies
    Example1 -->|uses DI| ASPNetCore
    Example2 -->|uses DI| ASPNetCore
    Example3A -->|uses DI| ASPNetCore
    Example3B -->|uses DI| ASPNetCore
    Example4A -->|uses DI| ASPNetCore
    Example4B -->|uses DI| ASPNetCore
    Example5 -->|uses DI| ASPNetCore
    Example6A -->|uses DI| ASPNetCore
    Example6B -->|uses DI| ASPNetCore
    Example7A -->|uses DI| ASPNetCore
    Example7B -->|uses DI| ASPNetCore
    Tests -->|references| BaseCode
    Tests -->|references| ASPNetCore
    Tests -->|references| PgSql
    Tests -->|references| SqlServer
    Tests -->|references| SupportCode
    Tests -->|references| AdminCode
    Tests -->|references| BulkLoad

    ASPNetCore -->|calls business rules| BaseCode
    ASPNetCore -->|configures EF Core| BaseCode
    BaseCode -->|delegates migrations| PgSql
    BaseCode -->|delegates migrations| SqlServer
    ASPNetCore -->|optional plugin| SupportCode
    ASPNetCore -->|optional plugin| AdminCode
    ASPNetCore -->|optional plugin| BulkLoad
    SupportCode -->|Azure AD integration| AzureAD
    AdminCode -->|tenant/user admin| BaseCode
    BulkLoad -->|bulk role/user| BaseCode

    MultiProjPack -->|reads csproj & config| AuthPermissions_AspNet_Sln[(AuthPermissions.AspNetCore.sln)]:::core
    MultiProjPack -->|outputs NuGet| NuPkg[(.nupkg)]:::support

    %% Click Events
    click BaseCode "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions.BaseCode/"
    click ASPNetCore "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions.AspNetCore/"
    click PgSql "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions.PostgreSql/"
    click SqlServer "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions.SqlServer/"
    click SupportCode "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions.SupportCode/"
    click AdminCode "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions/AdminCode/"
    click BulkLoad "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/AuthPermissions/BulkLoadServices/"
    click MultiProjPack "https://github.com/jonpsmith/authpermissions.aspnetcore/blob/main/AuthPermissions.AspNetCore/MultiProjPack.xml"
    click ExamplesCommonCode "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/ExamplesCommonCode/"
    click Example1 "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example1.RazorPages.IndividualAccounts/"
    click Example2 "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example2.WebApiWithToken.IndividualAccounts/"
    click Example3A "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example3.InvoiceCode/"
    click Example3B "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example3.MvcWebApp.IndividualAccounts/"
    click Example4A "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example4.MvcWebApp.IndividualAccounts/"
    click Example4B "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example4.ShopCode/"
    click Example5 "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example5.MvcWebApp.AzureAdB2C/"
    click Example6A "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example6.MvcWebApp.Sharding/"
    click Example6B "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example6.SingleLevelSharding/"
    click Example7A "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example7.MvcWebApp.ShardingOnly/"
    click Example7B "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Example7.SingleLevelShardingOnly/"
    click Tests "https://github.com/jonpsmith/authpermissions.aspnetcore/tree/main/Test/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,color:#004085;
    classDef integ fill:#d4edda,stroke:#155724,color:#155724;
    classDef infra fill:#fff3cd,stroke:#856404,color:#856404;
    classDef support fill:#f5c6cb,stroke:#721c24,color:#721c24;
    classDef example fill:#e2e3e5,stroke:#383d41,color:#383d41;
    classDef external fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
```
