Use Case
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."
Related Terms
Clean Architecture
Clean Architecture is like an onion with strict rules: the inner layers (your core business logic) have absolutely no idea the outer layers (databases, API...
CQRS
CQRS says: the way you write data and the way you read data should be separate systems. Writing (commands) goes to one model optimized for transactions.
Domain Model
A domain model is a code representation of your real-world business.
Interactor
An interactor is just another name for a use case — it's the code that 'interacts' with your domain to accomplish one specific task.