# xpertsoftorg/xaf-blazor-kubernetes-example architecture

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

- Interactive diagram: https://gitdiagram.com/xpertsoftorg/xaf-blazor-kubernetes-example
- Repository: https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example

## Overview

##### Project type and purpose
- This is a full-stack, containerized Blazor Server application (XAFContainerExample) with an EF Core/XPO module, deployed to Kubernetes (AKS/K3s) alongside a SQL Server database. Its purpose is to demonstrate horizontal scaling (HPA), ingress routing, and persistent storage in Kubernetes.

##### File structure
- Top-level solution (`XAFContainerExample.sln`) contains two projects:
- XAFContainerExample.Blazor.Server (ASP.NET Core Blazor Server host + Controllers, Services, Pages, wwwroot, Startup/Program)
- XAFContainerExample.Module (BusinessObjects, DbContext, Reports, Module.cs)
- Deployment/configuration artifacts:
- Dockerfiles (Linux, Windows, Nginx)
- docker-compose.yml (+ nginx variant)
- K8S folder with manifests: PersistentVolumeClaim, MS SQL Deployment & Service, App Deployment & Service, Ingress, HPA

##### Core components
a. Client Tier
- Web browsers/users (simulate concurrent connections)
b. Ingress & Networking
- NGINX Ingress Controller (as a Kubernetes Ingress resource or Docker Nginx container)
- LoadBalancer / Kubernetes Service(Type=LoadBalancer)
- Ingress rules (TLS/non-TLS, sticky sessions for Blazor Server)
c. Application Tier
- Kubernetes Deployment “app-depl”
- ReplicaSet & Pods running XAFContainerExample.Blazor.Server.dll
- HorizontalPodAutoscaler adjusting replicas (minReplicas=1, maxReplicas=20, CPU target=50%)
d. Data Tier
- Kubernetes Deployment “mssql-depl” for Microsoft SQL Server
- ClusterIP Service for SQL Server
- PersistentVolumeClaim → PersistentVolume backing SQL data
e. Optional Docker Compose scenario
- Two containers: “web” (Blazor Server) + “db” (mssql/server), Docker network
- Optional “nginx” reverse proxy

##### Relationships & data flows
- Monitoring/Scaling: HPA watches CPU metrics of Deployment → adjusts Pod count
- Kubernetes control plane orchestrates Deployments, ReplicaSets, Services, PVCs, Ingress

##### Architectural patterns & design principles
- Modular monolith: UI (Blazor Server) & business logic in separate assemblies (Server vs Module)
- Containerization: separate images for Linux/Windows hosting + sidecar Nginx reverse proxy
- Infrastructure as Code: Kubernetes manifests define desired state (Deployments, Services, Ingress, HPA, PVC)
- Horizontal scaling via HPA based on CPU utilization
- Sticky sessions for SignalR WebSockets in Blazor Server

##### Detail level
- Module project as a component inside the Blazor Server Pod
- If desired, overlay Kubernetes namespace segmentation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    subgraph "Clients" 
        direction TB
        Browser["Web Browser / Users"]:::client
    end

    subgraph "Ingress & Networking"
        direction TB
        IngressCtrl["Ingress Controller (NGINX)"]:::infra
        LBService["app-svc (LoadBalancer)"]:::infra
        IngressRules["Ingress Rules (TLS, Sticky Sessions)"]:::infra
    end

    subgraph "Kubernetes Cluster"
        direction TB
        subgraph "Application Tier"
            direction TB
            AppDeployment["app-depl Deployment"]:::app
            AppPod["Pod: XAFContainerExample.Blazor.Server"]:::app
            ModuleComp["Component: XAFContainerExample.Module"]:::app
            HPA["HPA (min=1,max=20,cpu=50%)"]:::infra
        end
        subgraph "Data & Storage"
            direction TB
            DBService["mssql-svc (ClusterIP)"]:::infra
            SQLDeployment["mssql-depl Deployment"]:::data
            SQLPod["Pod: SQL Server"]:::data
            PVC["PersistentVolumeClaim → PersistentVolume"]:::storage
        end
    end

    subgraph "Artifacts / Configuration"
        direction TB
        Solution["XAFContainerExample.sln"]:::config
        DockerBuild["Docker Build Definitions"]:::config
        DockerCompose["Docker Compose Scenario"]:::config
        subgraph "K8S Manifests"
            direction TB
            K8sAppMan["app-depl & Service (K8S/app-depl.yaml)"]:::config
            K8sHPA["HPA (K8S/app-hpa.yaml)"]:::config
            K8sIngress["Ingress & LB (K8S/ingress-srv.yaml)"]:::config
            K8sMSSQL["mssql-depl & Service (K8S/mssql-app-depl.yaml)"]:::config
            K8sPVC["PVC (K8S/local-pvc.yaml)"]:::config
        end
        NginxConf["nginx.conf"]:::config
        ClusterImg["images/cluster-diagram.png"]:::config
        GitRules[".gitignore & .dockerignore"]:::config
    end

    %% Connections
    Browser -->|"HTTPS/WebSocket"| IngressCtrl
    IngressCtrl -->|Routes| LBService
    IngressRules --> LBService
    LBService -->|Forward| AppDeployment
    AppDeployment --> AppPod
    AppPod --> ModuleComp
    AppPod -->|DB Connection| DBService
    DBService --> SQLDeployment
    SQLDeployment --> SQLPod
    SQLPod --> PVC
    HPA -. watches .-> AppDeployment

    %% Click Events
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Blazor.Server/Program.cs"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Blazor.Server/Startup.cs"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Blazor.Server/Pages/"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Blazor.Server/Controllers/"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Blazor.Server/Services/"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Blazor.Server/wwwroot/"
    click AppPod "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Blazor.Server/XAFContainerExample.Blazor.Server.csproj"
    click ModuleComp "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Module/Module.cs"
    click ModuleComp "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Module/BusinessObjects/"
    click ModuleComp "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Module/DatabaseUpdate/Updater.cs"
    click ModuleComp "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/XAFContainerExample.Module/Reports/"
    click ModuleComp "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.Module/XAFContainerExample.Module.csproj"
    click DockerBuild "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/tree/main/Dockerfile"
    click DockerBuild "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/Dockerfile.win"
    click DockerBuild "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/Dockerfile.Nginx"
    click DockerCompose "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/docker-compose.yml"
    click DockerCompose "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/docker-compose.nginx.yml"
    click K8sAppMan "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/K8S/app-depl.yaml"
    click K8sHPA "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/K8S/app-hpa.yaml"
    click K8sIngress "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/K8S/ingress-srv.yaml"
    click K8sMSSQL "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/K8S/mssql-app-depl.yaml"
    click K8sPVC "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/K8S/local-pvc.yaml"
    click NginxConf "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/nginx.conf"
    click ClusterImg "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/images/cluster-diagram.png"
    click GitRules "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/.gitignore"
    click GitRules "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/.dockerignore"
    click Solution "https://github.com/xpertsoftorg/xaf-blazor-kubernetes-example/blob/main/XAFContainerExample.sln"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064,color:#006064;
    classDef infra fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32;
    classDef app fill:#fff3e0,stroke:#ef6c00,color:#e65100;
    classDef data fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c;
    classDef storage fill:#e1f5fe,stroke:#0277bd,color:#01579b;
    classDef config fill:#fbe9e7,stroke:#bf360c,color:#bf360c;
```
