# rzane/docker2exe architecture

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

- Interactive diagram: https://gitdiagram.com/rzane/docker2exe
- Repository: https://github.com/rzane/docker2exe

## Overview

##### Project type and purpose
- docker2exe is a Go-based command-line tool (an open-source utility) whose job is to take a Docker image and wrap it up as a self-extracting executable.
- It supports two modes: “pull at runtime” (normal) and “embedded mode” (bundles the tarball inside the binary).

##### File structure
- Top-level files:
- main.go – entry point that parses flags and orchestrates the workflow
- cmd/generator.go – core logic that drives code generation and build
- cmd/templates/… – Go templates (Makefile.tmpl, main.go.tmpl, shim.go) used to scaffold a mini Go project per image
- Makefile – driver for CI/build tasks
- go.mod / go.sum – module definition
- Patterns:
- CLI parsing → generator module → template engine → file I/O → external process calls (docker, go build) → output to dist/
- No microservices; a single monolith with well-defined internal submodules.

##### Key insights from the README
- Dependencies at build time: Docker daemon, Go toolchain, gzip
- Runtime dependency: Docker daemon
- Workflow:
a. User runs docker2exe --name X --image Y [--embed]
b. At build time, generator reads templates, writes out a tiny Go program (the “shim”), optionally embeds the gzipped tarball, and invokes `go build` (cross-compiles) to produce platform-specific binaries
c. At runtime, the shim checks via Docker API/CLI for the image, and either pulls or loads it.

##### Diagramming recommendations
- Blue for user-facing modules (CLI Frontend)
- Green for processing modules (Generator, Template Engine)
- Orange for external dependencies

##### Capturing essential architectural elements
- Two runtime behaviors in the shim: “pull” vs “load.”
- How cross-compilation is orchestrated per platform.
- Template folder as the primary extension point.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Input
    UserCLI["User CLI"]:::frontend
    UserCLI -->|"runs docker2exe --name X --image Y [--embed]"| CLIFrontend

    %% Core Components
    CLIFrontend["CLI Frontend\n(parses flags)"]:::frontend
    CodeGen["Code Generator"]:::processing
    TemplateEngine["Template Engine"]:::processing
    WorkingDir["Working Dir\n(generated files)"]:::processing
    BuildOrch["Build Orchestrator"]:::processing
    GoCompiler["Go Compiler\n(cross-compilation)"]:::external
    OutputDist["Output Distributor\n(dist/)"]:::processing
    RuntimeShim["Runtime Shim\n(in binary)"]:::processing

    %% External Dependencies
    subgraph "External Dependencies"
        ExtDocker[(Docker daemon\n& registry)]:::external
        ExtGzip[(gzip / tar)]:::external
    end

    %% Data Flows
    CLIFrontend -->|"invoke generator"| CodeGen
    CodeGen -->|"load templates"| TemplateEngine
    TemplateEngine -->|"write files"| WorkingDir
    CodeGen -->|"hand off to build"| BuildOrch
    BuildOrch -->|"runs go build"| GoCompiler
    GoCompiler -->|"binaries"| OutputDist
    OutputDist -->|"bundled binary"| RuntimeShim
    RuntimeShim -->|"docker pull / load"| ExtDocker

    %% Optional Embed Flow
    BuildOrch -.->|"docker save | gzip"| ExtDocker
    BuildOrch -.->|"embed tarball into shim"| TemplateEngine

    %% Build Orchestrator dependencies
    BuildOrch -->|"uses toolchain"| GoCompiler

    %% Click Events
    click CLIFrontend "https://github.com/rzane/docker2exe/blob/master/main.go"
    click CodeGen "https://github.com/rzane/docker2exe/blob/master/cmd/generator.go"
    click TemplateEngine "https://github.com/rzane/docker2exe/tree/master/cmd/templates/"
    click RuntimeShim "https://github.com/rzane/docker2exe/blob/master/cmd/templates/shim.go"
    click BuildOrch "https://github.com/rzane/docker2exe/tree/master/Makefile"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#333,stroke-width:1px;
    classDef processing fill:#E0FFE0,stroke:#333,stroke-width:1px;
    classDef external fill:#FFE0B2,stroke:#333,stroke-width:1px;
```
