Tech Founder Notes

    Refactor towards Hexagonal Architecture

    Transform your current application into a more testable, maintainable, and scalable system by applying hexagonal architecture principles. Also known as the **Ports and Adapters** pattern, it separates business logic from infrastructure (databases, UI, APIs).

    When to use this prompt

    Legacy monolith refactoring

    Clean architecture introduction

    Domain-driven design alignment

    Preparing for microservice split

    What this prompt allows you to obtain

    Modular structure with isolated business logic

    Clearly defined input/output interfaces

    Testable code with dependency inversion principles

    Architecture ready for evolution and scaling

    Tips and mistakes to avoid

    βœ“Do's

    • β€’Use this prompt iteratively, module by module
    • β€’Add tests after each transformation
    • β€’Respect dependency inversion principles
    • β€’Keep business logic pure and without external dependencies

    βœ—Don'ts

    • β€’Don't refactor everything at once - proceed step by step
    • β€’Avoid mixing business logic and infrastructure

    Prompt Template

    This is the base template with placeholders. Replace the placeholders with your specific information:

    Refactor the following codebase towards a hexagonal (ports and adapters) architecture. Separate business logic from infrastructure (databases, frameworks, APIs), and create clearly defined input/output interfaces. Keep the code testable and modular. {{language_block}} {{framework_block}} {{focus_area_block}} {{additional_details_block}}

    Placeholder descriptions:

    {{language}}Programming language
    {{framework}}Current framework
    {{focus_area}}Refactor focus area
    {{additional_details}}Additional details or constraints (optional) - ex: legacy dependencies, test strategy, naming conventions

    Generated prompt example

    Here's an example with filled-in values:

    Refactor the following codebase towards a hexagonal (ports and adapters) architecture. Separate business logic from infrastructure (databases, frameworks, APIs), and create clearly defined input/output interfaces. Keep the code testable and modular. The framework used is: FastAPI. Focus on: Business logic only. Additional considerations: avoid changing the database schema for now.

    Share this prompt

    Help others discover this useful prompt by sharing it on social media