Architecture - Blazor Blueprint Clean Architecture & .NET Aspire Guide
Login Register

πŸ“ Architecture Overview

Clean Architecture Benefits

  • Separation of Concerns: Each layer has a single responsibility
  • Testability: Business logic isolated from infrastructure
  • Maintainability: Changes in one layer don't affect others
  • Flexibility: Easy to swap databases, UI frameworks, or external services

🏒 Tenancy Model

Tenant resolution (hostname -> tenant)

Requests are mapped to a tenant using TenantResolutionMiddleware. It normalizes the incoming host, resolves which Organisation owns that hostname, then sets the tenant database + tenant organisation id via ITenantContextSetter.

Resolution rules (high level):

  • Exact domain match: any active organisation whose Organisation.Domains contains the host (including the platform organisation).
  • Subdomain match: if the host is under the platform domain, the first label (e.g. brad in brad.yourdomain.com) is used as the organisation slug.
  • Main domain match: when the host equals a domain in Organisation.Domains, that organisation is selected.
  • Localhost: resolves to the platform organisation.
  • Single-org mode: resolves to the platform organisation by default (and uses the single non-platform org only when it is the only active tenant).

Tenant resolution results are cached briefly (in-memory) and cleared when admin actions update domain mappings.

Multi-org mode supports a cookie override: BB_SelectedOrg can select which organisation is used while you are on the platform host. The cookie override is only applied for page routes (not APIs/static assets) and only when the current resolved tenant is the platform.

Repository scoping (tenant DB vs platform DB)

Mongo repositories use ITenantContext to decide where to read/write:

  • MongoRepository<TEntity> uses CurrentTenantDatabaseName (tenant DB) and applies an organisation id filter for org-scoped entities.
  • PlatformMongoRepository<TEntity> always uses PlatformDatabaseName (platform DB), letting platform-owned entities be stored and queried consistently.

🧭 Platform vs Organisation Responsibilities

The goal is that platform-owned configuration can be applied consistently when browsing tenants on the platform host, while organisation-owned configuration still applies when you are accessing an organisation via its custom domain.

Where configuration lives

Area Platform Admin Organisation Admin
Cookie consent When platform branding is active When using organisation-owned settings
Legal policies When platform branding is active When using organisation-owned settings
PWA configuration When platform branding is active When using organisation-owned settings
Email & push notifications When platform branding is active When using organisation-owned settings
SSO & Audit logs Not platform-managed Organisation admin only

Effective organisation rule (Option B)

The effective organisation is determined by IEffectiveOrganisationSettingsService using: UsePlatformBrandingForSubdomainOrgs and whether the current host is the organisation’s custom domain.

  • If the flag is false, the system always uses the current organisation’s settings.
  • If the flag is true and the organisation is accessed via a custom domain, organisation-owned settings are used.
  • If the flag is true and the organisation is accessed via a subdomain, platform-owned settings are used.

πŸ“ Project Structure

πŸ“ BlazorBlueprint/
πŸ“ Core/ - Business Logic Layer
πŸ“ Application/ - Use cases, CQRS, MediatR
πŸ“ Domain/ - Entities, value objects, interfaces
πŸ“ ServiceDefaults/ - Shared configurations
πŸ“ Infrastructure/ - Data Access Layer
πŸ“ MongoDB/ - Database implementation
πŸ“ Extensions/ - Service registrations
πŸ“ Web/ - Presentation Layer
πŸ“ BlazorBlueprint.Web/ - Blazor Server UI
πŸ“ Services/ - API Services
πŸ“ ApplicationService/ - REST API endpoints
πŸ“ WorkerService/ - .NET Worker Service for background processing
πŸ“ Dev/ - Development Tools
πŸ“ AppHost/ - .NET Aspire orchestration
πŸ“ .github/workflows/ - GitHub Actions CI/CD
πŸ“ .azure/devops/ - Azure DevOps CI/CD

πŸ—οΈ Solution Architecture

Clean Architecture with .NET Aspire orchestration

🎨 Presentation Layer
🌐
Blazor Web
UI Components, Pages, Controllers
πŸ“‘
SignalR Hubs
Real-time Communication
πŸ“±
PWA
Service Worker, Manifest
βš™οΈ Application Layer
πŸ”§
Services
Business Logic, Use Cases
πŸ“‹
Interfaces
Service Contracts, Abstractions
πŸ“Š
Models
DTOs, ViewModels, Settings
πŸ›οΈ Domain Layer
🏒
Entities
Business Objects, Domain Models
πŸ”—
Interfaces
Repository Contracts, Domain Abstractions
⚑
Extensions
Domain Logic, Business Rules
πŸ”§ Infrastructure Layer
πŸ—„οΈ
MongoDB
Data Persistence, Repository Implementation
⚑
Redis
Page Output Caching, API Response Caching, SignalR Backplane
πŸ“¬
Kafka
Message Queue, Background Job Processing
βš™οΈ
.NET Worker Service
Background Processing, Queue Processing
πŸ“§
Email Providers
SendGrid, SMTP, MailerSend, Mailgun
πŸ€–
AI Services
OpenAI API, Chat Moderation
πŸ”
Identity
ASP.NET Core Identity, Custom Stores
πŸš€ .NET Aspire Orchestration
πŸ”
Service Discovery
πŸ“Š
Health Checks
πŸ”—
Service Communication
πŸ“ˆ
Observability
🐳
Container Orchestration
⚑
Resource Management
🌐 External Services
πŸ”
Identity Providers
πŸ“§
Email Services
πŸ€–
AI APIs
πŸ”—
Application Service

πŸ› οΈ Technology Stack

Built with modern technologies and best practices

Frontend

Blazor Server Fluent UI Responsive Design

Backend

.NET 10 ASP.NET Core SignalR MongoDB Redis Caching Output Caching Distributed Caching SignalR Backplane IRepository Pattern

Architecture

Clean Architecture Service Layer Pattern Dependency Injection Generic Repository

DevOps & Deployment

Docker Docker Compose Azure DevOps GitHub Actions Docker Hub GitHub Container Registry CI/CD Pipelines Container Orchestration Kubernetes Multi-Stage Builds

Features

Identity & Auth Real-time Chat Content Management AI Integration Multi-Tenant SaaS PWA Support Push Notifications Support System User Management Dynamic Pages Audit Logging GDPR Compliance .NET Worker Service Kafka Kubernetes Multi-Provider Email External OAuth (Facebook & Google) SEO Optimization Two-Factor Auth Theme Management Notification Preferences Personal Data Management External Login Management

πŸ“¦ Ready to Download?

Start building with Blazor Blueprint's Clean Architecture today. Download the free Developer version or get Enterprise with premium plugins and commercial licensing.

πŸ”“ Open Source on GitHub β€’ Free for personal/non-commercial use β€’ Enterprise license (Β£399) required for commercial use β€’ Full source code included

An unhandled error has occurred. Reload ??