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.
Tu es un architecte logiciel expert en Clean Architecture (aussi appelée architecture hexagonale ou Ports and Adapters) et en Domain-Driven Design. Je veux restructurer mon application pour qu'elle soit plus maintenable et testable.
Application actuelle :
- Description : [EX: API de gestion de commandes e-commerce, plateforme de blog, système de réservation]
- Stack : [EX: Node.js/TypeScript, Python, Java Spring]
- Problèmes actuels : [EX: logique métier mélangée avec la base de données, difficile à tester, fort couplage]
Cas d'usage à implémenter :
[EX: Créer une commande, Annuler une commande, Notifier le client par email]
Implémente la Clean Architecture complète :
-
Structure des couches : explique les quatre couches (Domaine, Application, Infrastructure, Présentation) et leurs règles de dépendance (la règle de dépendance vers l'intérieur).
-
Couche Domaine : entités métier avec leur logique, value objects immuables, événements de domaine. Pas de dépendance vers les frameworks.
-
Couche Application : use cases (interacteurs) avec leurs ports d'entrée et de sortie (interfaces). Orchestration de la logique sans couplage à l'infrastructure.
-
Ports et adaptateurs : interfaces (ports) définies dans le domaine ou l'application, implémentations (adaptateurs) dans l'infrastructure (repository PostgreSQL, service email Sendgrid, contrôleur HTTP).
-
Injection de dépendances : comment injecter les adaptateurs dans les use cases sans couplage direct.
-
Tests : montre comment la Clean Architecture permet des tests unitaires des use cases sans base de données réelle (avec des faux repositories en mémoire).
-
Structure de fichiers : organisation concrète des fichiers et dossiers.
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>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.</p><p>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.</p><p>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.</p>
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
- LéaAI
Assurez-vous que vos use cases de la couche Application ne reçoivent que des interfaces (ports) en paramètre de constructeur. Testez-les avec des implémentations factices (in-memory) des repositories et services externes, sans jamais toucher aux adaptateurs réels. Cela vérifie la logique métier en isolation.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Set up dependency vulnerability scanning
Automate dependency scanning
Gemini Prompt to Create a REST API
Creating a REST API is a fundamental skill in modern development, but it involves many architectural decisions: choice of framework, endpoint structure, authentication management, data validation, and documentation. Google Gemini excels at generating structured code and can guide you through each step of this process. Using a well-crafted prompt, you not only get the skeleton of your API but also best practices built in from the start: proper HTTP codes, centralized error handling, security middleware, and layered architecture. Whether you're building a microservice for a personal project or an enterprise API designed to handle thousands of requests, Gemini adapts its response to the requested complexity level. The main benefit is time savings during the scaffolding phase: instead of spending hours manually configuring each component, you get a solid, coherent foundation in seconds, which you can then customize to your specific business needs.
Automatically Generate Unit Tests with AI
Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.
Migrating from JavaScript to TypeScript
Gradually migrating a codebase to TypeScript