Bird
Raised Fist0
LLDsystem_design~5 mins

Clean Architecture layers in LLD - Cheat Sheet & Quick Revision

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of the Entities layer in Clean Architecture?
The Entities layer contains the core business rules and data. It represents the most general and high-level business objects that are independent of any external systems or frameworks.
Click to reveal answer
beginner
Which layer in Clean Architecture acts as a bridge between the Entities and external systems?
The Use Cases (or Interactors) layer acts as a bridge. It contains application-specific business rules and orchestrates the flow of data to and from the Entities layer and external layers.
Click to reveal answer
intermediate
What role does the Interface Adapters layer play in Clean Architecture?
The Interface Adapters layer converts data from the format most convenient for the Use Cases and Entities layers to the format used by external agencies like databases, web, or UI frameworks.
Click to reveal answer
intermediate
Why should dependencies in Clean Architecture always point inward?
Dependencies point inward to ensure that inner layers (Entities, Use Cases) do not depend on outer layers (UI, databases). This keeps business rules independent and reusable.
Click to reveal answer
beginner
Name the four main layers of Clean Architecture from innermost to outermost.
From innermost to outermost: Entities, Use Cases (Interactors), Interface Adapters, Frameworks & Drivers (e.g., UI, Database).
Click to reveal answer
Which layer contains the core business logic in Clean Architecture?
AEntities
BInterface Adapters
CFrameworks & Drivers
DUse Cases
In Clean Architecture, which layer is responsible for converting data formats between layers?
AEntities
BFrameworks & Drivers
CUse Cases
DInterface Adapters
Why do dependencies point inward in Clean Architecture?
ATo keep business rules independent of external systems
BTo make databases depend on UI
CTo allow UI to control business rules
DTo simplify outer layers
Which layer typically contains controllers, gateways, and presenters?
AEntities
BUse Cases
CInterface Adapters
DFrameworks & Drivers
What is the outermost layer in Clean Architecture?
AUse Cases
BFrameworks & Drivers
CInterface Adapters
DEntities
Explain the role and responsibilities of each Clean Architecture layer.
Think of layers as rings around the core business logic, each with a specific job.
You got /4 concepts.
    Describe why the dependency rule (dependencies point inward) is important in Clean Architecture.
    Imagine the core business logic as a safe that should not be affected by outside changes.
    You got /4 concepts.

      Practice

      (1/5)
      1. Which layer in Clean Architecture contains the core business rules and logic?
      easy
      A. UI layer
      B. Entities layer
      C. Database layer
      D. Frameworks layer

      Solution

      1. Step 1: Understand the role of each layer

        The Entities layer holds the core business rules and logic, independent of external concerns.
      2. Step 2: Identify the correct layer for business logic

        UI, Database, and Frameworks layers handle external interactions, not core logic.
      3. Final Answer:

        Entities layer -> Option B
      4. Quick Check:

        Business logic = Entities layer [OK]
      Hint: Core logic always lives in the Entities layer [OK]
      Common Mistakes:
      • Confusing UI layer with business logic
      • Thinking database layer contains core rules
      • Mixing frameworks with core logic
      2. In Clean Architecture, which layer is responsible for adapting data from the database to the business logic?
      easy
      A. Entities layer
      B. Use Cases (Interactor) layer
      C. UI layer
      D. Interface Adapters layer

      Solution

      1. Step 1: Identify the role of Interface Adapters

        Interface Adapters convert data from external sources like databases into a form usable by inner layers.
      2. Step 2: Confirm other layers' roles

        Entities hold business rules, Use Cases orchestrate logic, UI handles presentation, so adapting data fits Interface Adapters.
      3. Final Answer:

        Interface Adapters layer -> Option D
      4. Quick Check:

        Data adaptation = Interface Adapters [OK]
      Hint: Data conversion happens in Interface Adapters [OK]
      Common Mistakes:
      • Choosing Entities layer for data adaptation
      • Confusing Use Cases with data conversion
      • Selecting UI layer for database data handling
      3. Given the following flow in Clean Architecture: UI calls Use Cases, which then call Entities. What is the correct order of dependency direction?
      medium
      A. UI -> Entities -> Use Cases
      B. Entities -> Use Cases -> UI
      C. UI -> Use Cases -> Entities
      D. Use Cases -> UI -> Entities

      Solution

      1. Step 1: Understand dependency rule in Clean Architecture

        Dependencies always point inward, from outer layers to inner layers.
      2. Step 2: Apply to given flow

        UI depends on Use Cases, which depend on Entities, so direction is UI -> Use Cases -> Entities.
      3. Final Answer:

        UI -> Use Cases -> Entities -> Option C
      4. Quick Check:

        Dependency direction = UI to Entities [OK]
      Hint: Dependencies always point inward [OK]
      Common Mistakes:
      • Reversing dependency direction
      • Confusing which layer calls which
      • Assuming Entities depend on UI
      4. A developer placed database access code directly inside the Entities layer. What is the main problem with this design?
      medium
      A. Entities layer should not depend on external frameworks or databases
      B. Entities layer must handle UI rendering
      C. Database code belongs only in the UI layer
      D. Entities layer should only contain database schemas

      Solution

      1. Step 1: Recall Clean Architecture dependency rules

        Inner layers like Entities must be independent of external concerns like databases.
      2. Step 2: Identify why database code in Entities is wrong

        It creates tight coupling and breaks separation of concerns.
      3. Final Answer:

        Entities layer should not depend on external frameworks or databases -> Option A
      4. Quick Check:

        Entities layer independence = true [OK]
      Hint: Keep Entities free from external dependencies [OK]
      Common Mistakes:
      • Thinking Entities handle UI
      • Placing database code in UI layer
      • Confusing database schemas with business logic
      5. You need to design a system where the UI can be changed without affecting business rules, and the database can be swapped easily. Which Clean Architecture principle helps achieve this?
      hard
      A. Dependency Rule: Inner layers do not depend on outer layers
      B. UI layer directly accesses Entities for faster updates
      C. Database layer contains business logic for flexibility
      D. Use Cases layer handles UI rendering and database access

      Solution

      1. Step 1: Identify the principle for independence

        The Dependency Rule states inner layers (business rules) do not depend on outer layers (UI, database).
      2. Step 2: Explain how this helps system flexibility

        This separation allows changing UI or database without impacting core business logic.
      3. Final Answer:

        Dependency Rule: Inner layers do not depend on outer layers -> Option A
      4. Quick Check:

        Dependency Rule ensures flexibility [OK]
      Hint: Inner layers must be independent for easy changes [OK]
      Common Mistakes:
      • Allowing UI to access Entities directly
      • Putting business logic in database layer
      • Mixing UI rendering with Use Cases