# genocs/microservice-template architecture

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

- Interactive diagram: https://gitdiagram.com/genocs/microservice-template
- Repository: https://github.com/genocs/microservice-template

## Overview

##### Project Type and Purpose
- The project is an API-centric microservice template designed for .NET9.
- It serves as a starting point for building microservices based on Clean Architecture, Domain Driven Design, and includes advanced features such as multi-tenancy (using Finbuckle), CQRS, containerization, and cloud deployments.
- The README clearly indicates that the solution provides components such as Identity management, Catalog operations, Background Jobs, Notifications, and more.

##### Break Down the Main Components & Layers
- Frontend/API Layer (Web API):
– Represented by the “src/WebApi” folder which contains Controllers (Catalog, Identity, Dashboard, Multitenancy, Personal, etc.), Program.cs, and configuration files.
– Highlight API versioning, Swagger/OpenAPI integration, and end-user entry points.
- Application Layer:
– Located in “src/Core/Application” (inside the template) which encapsulates business logic, CQRS commands and queries, request validators, event handlers, DTOs, and caching.
– Include components like Identity (token service, user/role services) and Catalog (brands, products).
- Domain Layer:
– Located in “src/Core/Domain” which defines the domain models, aggregates, domain events, and contracts.
– Emphasize domain entities like Product, Brand and supporting contracts for Domain Events.
- Infrastructure Layer:
– Found in “src/Infrastructure” – This layer integrates external systems such as databases (with EF Core and Dapper for persistence), caching, file storage, mailing, logging (Serilog integration), and authentication (JWT, Azure AD).
– Show sub-components like persistence (repositories, DB contexts), external service integrations, and middleware (error handling, request/response logging).
- Cross-Cutting Concerns:
– Background jobs (Hangfire, as seen in the Hangfire-related files).
– Multi-tenancy support (configuration and tenant management in both Application and Infrastructure).
– Notifications/SignalR services for pushing real-time events.
– Mapping utilities (Mapster) and API security (permissions, role-based authorization).

##### Additional Supporting Elements
- Migrators:
– The “src/Migrators” directory, which includes migration projects for multiple databases (MSSQL, MySQL, Oracle, PostgreSQL, SQLite).
– Show data migration as an external process to synchronize the Domain/Infrastructure layer with the database schema.
- DevOps & Containerization:
– GitHub workflows (from “.github/workflows”) and Makefile commands.
– Docker-related files (docker-compose files, Dockerfile in the template) and Terraform configuration (for AWS ECS deployments).
– Indicate a CI/CD pipeline and container orchestration as external services.
- Testing:
– Note the presence of “src/template/tests” which contains unit and integration tests validating infrastructure, caching, localization, persistence, and custom validations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        WebApi["Web API Layer\n(Controllers, Swagger/OpenAPI)"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        AppService["Application Service\n(CQRS, MediatR, Validators, DTOs)"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DomainModel["Domain Model\n(Entities, Aggregates, Domain Events)"]:::dom
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        InfraService["Infrastructure Service\n(Repositories, Caching, Logging, Authentication)"]:::infra
        Database["Database\n(EF Core, Dapper)"]:::external
        ExternalID["External Identity\n(JWT, Azure AD)"]:::external
        EmailService["Email Service"]:::external
    end

    %% DevOps & Containerization Components
    subgraph "DevOps & Containerization"
        DevOpsCD["CI/CD Workflows"]:::devops
        DockerTerraform["Docker/Terraform Deployments"]:::devops
    end

    %% Migrators
    Migrators["Migrators\n(Data Migration)"]:::migrators

    %% Testing
    TestingSuite["Testing Suite\n(Unit/Integration Tests)"]:::testing

    %% Flow of Requests Through Layers
    Client -->|"APIRequest"| WebApi
    WebApi -->|"APIcall"| AppService
    AppService -->|"Command/Query"| DomainModel
    DomainModel -->|"DataPersistence"| InfraService
    InfraService -->|"Stores Data"| Database
    InfraService -->|"Uses"| ExternalID
    InfraService -->|"Sends Notifications"| EmailService

    %% Migrators connecting to Database
    Migrators -->|"SyncSchema"| Database

    %% DevOps & Containerization Deployment Flow
    DevOpsCD -->|"Triggers"| DockerTerraform
    DockerTerraform -->|"Deploys"| InfraService

    %% Testing interacts with API layer
    TestingSuite -->|"Tests"| WebApi

    %% Click Events
    click WebApi "https://github.com/genocs/microservice-template/tree/main/src/template/src/WebApi"
    click AppService "https://github.com/genocs/microservice-template/tree/main/src/template/src/Core/Application"
    click DomainModel "https://github.com/genocs/microservice-template/tree/main/src/template/src/Core/Domain"
    click InfraService "https://github.com/genocs/microservice-template/tree/main/src/template/src/Infrastructure"
    click Migrators "https://github.com/genocs/microservice-template/tree/main/src/template/src/Migrators"
    click DevOpsCD "https://github.com/genocs/microservice-template/blob/main/.github"
    click DockerTerraform "https://github.com/genocs/microservice-template/tree/main/src/template"
    click TestingSuite "https://github.com/genocs/microservice-template/tree/main/src/template/tests"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dom fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef migrators fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef devops fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef testing fill:#E0FFFF,stroke:#000,stroke-width:2px;
    classDef external fill:#FFE4B5,stroke:#000,stroke-width:2px;
```
