# calabonga/microservice-template architecture

> Architecture diagram of the GitHub repository calabonga/microservice-template, 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/calabonga/microservice-template
- Repository: https://github.com/calabonga/microservice-template

## Overview

- An Identity Module Template (which leverages OpenIddict for OAuth2.0 authentication and supports both cookie and bearer schemes)
- A Module Template (designed to act as a “business” or application service without built‐in OpenIddict)

There’s also a sample client application (a Blazor Web App under AuthClientSamples) intended to demonstrate how to consume the identity service for authentication. Additionally, note that several folder structures are repeated for two versions of the ASP.NET Core platform (v8.0 and v9.0), and this is done to support multiple target environments.

##### Main Components
- Identity Service Microservice – Show the IdentityModule template with its layered structure. Inside this service, indicate:
– Domain Layer (Domain models, Base classes, interfaces like IAuditable, IHaveId)
– Infrastructure Layer (DB Contexts, Database Initialization, ApplicationUser, ApplicationRole, etc.)
– Web/API Layer (Endpoints for authorization, token, profiles; hosted services like OpenIddictWorker; messaging endpoints)
– Definitions – Group the “Definitions” folders that include components for error handling, dependency injection (ContainerDefinition), ETag generation, mediator configuration, and OpenIddict pieces.
- Module/Business Microservice – Similar to the Identity module, show it with it’s own Domain, Infrastructure, Web/API, and Definitions layers. Note that it handles endpoints for EventItem and Profile messages.
- Client Applications – Include the “AuthClientSamples/BlazorWebApp” sample which demonstrates integration with the Identity Module for authentication.
- Shared/External Dependencies – Represent common libraries (for example, the shared nuget packages such as Calabonga.Results and UnitOfWork, OpenIddict, Mediatr, AutoMapper, and Swagger/OpenAPI generators). Indicate external systems such as the database and possibly external authorization providers that might be used if extended.

##### Relationships and Interactions
- That the Identity Microservice provides authentication, authorization, and token issuance functionality, which is consumed by both the Module Microservice (for cross-service security) and the client (via OAuth2.0 flows).
- How the Module Microservice exposes its API endpoints (using mediator patterns and error handling middleware) and uses a similar architectural layering.

##### Architectural Patterns and Design Principles
- The project clearly follows a layered architecture (Domain, Infrastructure, API/Web, and Application/Services) with a mix of Clean/Vertical Slice patterns.
- Use of Mediatr for command/queries – illustrate how API endpoints call into the mediator layer that then interacts with business logic.
- You might also illustrate key design components such as Dependency Injection (using ContainerDefinition classes), error handling (via middleware and OperationResult or FluentValidation), and the use of hosted services.

##### Relevant Technologies, Frameworks, and Libraries
- ASP.NET Core (with different target versions, v8.0, v9.0, etc.)
- OpenIddict (integrated into the Identity Module for secure token-based authentication)
- Mediatr (for internal messaging and encapsulation of business logic)
- Swagger/OpenAPI (to generate interactive API documentation)
- Entity Framework (with custom DBContext implementations in the Infrastructure layer)
- NuGet packages such as Calabonga.Results, UnitOfWork and others that support cross-cutting concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Identity Service Microservice
    subgraph "Identity Service Microservice"
        subgraph "Domain Layer"
            ID_Domain["Domain: Models, Base classes, IAuditable, IHaveId"] 
        end
        subgraph "Infrastructure Layer"
            ID_Infrastructure["Infrastructure: DB Contexts, ApplicationUser, ApplicationRole"] 
        end
        subgraph "Web/API Layer"
            ID_Web["Web/API: Authorization Endpoints, Token, Profiles, Hosted Services (OpenIddictWorker)"] 
        end
        subgraph "Definitions"
            ID_Def["Definitions: Error Handling, DI Container, ETag, Mediator, OpenIddict"] 
        end
    end

    %% Module/Business Microservice
    subgraph "Module/Business Microservice"
        subgraph "Domain Layer"
            Mod_Domain["Domain: Business Models and Logic"] 
        end
        subgraph "Infrastructure Layer"
            Mod_Infrastructure["Infrastructure: DB Contexts, Persistence"] 
        end
        subgraph "Web/API Layer"
            Mod_Web["Web/API: Endpoints for EventItem and Profile; Mediatr Integration"] 
        end
        subgraph "Definitions"
            Mod_Def["Definitions: Error Handling, Mediator, Mapping"] 
        end
    end

    %% Client Application
    subgraph "Client Application"
        Client["Blazor Web App (AuthClient Sample)"] 
    end

    %% External Dependencies
    ExternalDB[(Database)]
    SharedLibs["Shared Libraries: Calabonga.Results, UnitOfWork, OpenIddict, Mediatr, AutoMapper, Swagger/OpenAPI"]

    %% Connections between components
    Client -->|"OAuth2.0LoginTokenRequest"| ID_Web
    ID_Web -->|"TokenIssuanceAuthResponse"| Client
    Mod_Web -->|"SecuredAPICallsWithToken"| ID_Web
    Client -->|"BusinessAPIRequests"| Mod_Web

    %% Internal mediator and service calls
    ID_Web -->|"MediatorCall"| ID_Def
    Mod_Web -->|"MediatorCall"| Mod_Def
    ID_Web -->|"EF_DataAccess"| ExternalDB
    Mod_Web -->|"EF_DataAccess"| ExternalDB

    %% Shared libraries connected to definitions and client
    SharedLibs --- ID_Def
    SharedLibs --- Mod_Def
    SharedLibs --- Client

    %% Component click events
    click ID_Domain "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.IdentityModule.Template/content/Calabonga.Microservice.IdentityModule.Domain"
    click ID_Infrastructure "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.IdentityModule.Template/content/Calabonga.Microservice.IdentityModule.Infrastructure"
    click ID_Web "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.IdentityModule.Template/content/Calabonga.Microservice.IdentityModule.Web"
    click ID_Def "https://github.com/calabonga/microservice-template/tree/master/AspNetCore v8.0/Calabonga.Microservice.IdentityModule.Template/content/Calabonga.Microservice.IdentityModule.Web/Definitions"
    click Mod_Domain "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.Module.Template/content/Calabonga.Microservice.Module.Domain"
    click Mod_Infrastructure "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.Module.Template/content/Calabonga.Microservice.Module.Infrastructure"
    click Mod_Web "https://github.com/calabonga/microservice-template/blob/master/AspNetCore v8.0/Calabonga.Microservice.Module.Template/content/Calabonga.Microservice.Module.Web"
    click Mod_Def "https://github.com/calabonga/microservice-template/tree/master/AspNetCore v8.0/Calabonga.Microservice.Module.Template/content/Calabonga.Microservice.Module.Web/Definitions"
    click Client "https://github.com/calabonga/microservice-template/tree/master/AuthClientSamples/BlazorWebApp"

    %% Styles
    classDef identity fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef module fill:#ccffcc,stroke:#00cc00,stroke-width:2px;
    classDef client fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#cccc00,stroke-width:2px;

    class ID_Domain,ID_Infrastructure,ID_Web,ID_Def identity;
    class Mod_Domain,Mod_Infrastructure,Mod_Web,Mod_Def module;
    class Client client;
    class ExternalDB,SharedLibs external;
```
