DEV Community

Siddharth Bhamare
Siddharth Bhamare

Posted on • Edited on

πŸš€ Day 3: Architectures Explained with My Implementation

(DDD + Clean + Onion + Microservices)

Many times in interviews, questions come like:
πŸ‘‰ β€œWhat’s the difference between DDD, Clean, and Onion Architecture?”
πŸ‘‰ β€œHow do you apply them in a real project?”
πŸ‘‰ β€œWhy Microservices over Monolith?”

Today, I’ll simplify these with my Catalog Service example (Products, Categories, Brands).


1️⃣ Domain-Driven Design (DDD)

What it is:

  • Focuses on the Domain Model (business rules, not just CRUD).
  • Uses Entities, Value Objects, Repositories, Aggregates, Aggregate Roots.
  • Communication happens via Ubiquitous Language (same words as business).

Layers in DDD:

  • Domain Layer (Inner) β†’ Entities (Product, Category), Interfaces (IProductRepository).
  • Application Layer (Middle) β†’ Services (ProductService orchestrating use cases).
  • Infrastructure Layer (Outer) β†’ EF Core, DB, external APIs.

My Example:

  • Product is an Aggregate Root.
  • IProductRepository ensures access through the domain contract.
  • EfRepository<Product> (Infra) implements IProductRepository.
  • Application Layer (ProductService) coordinates actions like β€œAdd Product to Category.”

πŸ‘‰ Interview Tip: DDD ensures business-first design, avoids anemic models.


2️⃣ Clean Architecture

What it is:

  • Robert C. Martin (Uncle Bob) β†’ emphasis on independence of frameworks, UI, DB.
  • Dependency Rule: All dependencies point inward, towards the Domain.

Layers (from inner to outer):

  • Entities (Domain) β†’ Business rules.
  • Use Cases (Application) β†’ Application-specific business logic.
  • Interface Adapters β†’ Controllers, Presenters, DTOs.
  • Frameworks & Drivers (Outer) β†’ EF Core, ASP.NET Core, DB, external systems.

My Example:

  • Entities: Product, Category, Brand.
  • Use Cases: ProductService, CategoryService.
  • Interface Adapters: ASP.NET Core Controllers (ProductController).
  • Frameworks/Drivers: CatalogDbContext, EF Core repositories.

πŸ‘‰ Interview Tip: Clean Architecture is technology-agnostic β†’ I can switch from EF Core to Dapper without touching Domain/Application.


3️⃣ Onion Architecture

What it is:

  • Similar to Clean, but visually represented as onion rings.
  • Inner Core = Domain, outer layers depend on inner.

Layers (from core out):

  1. Core (Domain) β†’ Entities (Product, Category), Interfaces (IRepository<T>).
  2. Application Layer β†’ Services (ProductService).
  3. Infrastructure Layer β†’ Repositories (EfRepository<Product>).
  4. Presentation Layer β†’ API Controllers.

My Example:

  • Inner Onion Ring = Product + IProductRepository.
  • Middle = ProductService.
  • Outer = EfRepository<Product> + ProductController.

πŸ‘‰ Interview Tip: Onion vs Clean = philosophy is same (dependency direction). Onion is more visual metaphor, Clean is more principle-driven.


4️⃣ Microservices

What it is:

  • Break monolith into independent services around business capabilities.
  • Each service has its own DB + bounded context.

My Example:

  • Catalog Service = Products, Categories, Brands.
  • Future Order Service = Orders, Payments.
  • Communication β†’ REST / gRPC / Messaging (RabbitMQ, Kafka).
  • Independent DBs β†’ CatalogDB, OrderDB.

πŸ‘‰ Interview Tip: Microservices solve scaling + team autonomy, but add complexity (distributed systems).


🎯 How They All Connect in My Project

  • DDD β†’ defines my Domain & Repositories.
  • Clean Architecture β†’ ensures dependency flow is inward.
  • Onion Architecture β†’ shows layered structure visually.
  • Microservices β†’ breaks Catalog, Order, Auth into separate deployable units.

βœ… So when interviewers ask β€œWhich architecture are you following?” β†’ My answer:

β€œI use a combination of DDD for domain modeling, Onion/Clean for dependency flow, and Microservices for scalability and independence. For example, in my Catalog Service, Product is an Aggregate Root in the Domain Layer, EfRepository<Product> sits in Infrastructure, ProductService in Application, and ASP.NET Controllers in the Presentation Layer. This separation ensures testability, maintainability, and future scalability.”

πŸ“Œ GitHub repo https://github.com/SiddharthBhamare/SmartKart-Catalog.git

Stay tuned! πŸš€

dotnet #architecture #ddd #cleanarchitecture #microservices #onionarchitecture #softwareengineering

Top comments (0)