Modular Feature-Based Clean Architecture (MFCA)

A modern approach to scalable and maintainable monoliths.

1. Introduction

MFCA is a pragmatic backend architecture that combines Domain Driven Design (DDD) principles, Clean Architecture, REPR Pattern, Vertical Slice Architecture and N Layer Architecture.

2. Architectural Goals

3. Project Structure

csharp_mfca.API/
โ”œโ”€โ”€ Configurations/
โ”œโ”€โ”€ Constants/
โ”œโ”€โ”€ Entities/
โ”œโ”€โ”€ Exceptions/
โ”œโ”€โ”€ Extensions/
โ”œโ”€โ”€ Features/
โ”‚   โ”œโ”€โ”€ Core/
โ”‚   โ”œโ”€โ”€ Users/
โ”‚   โ”‚   โ”œโ”€โ”€ Core/
โ”‚   โ”‚   โ””โ”€โ”€ CreateUser/
โ”œโ”€โ”€ Models/
โ”œโ”€โ”€ Middlewares/
โ”œโ”€โ”€ Persistence/
โ”‚   โ”œโ”€โ”€ Base/
โ”‚   โ”œโ”€โ”€ Wrapper/
โ”œโ”€โ”€ Resources/
โ”œโ”€โ”€ Services/
โ”œโ”€โ”€ Utils/
โ”œโ”€โ”€ Program.cs / Dockerfile
      

4. Layers & Responsibilities

Layer Responsibility
Configurations Manages application settings efficiently using the Options Pattern, ensuring type safety and reducing the risk of spelling errors or misconfigurations across the codebase.
Constants This is where the application constants and enum exist.
Entities The main entities of the application if we are using one DB instance.
Exceptions This is where we can implement custom exceptions and global handlers.
Extensions Custom implementation of extensions including Mapper, Extension and DI extensions.
Features Encapsulated domain features, Request DTOs, Response DTOs validators, and service calls.
Models Domain entities used across features including aggregates.
Middlewares Custom middlewares for interception and custom logic.
Persistence Generic Repository Pattern, Unit Of Work Pattern lie in this layer. Also, ORM integration can be found there.
Resources We can add localization here.
Services Shared services like Fluent Email, JWT, AES, S3, SES, SNS, etc.
Utils Mainly BaseResponseModel for consistent API response.

5. Testing Strategy

6. Advantages Over CQRS

Traditional CQRS MFCA
Two separate commands and queries Request/Response DTOs under the slice and aggregates under the Core if needed.
Dual databases or projection layers Single DB with layered access
Heavy setup and boilerplate Minimal overhead, fast development

7. Extensibility