# g0oce/certificate-login architecture

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

- Interactive diagram: https://gitdiagram.com/g0oce/certificate-login
- Repository: https://github.com/g0oce/certificate-login

## Overview

##### Main Components
a. Presentation/API Layer:
- Projects: Web and CertAuth
- Role: These projects contain controllers (located under Controllers/V1, for example) that are responsible for handling HTTP requests, mapping endpoints (e.g., CertificateController.cs, HomeController.cs, UserController.cs) and initializing dependency injection via Installer classes.

b. Business Logic / Service Layer:
- Project: Services (which includes CertificateValidationServices and UserServices) and parts of SecurityManager
- Role: Implements the core business operations such as certificate validation and user management. SecurityManager also deals with generating and managing tokens (via RsaKeyProvider and TokenHelper), which is critical in certificate-based authentication.

c. Data Access Layer:
- Project: DataAccess
- Role: Implements repositories (CustomerRepository, UserRepository) and the Unit of Work pattern. This layer abstracts database operations (with a DapperDbContext) and enforces data consistency.

d. Common Utilities:
- Project: Common
- Role: Provides shared helpers, extension methods, enums, and resources that are used across multiple layers.

e. Cryptography / Certificate Management:
- Project: FrdCoreCrypt
- Role: Manages certificate-specific operations such as certificate claim conversions, handling certificate statuses, and possibly orchestrates OCSP client interactions via FrdOcspClient. This module is integral in handling encryption and digital signing aspects.

f. Auxiliary Components:
- Project: SocketCore
- Role: Contains a separate Dockerfile and appears to utilize socket communication. This can be an additional communication service or real-time component that works alongside the HTTP based APIs.
- StaticFiles: Holds documents like “Certificate Login.docx” and SQL scripts (script.sql) that might be used for documentation or database setup.

##### Relationships and Interactions
- The Web and CertAuth projects serve as entry points for client requests. They call into the Services layer to process business logic.
- The Services layer in turn retrieves or persists data via the DataAccess layer’s repositories and Unit of Work.
- Both the Services and SecurityManager components integrate cryptographic functions from FrdCoreCrypt to handle certificate processing.
- Common code is shared across these layers to enforce consistent business rules and utility functions.
- SocketCore operates as a parallel component that might be communicating with the other layers for real-time updates or supplemental authentication notifications via sockets.

##### Architectural Patterns and Design Principles
- Layered Architecture: The solution follows a typical layered design (Presentation -> Business Logic -> Data Access) promoting separation of concerns.
- Dependency Injection: Multiple Installer classes indicate a heavy reliance on DI for modularity and testability.
- Repository and Unit of Work Patterns: These patterns are used in the DataAccess project.
- Microservices or Distributed Components: The presence of multiple projects (such as SocketCore) can indicate that certain functionalities may be deployed as separate services or containers (especially with Dockerfiles and docker-compose).
- Security Best Practices: Cryptographic operations, token management, and certificate validation imply a design tailored around robust security.

##### Incorporate Relevant Technologies and Frameworks
- .NET Core (or .NET 5/6 depending on your version) is the primary framework for these projects.
- ASP.NET MVC/Web API is in use given the Controllers and Startup configuration.
- Dependency injection frameworks (built-in DI or others) are evident in the Installer folders.
- Dapper is used in DataAccess for database communication.
- Docker is part of the deployment setup with Dockerfiles in CertAuth and SocketCore.
- External services may be abstracted (like OCSP with FrdOcspClient) for certificate revocation checking.

##### Summary of Steps
- Detail sub-components (controllers, services, repositories, installers) within each block.
- Use callouts or notes to mention design patterns (e.g., Repository Pattern, Dependency Injection) next to the related components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation/API Layer
    subgraph "Presentation/API Layer"
        A1("CertAuth (Controllers & Installers)"):::presentation
        A2("Web (Controllers & Installers)"):::presentation
    end

    %% Business Logic / Service Layer
    subgraph "Business Logic / Service Layer"
        B1("Services (Certificate & User Services)"):::business
        B2("SecurityManager (Token & Crypto)"):::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        C1("DataAccess (Repositories & UoW)"):::data_access
    end

    %% Common Utilities
    subgraph "Common Utilities"
        D1("Common Utilities"):::common
    end

    %% Cryptography / Certificate Management
    subgraph "Cryptography / Certificate Management"
        E1("FrdCoreCrypt (Certificate Management)"):::crypto
    end

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        F1("SocketCore (Socket Communication)"):::auxiliary
        F2("StaticFiles (Docs & SQL Scripts)"):::auxiliary
    end

    %% Connections between layers
    %% Presentation to Business Logic
    A1 -->|"HTTPcalls"| B1
    A2 -->|"HTTPcalls"| B1

    %% Business Logic interactions
    B1 -->|"RepositoryCalls"| C1
    B1 -->|"CertOps"| E1
    B2 -->|"Token/Crypto"| E1
    B2 -->|"AuthToken"| A1
    B2 -->|"AuthToken"| A2

    %% Auxiliary real-time communication
    F1 -->|"RealTimeData"| B1

    %% Common Utilities are used by all layers (dashed lines)
    A1 ---|"Uses"| D1
    A2 ---|"Uses"| D1
    B1 ---|"Uses"| D1
    B2 ---|"Uses"| D1
    C1 ---|"Uses"| D1
    E1 ---|"Uses"| D1

    %% Click Events
    click A1 "https://github.com/g0oce/certificate-login/tree/master/CertAuth/Controllers/V1"
    click A2 "https://github.com/g0oce/certificate-login/tree/master/Web/Controllers/V1"
    click B1 "https://github.com/g0oce/certificate-login/tree/master/Services/Services/CertificateValidationServices"
    click B2 "https://github.com/g0oce/certificate-login/tree/master/SecurityManager/Helpers"
    click C1 "https://github.com/g0oce/certificate-login/tree/master/DataAccess/Repositories"
    click D1 "https://github.com/g0oce/certificate-login/tree/master/Common"
    click E1 "https://github.com/g0oce/certificate-login/tree/master/FrdCoreCrypt"
    click F1 "https://github.com/g0oce/certificate-login/tree/master/SocketCore"
    click F2 "https://github.com/g0oce/certificate-login/tree/master/StaticFiles"

    %% Styles
    classDef presentation fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef business fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef data_access fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef common fill:#99ffff,stroke:#333,stroke-width:2px;
    classDef crypto fill:#cc99ff,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#ff9999,stroke:#333,stroke-width:2px;
```
