# nahidulhasan/solid-principles architecture

> Architecture diagram of the GitHub repository nahidulhasan/solid-principles, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nahidulhasan/solid-principles
- Repository: https://github.com/nahidulhasan/solid-principles

## Overview

This project is a repository composed of a series of examples that demonstrate the SOLID principles with a clear “good design vs. bad design” comparison for each principle. In other words, it isn’t a full-fledged enterprise application but rather an educational resource or reference implementation aimed at explaining how to correctly (and incorrectly) apply each SOLID principle in PHP.

##### Main Components
– Single Responsibility Principle (SRP)
– Open-Closed Principle (OCP)
– Liskov Substitution Principle (LSP)
– Interface Segregation Principle (ISP)
– Dependency Inversion Principle (DIP)
- Within several of these, the design is split between “GoodDesign” and “BadDesign” examples. Represent these as subcomponents or branches where applicable.

##### File Structure as Architectural Modules
- For Single Responsibility Principle:
– Show two distinct modules: one for “BadDesign” (which contains code that combines responsibilities), and one for “GoodDesign” (which refactors responsibilities into separate classes, plus a repository component).
- For Open-Closed Principle:
– Create a module with branches for “BadDesign” and “GoodDesign”.
- For Interface Segregation Principle:
- For Liskov Substitution Principle:
– Represent this module with its multiple example files that demonstrate correct and sometimes incorrect subtype behavior.
- For Dependency Inversion Principle:
– Exhibit a module that highlights the move from tightly coupled dependencies (e.g., instantiating a MySQLConnection directly) to working with an abstraction (a ConnectionInterface).

– Show how the “OrdersReport” component in SRP interacts with both the “OrdersRepository” (for data access) and the output formatter (for presentation), highlighting the decoupling achieved.
– In OCP, show how the CostManager depends on the abstraction (AreaInterface) rather than concrete implementations.
- If appropriate, include connections between good and bad design modules to emphasize improvements from violating to adhering to a principle.

##### Architectural Patterns and Design Principles
- Separation of concerns evident in the “GoodDesign” versions.
- Use of interfaces in both the Open-Closed and Dependency Inversion examples.
- Strategy of splitting responsibilities (for SRP) and segregating interfaces (for ISP).

##### Technologies and Concepts
- You may also annotate that the repository is structured to illustrate the SOLID principles as a set of best practices rather than an integrated full-stack system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Single Responsibility Principle (SRP)
    subgraph "Single Responsibility Principle (SRP)"
        subgraph "BadDesign"
            SRP_BadOrdersReport["OrdersReport (BadDesign)"]:::bad
        end
        subgraph "GoodDesign"
            SRP_GoodOrdersReport["OrdersReport (GoodDesign)"]:::good
            HtmlOutput["HtmlOutput (GoodDesign)"]:::good
            OrdersOutPutInterface["OrdersOutPutInterface (GoodDesign)"]:::good
            OrdersRepository["OrdersRepository (GoodDesign)"]:::good
        end
        SRP_GoodOrdersReport -->|"uses"| OrdersRepository
        SRP_GoodOrdersReport -->|"formats"| HtmlOutput
    end

    %% Open-Closed Principle (OCP)
    subgraph "Open-Closed Principle (OCP)"
        subgraph "BadDesign"
            OCP_BadCircle["Circle (BadDesign)"]:::bad
            OCP_BadRectangle["Rectangle (BadDesign)"]:::bad
            OCP_BadCostManager["CostManager (BadDesign)"]:::bad
        end
        subgraph "GoodDesign"
            OCP_GoodAreaInterface["AreaInterface (GoodDesign)"]:::good
            OCP_GoodCircle["Circle (GoodDesign)"]:::good
            OCP_GoodRectangle["Rectangle (GoodDesign)"]:::good
            OCP_GoodCostManager["CostManager (GoodDesign)"]:::good
        end
        OCP_BadCostManager -->|"calls"| OCP_BadCircle
        OCP_BadCostManager -->|"calls"| OCP_BadRectangle
        OCP_GoodCostManager -->|"uses"| OCP_GoodAreaInterface
    end

    %% Liskov Substitution Principle (LSP)
    subgraph "Liskov Substitution Principle (LSP)"
        LSP_Example1["Example1"]:::module
        LSP_Example2["Example2"]:::module
        LSP_Example3["Example3"]:::module
        LSP_Example1 -->|"substitutes"| LSP_Example2
        LSP_Example2 -->|"enhances"| LSP_Example3
    end

    %% Interface Segregation Principle (ISP)
    subgraph "Interface Segregation Principle (ISP)"
        ISP_BadExample["Monolithic workerInterface (BadDesign)"]:::bad
        ISP_GoodExample["Split Interfaces (GoodDesign)"]:::good
        ISP_BadExample -->|"refactoredTo"| ISP_GoodExample
    end

    %% Dependency Inversion Principle (DIP)
    subgraph "Dependency Inversion Principle (DIP)"
        DIP_Bad["MySQLConnection (TightlyCoupled)"]:::bad
        DIP_Good["ConnectionInterface (Abstraction)"]:::good
        DIP_Good -->|"decouples"| DIP_Bad
    end

    %% Click Events for SRP
    click SRP_BadOrdersReport "https://github.com/nahidulhasan/solid-principles/blob/master/SingleResponsiblityPrinciple/BadDesign/OrdersReport.php"
    click SRP_GoodOrdersReport "https://github.com/nahidulhasan/solid-principles/blob/master/SingleResponsiblityPrinciple/GoodDesign/OrdersReport.php"
    click HtmlOutput "https://github.com/nahidulhasan/solid-principles/blob/master/SingleResponsiblityPrinciple/GoodDesign/HtmlOutput.php"
    click OrdersOutPutInterface "https://github.com/nahidulhasan/solid-principles/blob/master/SingleResponsiblityPrinciple/GoodDesign/OrdersOutPutInterface.php"
    click OrdersRepository "https://github.com/nahidulhasan/solid-principles/blob/master/SingleResponsiblityPrinciple/GoodDesign/Repositories/OrdersRepository.php"

    %% Click Events for OCP BadDesign
    click OCP_BadCircle "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/BadDesign/Circle.php"
    click OCP_BadRectangle "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/BadDesign/Rectangle.php"
    click OCP_BadCostManager "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/BadDesign/CostManager.php"
  
    %% Click Events for OCP GoodDesign
    click OCP_GoodAreaInterface "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/GoodDesign/AreaInterface.php"
    click OCP_GoodCircle "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/GoodDesign/Circle.php"
    click OCP_GoodRectangle "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/GoodDesign/Rectangle.php"
    click OCP_GoodCostManager "https://github.com/nahidulhasan/solid-principles/blob/master/OpenClosedPrinciple/GoodDesign/CostManager.php"

    %% Click Events for LSP
    click LSP_Example3 "https://github.com/nahidulhasan/solid-principles/blob/master/LiskovSubstitutionPrinciple/LiskobSubstituitionExample3.php"
    click LSP_Example2 "https://github.com/nahidulhasan/solid-principles/blob/master/LiskovSubstitutionPrinciple/LiskovSubstitutionExample2.php"
    click LSP_Example1 "https://github.com/nahidulhasan/solid-principles/blob/master/LiskovSubstitutionPrinciple/LiskovSubstitutonExample1.php"

    %% Click Events for ISP
    click ISP_BadExample "https://github.com/nahidulhasan/solid-principles/blob/master/InterfaceSegregationPrinciple/BadDesign/InterfaceSegregationViolateExample.php"
    click ISP_GoodExample "https://github.com/nahidulhasan/solid-principles/blob/master/InterfaceSegregationPrinciple/GoodDesign/InterfaceSegregationExample.php"

    %% Click Events for DIP
    click DIP_Good "https://github.com/nahidulhasan/solid-principles/blob/master/DependencyInversionPrinciple/DependencyInversionExample.php"
    click DIP_Bad "https://github.com/nahidulhasan/solid-principles/blob/master/DependencyInversionPrinciple/DependencyInversionViolation.php"

    %% Class Definitions for styling
    classDef good fill:#C6E2FF,stroke:#1E90FF,stroke-width:2px;
    classDef bad fill:#FFC0CB,stroke:#FF6347,stroke-width:2px;
    classDef module fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
```
