knowt logo

clean architecture in 3 minutes

Clean Architecture Overview

  • Clean architecture focuses on structuring an application into logical pieces.

  • Each piece operates independently without needing knowledge of each other.

Key Components

Models

  • Models represent data entities, such as:

    • Database records

    • Incoming requests

    • Outgoing responses

  • Models are the only shared element across the entire application.

Application Layer

  • The core of the architecture where business logic resides.

  • Handles incoming requests from:

    • APIs

    • Socket listeners

    • User-facing interfaces

  • Processes requests by:

    • Hosting features or use cases

    • Each corresponding to user actions (e.g., register, sign in, add to cart)

Features / Use Cases

  • Business logic is segmented into features or use cases.

  • Each feature is essentially an action with its own logic:

    • Examples include user authentication and transactions.

  • Larger actions can invoke smaller actions.

Database Interaction

  • The application layer is abstracted from:

    • Database or repository details

    • Shared services

    • Messaging systems

  • Uses interfaces to define interactions:

    • Example: An email class must include a sendMessage method.

Benefits of Clean Architecture

  • Promotes separation of concerns:

    • Business logic is isolated from API or repository logic.

  • Modularity allows for easy swapping of:

    • Databases

    • Email services

    • Notification handlers

  • Ensures that changes in back-end services do not affect business logic or processing logic.

  • Streamlines processing:

    • Requests are handled consistently, passing through defined paths.

Clean Architecture Overview

  • Clean architecture focuses on structuring an application into logical pieces.

  • Each piece operates independently without needing knowledge of each other.

Key Components

Models

  • Models represent data entities, such as:

    • Database records

    • Incoming requests

    • Outgoing responses

  • Models are the only shared element across the entire application.

Application Layer

  • The core of the architecture where business logic resides.

  • Handles incoming requests from:

    • APIs

    • Socket listeners

    • User-facing interfaces

  • Processes requests by:

    • Hosting features or use cases

    • Each corresponding to user actions (e.g., register, sign in, add to cart)

Features / Use Cases

  • Business logic is segmented into features or use cases.

  • Each feature is essentially an action with its own logic:

    • Examples include user authentication and transactions.

  • Larger actions can invoke smaller actions.

Database Interaction

  • The application layer is abstracted from:

    • Database or repository details

    • Shared services

    • Messaging systems

  • Uses interfaces to define interactions:

    • Example: An email class must include a sendMessage method.

Benefits of Clean Architecture

  • Promotes separation of concerns:

    • Business logic is isolated from API or repository logic.

  • Modularity allows for easy swapping of:

    • Databases

    • Email services

    • Notification handlers

  • Ensures that changes in back-end services do not affect business logic or processing logic.

  • Streamlines processing:

    • Requests are handled consistently, passing through defined paths.