Archetypes

Archetypes

January 2, 2025

In software development, particularly when following clean code and clean architecture principles, we can identify several common module archetypes. These archetypes serve as patterns or templates for organizing code and responsibilities within a system. Here are some key module archetypes:

  1. Entity
  • Represents core business objects
  • Contains business logic and rules
  • Example: Customer, Order, Product
  1. Use Case / Interactor
  • Implements specific business use cases
  • Orchestrates the flow of data between entities and gateways
  • Example: CreateOrder, ProcessPayment
  1. Controller / Presenter
  • Handles input from the user interface or external systems
  • Prepares data for presentation
  • Example: OrderController, UserProfilePresenter
  1. Gateway / Repository
  • Abstracts data access and persistence
  • Provides an interface for interacting with external systems or databases
  • Example: CustomerRepository, PaymentGateway
  1. View / UI Component
  • Responsible for displaying information to the user
  • Handles user interactions
  • Example: OrderListView, ProductDetailsComponent
  1. Data Transfer Object (DTO)
  • Used to transfer data between processes or layers
  • Typically contains no business logic
  • Example: CustomerDTO, OrderSummaryDTO
  1. Factory
  • Creates and configures complex objects or object graphs
  • Example: ReportFactory, DatabaseConnectionFactory
  1. Service
  • Provides stateless operations that don’t naturally belong to entities
  • Often used for cross-cutting concerns
  • Example: EmailService, LoggingService
  1. Adapter
  • Converts interfaces between different systems or modules
  • Example: ThirdPartyPaymentAdapter, LegacySystemAdapter
  1. Validator
  • Ensures data integrity and business rule compliance
  • Example: OrderValidator, UserInputValidator

These archetypes help in organizing code, separating concerns, and maintaining a clean, modular architecture. They provide a common vocabulary for developers and can guide the design of software systems.