# alex-reef/reef.aspnet.security architecture

> Architecture diagram of the GitHub repository alex-reef/reef.aspnet.security, 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/alex-reef/reef.aspnet.security
- Repository: https://github.com/alex-reef/reef.aspnet.security

## Overview

##### Main Components
- Library Core: Represent the core library (Reef.AspNet.Security) as the main module.
- Configuration: A key component is the JwtConfiguration (found in Reef.AspNet.Security/Configuration/JwtConfiguration.cs) which holds the secret, issuer, audience, and expiration settings.
- JWT Service: The IJwtService interface and its concrete implementation (JwtService.cs) that is responsible for generating and validating tokens.
- DI / Service Registration: The DI folder containing ServiceBuilder (Reef.AspNet.Security/DI/ServiceBuilder.cs) which handles registering the required services into the ASP.NET Core dependency injection container.
- Consumer Application: Although not part of this library directly, include an external ASP.NET Core application that uses these services. This component represents the integration point where the library is pulled in and used (as shown in the README’s sample code in Program.cs).

##### Relationships and Interactions
- The external application loads the JWT configuration (from appsettings.json or environment variables) and passes it to the library.
- Service registration is done through a DI extension method (e.g., builder.AddSecurity(jwtConfig)) that wires up the IJwtService and any other required components.
- The IJwtService is then injected into consuming components where token generation, validation, and retrieval of claims are performed.

##### Architectural Patterns and Design Principles
- Dependency Injection: Essential for integrating the library into any ASP.NET Core application.
- Separation of Concerns: The library clearly separates configuration, service logic, and DI setup.
- Encapsulation of Security Logic: The JWT generation and validation are encapsulated within the IJwtService and its implementation.

##### Relevant Technologies and Frameworks
- ASP.NET Core – the hosting framework for integration.
- JWT for security token handling.
- C#/.NET Core project structure (indicated by the .csproj file and the solution file).
- DI container pattern native to ASP.NET Core.

## Diagram (Mermaid)

```mermaid
graph TD
    App["ASP.NET Core Application"]:::external
    LC["Library Core"]:::library
    SB["ServiceBuilder"]:::library
    JS["IJwtService / JwtService"]:::service
    JC["JwtConfiguration"]:::config

    App -->|"uses"| LC
    LC -->|"registers_DI"| SB
    SB -->|"registers_token_service"| JS
    JS -->|"reads_config"| JC

    click LC "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security/Reef.AspNet.Security.csproj"
    click LC "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security"
    click SB "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security/DI/ServiceBuilder.cs"
    click JS "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security/IJwtService.cs"
    click JS "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security/JwtService.cs"
    click JC "https://github.com/alex-reef/reef.aspnet.security/blob/master/Reef.AspNet.Security/Configuration/JwtConfiguration.cs"

    classDef external fill:#cccccc,stroke:#666666,stroke-width:2px;
    classDef library fill:#b3cde0,stroke:#03396c,stroke-width:2px;
    classDef service fill:#fbb4ae,stroke:#d95f02,stroke-width:2px;
    classDef config fill:#ccebc5,stroke:#006400,stroke-width:2px;
```
