CRM Mini

Designing a lightweight CRM system using Domain-Driven Design and CQRS with ASP.NET Core and EF Core.

The CRM Mini project was built to demonstrate how Domain-Driven Design (DDD) and CQRS principles can be applied to build scalable, maintainable business systems in ASP.NET Core.

It focuses on clarity of domain models, separation of concerns, and clean command/query workflows — all while remaining lightweight and developer-friendly.

Objective

To create a Customer Relationship Management (CRM) system that manages clients, contacts, and sales opportunities with a strong emphasis on domain modeling, business rules, and CQRS separation — enabling testability, extensibility, and long-term maintainability.

Architecture Overview

  • Pattern: Domain-Driven Design + CQRS
  • Core Projects:
    • CrmMini.Domain — Entities, Value Objects, Aggregates, Domain Events
    • CrmMini.Application — CQRS handlers (Commands/Queries), validators, and mapping
    • CrmMini.Infrastructure — EF Core persistence, repository, event dispatchers
    • CrmMini.Api — ASP.NET Core Web API endpoints
  • Technology Stack:
    • ASP.NET Core 8 (Minimal APIs)
    • EF Core 8 with SQL Server
    • MediatR for CQRS pattern
    • AutoMapper for DTO mapping
    • FluentValidation for input validation
    • Serilog for structured logging
    • xUnit for testing

Domain Model

  • Entities & Aggregates
    • Customer — root entity with contacts and opportunities.
    • Contact — value object with name, email, phone, role.
    • Opportunity — aggregate with stage, amount, and probability fields.
  • Value Objects
    • Email, PhoneNumber, and Money — ensuring validation and consistency across the domain.
  • Domain Events
    • OpportunityStageChangedEvent, CustomerCreatedEvent, etc. for async notification or integration triggers.
  • Repositories
    • Generic repository abstraction with specification pattern for query flexibility.

CQRS Implementation

  • Commands: CreateCustomer, AddOpportunity, UpdateOpportunityStage, DeleteCustomer.
  • Queries: GetCustomerById, ListCustomers, ListOpportunitiesByStage.
  • Each command/query handled by a MediatR handler, enforcing single responsibility.
  • Handlers orchestrate logic, Domain layer enforces rules, Infrastructure layer persists state.

Core Features

  • Manage customers, contacts, and opportunities
  • Filter and search customers by name, location, and opportunity stage
  • Business rules for opportunity probability calculation
  • Event-driven notifications for important sales actions
  • RESTful API endpoints with OpenAPI (Swagger) documentation
  • Audit logs and soft-delete functionality

Code Quality & Testing

  • Unit Tests for command handlers and domain rules using xUnit + Moq.
  • Integration Tests for repository and persistence layer.
  • Testable architecture — no direct EF Core dependency in business logic.
  • Automated build & test pipeline using GitHub Actions.

Cloud & Deployment

  • Deployed to Azure App Service with Azure SQL Database backend.
  • CI/CD pipeline configured with lint, test, and deploy stages.
  • Application Insights for monitoring domain events and API performance.
  • Azure Key Vault for managing connection strings and secrets.

Outcomes

  • Achieved 100% separation between domain logic and infrastructure code.
  • Demonstrated true CQRS — simplified read/write scaling and testing.
  • Reduced coupling → easier to add new modules like Invoicing or Reports.
  • Clearer business language across code, documentation, and UI.

Key Learnings

  • DDD improves communication with stakeholders when domain models mirror real-world terms.
  • CQRS works best when commands and queries are independently optimized.
  • MediatR keeps the architecture lightweight and scalable without over-engineering.
  • Clear boundaries between Application, Domain, and Infrastructure make the system more maintainable over time.

The CRM Mini project demonstrates that even a small application can reflect enterprise-grade design when built with the right architectural discipline.

It’s a prime example of how Domain-Driven Design + CQRS + Clean Architecture can produce scalable, testable systems that are easy to evolve as business needs grow.

Tech Stack: ASP.NET Core 8 · EF Core 8 · DDD · CQRS · MediatR · Azure