Skip to content

Use Case

Medium — good to knowArchitecture

ELI5 — The Vibe Check

A use case is a single thing a user can do with your system — 'Place Order', 'Register Account', 'Cancel Subscription.' Each one is a self-contained piece of business logic that tells the story of one user interaction.

Real Talk

In Clean Architecture, a use case (or interactor) encapsulates a specific application business rule, orchestrating the flow of data between entities and the outside world. Use cases define the application's behavior independently of UI, database, or framework, taking input through a request model and returning output through a response model.

Show Me The Code

class PlaceOrderUseCase {
  constructor(
    private orderRepo: OrderRepository,
    private paymentGateway: PaymentGateway
  ) {}

  async execute(input: PlaceOrderInput): Promise<PlaceOrderOutput> {
    const order = Order.create(input.items);
    await this.paymentGateway.charge(order.total);
    await this.orderRepo.save(order);
    return { orderId: order.id };
  }
}

When You'll Hear This

"Each use case has one job — PlaceOrder doesn't also send emails; that's a different use case or event handler." / "Use cases are the most important layer — they define what your application actually does."

Made with passive-aggressive love by manoga.digital. Powered by Claude.