How redline-solutions-inc/redline-gaia works
Project type and purpose
• This is a full-stack .NET API project following Clean (Onion) Architecture principles, implementing a multi-tenant architecture with separate databases per tenant, plus a master database (“Tenant Registry”).
• The solution exposes HTTP endpoints via ASP.NET Core Web API, processes commands/queries via MediatR, persists using Entity Framework, and supports tenant migrations via a console app.
File structure
• Top-level projects/layers:
• RedLine-Gaia.Domain – core business entities, errors, repository and service interfaces.
• RedLine-Gaia.Application – application layer with features (Commands, Queries, DTOs), MediatR handlers, validation behaviors, Mapster config, DI.
• RedLine-Gaia.Infrastructure – EF Core DbContexts (MasterDbContext, ApplicationDbContext for tenant), repositories, Unit of Work, tenant/current-tenant services, migrations folders.
• RedLine-Gaia.WebApi – ASP.NET Core API: controllers, middleware (GlobalExceptionHandler, TenantResolver, TenantActionFilter), Program.cs, appsettings.
• TenantDatabaseMigrater – console app to run EF migrations against master and tenant DBs.
• Tests – xUnit tests for application and infrastructure layers.
README insights
• Emphasizes Onion Architecture: Domain at center, outer layers depend inward.
• Multi-tenant design: shared schema per tenant DB, plus master DB for registry.
• Core patterns: Repository, Unit of Work, MediatR, FluentValidation, Mapster.
• External dependencies: Serilog/BetterStack logging, Scalar (Swagger UI generation).
a. Main components:
• Presentation/API Layer (WebApi project, Controllers, Middleware)
• Application Layer (MediatR pipeline: Commands, Queries, Handlers, Behaviors, DTOs)
• Domain Layer (Entities, Errors, Interfaces)
• Infrastructure Layer
– Tenant Registry (MasterDbContext + TenantMaster migrations)
– Tenant Databases (ApplicationDbContext + Migrations directory)
– Repositories & UoW
– CurrentTenantService, TenantService, DbContextFactory
• TenantDatabaseMigrater (Console app orchestrating migrations)
• External Systems: BetterStack logging, SQL Servers for Master + Tenant DBs, Swagger/Scalar UI
b. Relationships & interactions:
• Client HTTP → WebApi Middleware (TenantResolver reads header, sets current tenant)
→ Controller → MediatR → Application Handlers → inject DbContext from DbContextFactory → Repositories/UoW → EF Core → Tenant DB → return ResultDTO → back up the chain.
• TenantService (singleton) → reads master DB → resolves tenant connection string.
• CurrentTenantService (scoped) → holds tenant info for each request.
• TenantDatabaseMigrater console → uses TenantService → enumerates tenants → applies EF migrations to each tenant DB (and Master DB).
c. Architectural patterns & design principles:
• Onion/Clean Architecture: clear layer dependencies inward.
• CQRS via MediatR: separating reads (Queries) and writes (Commands).
• Repository + Unit of Work for data access abstraction.
• Dependency Injection across layers (Infrastructure implements Domain interfaces).
• Middleware for cross-cutting concerns: exception handling, tenant resolution.
• Multi-tenancy via separate databases with a registry pattern.
d. Key technologies/frameworks:
• ASP.NET Core Web API, Middleware pipeline
• MediatR for in-process messaging
• Entity Framework Core for ORM
• FluentValidation for command input validation
• Mapster for DTO mapping
• Serilog + BetterStack for logging
• Scalar for API documentation UI
• xUnit + FluentAssertions + NSubstitute for unit tests