# davmakar/command_parser architecture

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

- Interactive diagram: https://gitdiagram.com/davmakar/command_parser
- Repository: https://github.com/davmakar/command_parser

## Overview

##### Main Components
- CLI Layer:
- Contains the core command handling logic, including a registry and various command implementations (e.g., AddCommand, ChangeItemCommand, CreateSlideCommand, etc.).
- This component is responsible for parsing user inputs and triggering the corresponding actions.
- Director / Controller Layer:
- Includes the “director” folder, which handles high-level actions (such as maintaining an action history and managing actions like AddItemAction, CreateSlideAction, etc).
- Acts as the orchestration layer between user commands and the underlying document state.
- Document Model:
- Represented by the “document” folder.
- Contains the core data structures for slides and items. Elements such as BoundingBox, Point, and text/pen attributes form the backbone of the presentation's data.
- GUI Layer:
- Found under the “gui” folder. It contains components for the main window, user input handling, and various subviews (like the slide view, command log, toolbars, etc).
- Implements the visual representation of the presentation and interacts with user operations.
- Rendering Subsystem:
- This layer converts document data into graphical elements that the GUI displays.
- Serialization Subsystem:
- Managed by the “serializer” folder (with both text and JSON implementations).
- Handles saving and loading functionalities (persisting the document to a file and restoring from it).

##### Relationships and Interactions
- The CLI layer sends commands to the Director, which manipulates the Document Model. In turn, these changes are reflected in both the GUI (for live interaction) and serialized for persistence.
- The GUI layer may also directly invoke actions similar to CLI commands, for example, via the UiController, which communicates with the Director.
- The Rendering subsystem takes graphical commands (or document item data) and produces visual output that is integrated within the GUI.
- The Serializer interacts with the Document Model to load and save presentation data, supporting both text and JSON formats.

##### Architectural Patterns and Design Principles
- Command Pattern: Evident in the CLI commands implementation (each command encapsulates a specific action).
- MVC/MV* Pattern: The separation between document (model), director/CLI (controller), and GUI (view) illustrates a clear separation of concerns.
- Layered Architecture: Clearly defined subsystems (CLI, director, GUI, rendering, and serialization) each performing specific responsibilities.
- Dependency Injection & Inter-module Communication: Interaction between GUI, director, and rendering layers, likely through well-defined interfaces and intermediate callbacks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Entry
    mainCPP["main.cpp"]:::mainEntryStyle

    %% CLI Layer
    subgraph "CLI Layer"
        cli["CLI Layer"]:::cliStyle
        cliCmdCreator["Command Creator"]:::cliStyle
        cliCommands["Commands"]:::cliStyle
    end

    %% Director/Controller Layer
    subgraph "Director/Controller Layer"
        director["Director/Controller"]:::controllerStyle
        directorActions["Actions"]:::controllerStyle
    end

    %% Document Model
    subgraph "Document Model"
        document["Document Model"]:::documentStyle
    end

    %% GUI Layer
    subgraph "GUI Layer"
        gui["GUI Layer"]:::guiStyle
        guiView["Views"]:::guiStyle
    end

    %% Rendering Subsystem
    subgraph "Rendering Subsystem"
        rendering["Rendering Subsystem"]:::renderingStyle
    end

    %% Serialization Subsystem
    subgraph "Serialization Subsystem"
        serialization["Serialization Subsystem"]:::serializerStyle
        serializerJSON["JSON Serializer"]:::serializerStyle
    end

    %% Relationships and Data Flow
    mainCPP -->|"Initialize"| director
    cliCommands -->|"CommandRequest"| director
    gui -->|"UIActionDispatch"| director
    director <-->|"StateUpdate"| document
    document -->|"RenderRequest"| rendering
    document -->|"PersistenceOperation"| serialization

    %% Click Events
    click cli "https://github.com/davmakar/command_parser/tree/main/cli/"
    click cliCmdCreator "https://github.com/davmakar/command_parser/tree/main/cli/commandCreator"
    click cliCommands "https://github.com/davmakar/command_parser/tree/main/cli/commands"
    click director "https://github.com/davmakar/command_parser/tree/main/director/"
    click directorActions "https://github.com/davmakar/command_parser/tree/main/director/actions"
    click document "https://github.com/davmakar/command_parser/tree/main/document/"
    click gui "https://github.com/davmakar/command_parser/tree/main/gui/"
    click guiView "https://github.com/davmakar/command_parser/tree/main/gui/view/"
    click rendering "https://github.com/davmakar/command_parser/tree/main/rendering/"
    click serialization "https://github.com/davmakar/command_parser/tree/main/serializer/"
    click serializerJSON "https://github.com/davmakar/command_parser/tree/main/serializer/json/"

    %% Styles
    classDef cliStyle fill:#a1c4fd,stroke:#1f5f8b,stroke-width:2px;
    classDef controllerStyle fill:#c3fdb8,stroke:#399d59,stroke-width:2px;
    classDef documentStyle fill:#ffe699,stroke:#b78700,stroke-width:2px;
    classDef guiStyle fill:#ffcccb,stroke:#e60000,stroke-width:2px;
    classDef renderingStyle fill:#d3d3d3,stroke:#808080,stroke-width:2px;
    classDef serializerStyle fill:#fadadd,stroke:#ff69b4,stroke-width:2px;
    classDef mainEntryStyle fill:#e0ffff,stroke:#008b8b,stroke-width:2px;
```
