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
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.
- Map the domain, application, infrastructure and presentation layers. Show where each dependency points and explain the rule that source-code dependencies point inward.
- Implement the domain entities and their business logic, immutable value objects and domain events. Keep framework dependencies outside the domain.
- Write the application use cases (interactors) with input and output ports. Show how they coordinate the domain logic without depending on infrastructure.
- 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.
- Wire the adapters into the use cases with dependency injection so the use cases can run with different implementations.
- Unit-test the use cases with an in-memory fake repository.
- 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
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 OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Improve this prompt with the Optimizer
Analyze the prompt, strengthen the context and get a more precise version.
Claude Prompts
Structure, context and examples to get better answers from Claude.
AI prompts for web developers
Code review and debugging, keeping API keys and secrets out of the prompt.
Security, GDPR & Business Plans
ChatGPT Business, Claude Team, Gemini Workspace and Mistral Vibe compared from vendor sources: training, EU hosting and a GDPR checklist.
Similar Prompts
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.
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.
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.
Generate Storybook Stories for UI Components
Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.