What are Modules?
Modules are self-contained, vertically-sliced bounded contexts that encapsulate specific business capabilities. Each module owns its:- Domain models and business logic
- Database schema via dedicated DbContext
- HTTP endpoints using Minimal APIs
- Dependency injection registration
- Health checks and initialization
The IModule Interface
Every module implements theIModule interface, which defines two core responsibilities:
ConfigureServices
Registers all module dependencies, including:- Services and repositories
- DbContext with connection pooling
- Health checks
- Options configuration
- Background workers
- Event handlers
Services registered here should not depend on ASP.NET Core HTTP types. Keep this layer focused on application infrastructure.
MapEndpoints
Configures HTTP routing using Minimal APIs:- API versioning
- Route groups with base paths
- Individual endpoints with authorization
- Rate limiting
Module Registration
Modules are automatically discovered and loaded using assembly-level attributes:order parameter controls initialization sequence:
- Lower numbers execute first
- Identity (100) loads before Multitenancy (200)
- Critical infrastructure modules load early
Loading Modules
TheModuleLoader discovers and initializes modules from assemblies:
Module Lifecycle
Discovery
The
ModuleLoader scans assemblies for FshModuleAttribute declarations and instantiates module classes.Service Configuration
Each module’s
ConfigureServices method is called in order, registering dependencies with the DI container.Validation Registration
FluentValidation validators are automatically discovered from module assemblies.
Built-in Modules
FullStackHero includes three core modules:Identity
Authentication, authorization, users, roles, permissions, and sessions
Multitenancy
Tenant provisioning, isolation, and management with database per tenant
Auditing
Security audits, activity logging, and exception tracking
Module Isolation
Modules maintain clear boundaries:| Aspect | Approach |
|---|---|
| Database | Separate DbContext per module |
| Contracts | Shared via *.Contracts projects |
| Events | Integration events for cross-module communication |
| Dependencies | Modules don’t directly reference each other |
| Endpoints | Prefixed with module name (e.g., /api/v1/identity/*) |
Module Structure
A typical module follows this organization:Health Checks
Modules register health checks duringConfigureServices:
/health endpoint.
Next Steps
Create Custom Module
Learn how to build your own modules from scratch
Identity Module
Explore authentication and authorization features
