dev-resources.site
for different kinds of informations.
comparing Domain-Driven Design (DDD) and Clean Architecture
main difference between domain-driven design and clean architecture is we are seperating business login, infrastructure and presentation layer for individual module
in domain-driven design(DDD).
where seperating business login, infrastructure and presentation layer onces for all module
in clean architecture.
Hereβs a simplified folder structure comparing Domain-Driven Design (DDD) and Clean Architecture, ensuring clarity and scalability while reducing unnecessary depth.
let take an example for creating folder structure for user and blog module...
Domain-Driven Design (DDD)
src/
βββ modules/ # Feature-based modules
β βββ user/ # User module
β β βββ application/ # Use cases (business logic)
β β β βββ create-user.usecase.ts
β β β βββ update-user.usecase.ts
β β βββ domain/ # Core business logic
β β β βββ user.entity.ts
β β β βββ user.repository.ts
β β β βββ user.validator.ts
β β βββ infrastructure/ # Data access and persistence
β β β βββ user.repository.impl.ts
β β β βββ prisma.service.ts
β β βββ interfaces/ # Controllers, APIs, and DTOs
β β β βββ user.controller.ts
β β β βββ create-user.dto.ts
β β β βββ update-user.dto.ts
β β βββ user.module.ts # Module setup
β βββ blog/ # Blog module
β β βββ application/
β β βββ domain/
β β βββ infrastructure/
β β βββ interfaces/
β β βββ blog.module.ts
βββ shared/ # Shared utilities and services
β βββ exceptions/
β β βββ custom-error.ts
β βββ utils/
β β βββ logger.service.ts
βββ main.ts # Entry point
βββ app.module.ts # Root application module
Clean Architecture
src/
βββ core/ # Core application logic
β βββ usecases/ # Application use cases
β β βββ create-user.usecase.ts
β β βββ update-user.usecase.ts
β β βββ create-blog.usecase.ts
β β βββ update-blog.usecase.ts
β βββ entities/ # Domain models/entities
β β βββ user.entity.ts
β β βββ blog.entity.ts
β β βββ index.ts
β βββ repositories/ # Repository interfaces
β β βββ user.repository.ts
β β βββ blog.repository.ts
β β βββ index.ts
β βββ validators/ # Domain-level validations
β βββ user.validator.ts
β βββ blog.validator.ts
β βββ index.ts
βββ adapters/ # Adapters for data and frameworks
β βββ database/ # Database layer
β β βββ prisma/
β β β βββ schema.prisma
β β β βββ prisma.service.ts
β β β βββ user.repository.impl.ts
β β βββ blog.repository.impl.ts
β βββ controllers/ # Controllers (API endpoints)
β βββ user.controller.ts
β βββ blog.controller.ts
β βββ index.ts
βββ config/ # Configuration files
β βββ app.config.ts
βββ shared/ # Shared utilities
β βββ exceptions/
β β βββ custom-error.ts
β βββ utils/
β β βββ logger.service.ts
β βββ index.ts
βββ main.ts # Entry point
βββ app.module.ts # Root application module
Choose DDD if the application is domain-complex and feature-based, or Clean Architecture if you want to prioritize clear separation of layers. Let me know which one resonates!
want to know more about me, just write sallbro on search engine...
Featured ones: