Overview
Clean Architecture is an architectural pattern that emphasizes separation of concerns, independence of frameworks, and testability. Intent Architect provides comprehensive support for Clean Architecture through its modular system, generating code that naturally follows these principles.Key Benefits
- Separation of Concerns: Clear boundaries between business logic and infrastructure
- Framework Independence: Core business logic doesn’t depend on external frameworks
- Testability: Business logic can be tested without UI, database, or external dependencies
- Maintainability: Changes in one layer don’t cascade to others
The Layers
Intent Architect organizes your application into distinct layers, each with specific responsibilities:Domain Layer
The innermost layer containing business logic and domain entities. Generated Artifacts:- Domain entities (via
Intent.Entitiesmodule) - Value objects (via
Intent.ValueObjectsmodule) - Domain events (via
Intent.DomainEventsmodule) - Domain services (via
Intent.DomainServicesmodule)
- No dependencies on other layers
- Contains business rules and invariants
- Framework-agnostic
Application Layer
Orchestrates the flow of data and coordinates domain objects to perform use cases. Generated Artifacts:- Command/Query handlers (via
Intent.Application.MediatRmodule) - Application services (via
Intent.Application.ServiceImplementationsmodule) - DTOs (via
Intent.Application.Dtosmodule) - Validation logic (via
Intent.Application.FluentValidationmodule) - Repository interfaces (via
Intent.Entities.Repositories.Apimodule)
- Depends only on the Domain layer
- Defines repository interfaces (not implementations)
- Contains application-specific business rules
- Orchestrates use cases
Infrastructure Layer
Implements interfaces defined in the Application layer and provides access to external concerns. Generated Artifacts:- Repository implementations (via
Intent.EntityFrameworkCore.Repositoriesmodule) - DbContext and configurations (via
Intent.EntityFrameworkCoremodule) - External service integrations (via
Intent.Integration.HttpClientsmodule) - Message bus implementations (via
Intent.Eventing.*modules)
- Depends on Application and Domain layers
- Contains framework-specific code
- Implements data access and external integrations
- Plugin architecture for different technologies
Presentation Layer
Handles external requests and presents data to users or external systems. Generated Artifacts:- REST API controllers (via
Intent.AspNetCore.Controllersmodule) - GraphQL endpoints (via
Intent.HotChocolate.GraphQLmodule) - gRPC services (via
Intent.AspNetCore.Grpcmodule) - Blazor components (via
Intent.Blazormodule)
- Depends on Application layer
- Handles HTTP requests/responses
- Dispatches to application layer handlers
- Manages authentication and authorization
Dependency Flow
In Clean Architecture, dependencies point inward toward the domain:The Dependency Rule: Source code dependencies must point only inward, toward higher-level policies. The Domain layer has no dependencies, while outer layers depend on inner layers.
Project Structure
Intent Architect typically generates the following project structure:Module Configuration
Essential Modules for Clean Architecture
Domain Layer
Intent.EntitiesIntent.ValueObjectsIntent.DomainEventsIntent.DomainServices
Application Layer
Intent.Application.MediatRIntent.Application.DtosIntent.Application.FluentValidationIntent.Entities.Repositories.Api
Infrastructure Layer
Intent.EntityFrameworkCoreIntent.EntityFrameworkCore.RepositoriesIntent.Infrastructure.DependencyInjection
Presentation Layer
Intent.AspNetCore.ControllersIntent.AspNetCore.Controllers.Dispatch.MediatRIntent.AspNetCore
Best Practices
Keep the Domain Pure
Keep the Domain Pure
The Domain layer should have no dependencies on infrastructure concerns:
- No ORM attributes on entities
- No HTTP/API concerns
- No framework-specific code
- Only business logic and domain rules
Define Interfaces in Application Layer
Define Interfaces in Application Layer
Repository and service interfaces belong in the Application layer:
- Application layer defines the contract
- Infrastructure layer provides the implementation
- Enables testing with mocks/stubs
- Maintains dependency inversion
Use DTOs for Data Transfer
Use DTOs for Data Transfer
Never expose domain entities directly through APIs:
- Map entities to DTOs using AutoMapper or Mapperly
- DTOs can have different structures than entities
- Protects domain model from API changes
- Prevents over-posting vulnerabilities
Leverage Intent Architect's Code Management
Leverage Intent Architect's Code Management
Take advantage of Intent’s merge strategies:
- Business logic methods use
Mode.Mergefor manual control - Infrastructure code uses
Mode.Fullyfor full automation - Customize behavior through decorators and extensions
Testing Strategy
Unit Testing Domain Logic
Integration Testing Application Layer
Related Patterns
CQRS
Command Query Responsibility Segregation
DDD
Domain-Driven Design principles
Repository
Data access abstraction
