Implementing 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 : 1. **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). 2. **Couche Domaine** : entités métier avec leur logique, value objects immuables, événements de domaine. Pas de dépendance vers les frameworks. 3. **Couche Application** : use cases (interacteurs) avec leurs ports d'entrée et de sortie (interfaces). Orchestration de la logique sans couplage à l'infrastructure. 4. **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). 5. **Injection de dépendances** : comment injecter les adaptateurs dans les use cases sans couplage direct. 6. **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). 7. **Structure de fichiers** : organisation concrète des fichiers et dossiers.
Why this prompt works
<p>This prompt tackles the main challenge of Clean Architecture: moving from theoretical concepts to concrete implementation. By asking for 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 fake in-memory repositories, making unit tests instantaneous and without external dependencies. This is the most convincing argument for skeptical teams.</p><p>The request for 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 content.</p>
Use Cases
Expected Output
Complete Clean Architecture implementation with code by layer, interfaces (ports), adapters, dependency injection and unit tests.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt GuideGlossary Terms
Similar Prompts
Learn the basics of Git for beginners
Learn Git from scratch with illustrated explanations, concrete examples, a practical workflow and a cheatsheet of essential commands.
Implement robust error handling in Node.js
Create a professional Node.js error handling architecture with custom error classes, centralized middleware and monitoring.
Define a Git strategy for a team
Define a comprehensive Git strategy adapted to your team: branching model, conventions, code review and release management.
Write integration tests for an API
Create comprehensive API integration tests with database setup, authentication, CRUD and end-to-end scenarios.