# mariotoffia/fluentdocker architecture

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

- Interactive diagram: https://gitdiagram.com/mariotoffia/fluentdocker
- Repository: https://github.com/mariotoffia/fluentdocker

## Overview

##### Main architectural layers and components
- Layer 1 – Docker Binaries Interactions: This is where the library wraps low-level Docker commands. It includes modules in the “Commands”, “Executors” (e.g., process executors and response parsers), and “Common” directories (e.g., DockerUri, RequestResponse classes) that encapsulate how the library interacts with Docker processes or shells.
- Layer 2 – Service Layer: Found in the “Services” directory and its “Impl” subdirectory, this layer provides thin service abstractions (like IContainerService, IHostService, and IVolumeService) that encapsulate Docker operations. These services use many of the extension methods (in the “Extensions” directories) to enhance functionality and offer operations like “wait for port”, “copy files”, or “export container” on service objects.
- Layer 3 – Fluent API/Builder Layer: This layer (visible in the “Builders” directory and the “Fd” static class) uses builder and fluent interfaces that allow users to define container setups, docker-compose configurations, and even network/volume settings. It expresses the composition of services, letting a developer create complex multi-container configurations using a chainable API.

##### Ancillary components
- Testing Projects: The tests (located in projects like Ductus.FluentDocker.Tests, Ductus.FluentDocker.MsTest, and Ductus.FluentDocker.XUnit) illustrate how the library is used to spin up Docker containers for integration unit testing. They essentially simulate client code scenarios.
- Examples: The “Examples” directory demonstrates simple, Docker-in-Docker, and event-driven examples, which showcase real-world usage.
- Docker Compose and SSH/Docker-Machine Support: The library also supports external configurations (docker-compose YAML files) and connections to remote Docker daemons (via SSH and docker-machine). These functionalities should be depicted as integrations to external Docker environments.

##### Representing Relationships and Data Flow
- Use clear labels for each component – for instance “Docker Binaries Layer”, “Service Layer”, and “Fluent API Layer.”
- That extension methods “decorate” services and that the builder pattern is used to assemble these pieces.
- External interactions such as connections to the Docker daemon (both local and remote), docker-compose YAML parsing, and SSH or docker-machine integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level Client
    Client("Client/Developer"):::external

    %% Fluent API / Builder Layer
    subgraph "Fluent API / Builder Layer"
        API_Builder("Builder API (Chainable DSL)"):::fluent
        FdEntry("Fluent Entry Point"):::fluent
        %% Remote Machine Builders branch within Fluent API Layer (for clarity in integration)
        %% Although Remote Docker Support is shown separately, sometimes they tie back
    end

    %% Service Layer
    subgraph "Service Layer"
        Docker_Services("Service Abstractions (Containers, Images, Networks, Volumes)"):::service
        Service_Impl("Service Implementations"):::service
        Service_Extensions("Service Extensions"):::service
    end

    %% Docker Binaries Interactions Layer
    subgraph "Docker Binaries Interactions Layer"
        Docker_Commands("Docker Commands Wrapper"):::binaries
        Process_Executors("Process Execution & Response Parsing"):::binaries
        Common_Utils("Common Utilities (DockerUri, RequestResponse)"):::binaries
    end

    %% Docker Compose Support
    subgraph "Docker Compose Support"
        Compose_Commands("Compose Commands"):::compose
        Compose_Models("Compose Models"):::compose
    end

    %% Remote Docker Support
    subgraph "Remote Docker Support"
        Machine_Commands("Machine Commands"):::remote
        Machine_Builder("Machine Builder"):::remote
        Remote_SSH_Builder("Remote SSH Host Builder"):::remote
    end

    %% Testing Components
    subgraph "Testing Components"
        MsTest("MsTest Tests"):::testing
        XUnit("XUnit Tests"):::testing
        Integration_Tests("Integration Tests"):::testing
    end

    %% Example Projects
    Examples("Example Projects"):::example

    %% External Docker Daemon
    Docker_Daemon("Docker Daemon"):::external

    %% Connections
    Client -->|"calls"| API_Builder
    Client -->|"calls"| FdEntry

    API_Builder -->|"builds configuration"| Docker_Services
    FdEntry -->|"invokes services"| Docker_Services

    Docker_Services -->|"uses implementations"| Service_Impl
    Service_Impl -->|"executes"| Docker_Commands
    Service_Extensions -->|"decorates"| Docker_Services

    Docker_Commands -->|"triggers"| Process_Executors
    Process_Executors -->|"communicates with"| Common_Utils
    Common_Utils -->|"sends commands to"| Docker_Daemon

    Docker_Services -->|"handles compose"| Compose_Commands
    Compose_Commands -->|"parses"| Compose_Models

    Docker_Services -->|"handles remote"| Machine_Commands
    Machine_Commands -->|"utilizes"| Machine_Builder
    Machine_Builder -->|"and"| Remote_SSH_Builder

    MsTest -->|"tests API"| FdEntry
    XUnit -->|"tests API"| FdEntry
    Integration_Tests -->|"tests integration"| FdEntry

    Examples -->|"demonstrates usage"| FdEntry

    %% Click Events for Docker Binaries Interactions Layer
    click Docker_Commands "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Commands"
    click Process_Executors "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Executors"
    click Common_Utils "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Common"

    %% Click Events for Service Layer
    click Docker_Services "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Services"
    click Service_Impl "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Services/Impl"
    click Service_Extensions "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Services/Extensions"

    %% Click Events for Fluent API / Builder Layer
    click API_Builder "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Builders"
    click FdEntry "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker/Fd.cs"

    %% Click Events for Docker Compose Support
    click Compose_Commands "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Commands/Compose"
    click Compose_Models "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Model/Compose"

    %% Click Events for Remote Docker Support
    click Machine_Commands "https://github.com/mariotoffia/fluentdocker/tree/master/Ductus.FluentDocker/Commands/Machine"
    click Machine_Builder "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker/Builders/MachineBuilder.cs"
    click Remote_SSH_Builder "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker/Builders/RemoteSshHostBuilder.cs"

    %% Click Events for Testing Components
    click MsTest "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker.MsTest"
    click XUnit "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker.XUnit"
    click Integration_Tests "https://github.com/mariotoffia/fluentdocker/blob/master/Ductus.FluentDocker.Tests"

    %% Click Event for Examples
    click Examples "https://github.com/mariotoffia/fluentdocker/tree/master/Examples"

    %% Styles
    classDef fluent fill:#FFEEAA,stroke:#333,stroke-width:2px;
    classDef service fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef binaries fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef compose fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef remote fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef testing fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef example fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;
```
