P
💻DeveloppementAdvancedClaude

Implement Clean Architecture in Practice

Implement Clean Architecture in practice with layers, ports and adapters, use cases, and unit tests without infrastructure.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Help me restructure my application so its business rules are easier to change and test. Use Clean Architecture, ports and adapters, and domain-driven design where they fit.

My application: [e.g., an e-commerce order API, a blogging platform or a booking system]
Stack: [e.g., Node.js with TypeScript, Python or Java with Spring]
Current problems: [e.g., business rules mixed into database code, hard-to-test logic or tight coupling]
Use cases to implement: [e.g., place an order, cancel an order or email a customer]

Show how one of my use cases runs through the code, and implement the use cases I've listed.

  1. Map the domain, application, infrastructure and presentation layers. Show where each dependency points and explain the rule that source-code dependencies point inward.
  2. Implement the domain entities and their business logic, immutable value objects and domain events. Keep framework dependencies outside the domain.
  3. Write the application use cases (interactors) with input and output ports. Show how they coordinate the domain logic without depending on infrastructure.
  4. Define the port interfaces in the domain or application layer. Show the adapters that connect them to the outside world, such as a PostgreSQL repository, a SendGrid email service and an HTTP controller.
  5. Wire the adapters into the use cases with dependency injection so the use cases can run with different implementations.
  6. Unit-test the use cases with an in-memory fake repository.
  7. Show the actual file and directory layout so I can see where each piece belongs.

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt tackles the main challenge of Clean Architecture: going from theoretical concepts to a concrete implementation. By requesting complete implementation for specific use cases (rather than an abstract explanation), the prompt forces the AI to produce real and applicable code. The testing section is the main justification for adopting Clean Architecture: use cases completely decoupled from infrastructure can be tested with in-memory fake repositories, making unit tests instant and free of external dependencies. This is the most convincing argument for skeptical teams. Requesting a concrete file structure is often omitted in Clean Architecture explanations, but it's precisely what teams need to get started: an example of folders (domain/, application/, infrastructure/, presentation/) with their respective contents.

Use Cases

Refactoring toward clean architectureClean Architecture trainingDesigning new maintainable projects

Expected Output

Complete Clean Architecture implementation with code by layer, interfaces (ports), adapters, dependency injection, and unit tests.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

Task brief for Claude Code: frame a feature end to end

Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.

1679
💻DeveloppementIntermediateClaude

Write a project's CLAUDE.md: the brief Claude Code reads at every session

Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.

639
💻DeveloppementAdvancedAll AIs

Design a Secure Webhook API

Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.

411
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

473