# andonys24/rule-of-five-cpp architecture

> Architecture diagram of the GitHub repository andonys24/rule-of-five-cpp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andonys24/rule-of-five-cpp
- Repository: https://github.com/andonys24/rule-of-five-cpp

## Overview

##### Project type and purpose
- This is a small C++ “demo” / library project illustrating the Rule of Five via a template class `Matrix<T>`.
- There is one core component (`Matrix`), a driver (`main.cpp`) that exercises copy/move operations, and a CMake build script.

##### File structure
- Top level:
- CMakeLists.txt → build orchestration
- README.md → description
- includes/Matrix.hpp → header-only template class
- src/main.cpp → demo client
- No separate “frontend” or “backend”—it’s a single binary with an embedded library.

##### README for additional insights
- Confirms purpose: showcase five special member functions (ctor copy, op= copy, ctor move, op= move, dtor).
- No external services, no databases, purely in-process memory management.

a. Main components
- Build System (CMake)
- Matrix<T> class (manages dynamic 2D array)
- Dynamic Memory Resource
- Demo Client (main)
b. Relationships / interactions
- CMake → builds `main` binary, compiles `Matrix.hpp` and `main.cpp`
- Demo Client → instantiates `Matrix<int>`, invokes ctor, copy, move, dtor
- `Matrix<T>` → allocates/releases raw memory block (`new[]` / `delete[]`)
c. Architectural patterns / design principles
- RAII (Resource Acquisition Is Initialization)
- Rule of Five enforcing exception safety and correct ownership transfer
- Header-only template providing inline behavior
d. Key technologies
- C++17 (or later)
- CMake for configuration & build
- Standard library (std::exception for out-of-range)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Project Artifacts"
        CMake["CMake"]:::code
        README["README.md"]:::code
    end

    subgraph "Build Output"
        Main["main.exe (Demo Client)"]:::code
    end

    subgraph "Library: Matrix<T>"
        Matrix["Matrix<T>"]:::code
        subgraph "Rule of Five Methods"
            CTOR["Normal ctor()"]:::method
            COPY["Copy ctor()"]:::method
            MOVE["Move ctor()"]:::method
            COPYASSIGN["Copy operator=()"]:::method
            MOVEASSIGN["Move operator=()"]:::method
            DTOR["Destructor ~Matrix()"]:::method
        end
    end

    Memory["Memory Block"]:::resource

    CMake -->|"builds"| Main
    Main -->|"invoke ctor"| CTOR
    Main -->|"invoke copy ctor"| COPY
    Main -->|"invoke move ctor"| MOVE
    Main -->|"invoke copy assign"| COPYASSIGN
    Main -->|"invoke move assign"| MOVEASSIGN
    Main -->|"invoke destructor"| DTOR

    CTOR -->|"allocates"| Memory
    COPY -->|"allocates clone"| Memory
    DTOR -->|"frees"| Memory
    MOVE -.->|"steals pointer"| Memory

    click CMake "https://github.com/andonys24/rule-of-five-cpp/blob/master/CMakeLists.txt"
    click README "https://github.com/andonys24/rule-of-five-cpp/blob/master/README.md"
    click Main "https://github.com/andonys24/rule-of-five-cpp/blob/master/src/main.cpp"
    click Matrix "https://github.com/andonys24/rule-of-five-cpp/blob/master/includes/Matrix.hpp"

    classDef code fill:#cce5ff,stroke:#004085,color:#004085
    classDef resource fill:#d4edda,stroke:#155724,color:#155724
    classDef method fill:#fff3cd,stroke:#856404,color:#856404
```
