DEV Community

Salman Asu
Salman Asu

Posted on

1 1 1 1 1

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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...

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay