# crc-org/crc architecture

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

- Interactive diagram: https://gitdiagram.com/crc-org/crc
- Repository: https://github.com/crc-org/crc

## Overview

##### Project Type and Purpose
- This project is a command-line tool that orchestrates and manages local OpenShift/OKD clusters for development and testing purposes. It’s not a full-stack web application but a CLI-based tool that interfaces directly with container runtimes and virtualization layers.
- The README clarifies that CRC is “a tool to run containers,” specifically handling OpenShift 4.x/OKD clusters, and it includes telemetry and configuration for usage data collection.

##### Analyzing the File Structure
- The top-level directories reveal clear segmentation:
- The “cmd” directory defines the CLI commands (e.g., start, stop, config, daemon, etc.). There are two main command binaries: one for the core “crc” logic and one for “crc-embedder.”
- The “pkg” directory contains a large number of sub-packages implementing core functionalities such as cluster management, machine handling, network configuration, driver integrations (vfkit, libvirt, libhvee), API endpoints, telemetry, error handling, configuration, and caching.
- The “packaging” and “images” directories illustrate how the binary is built and deployed for different platforms (macOS, Windows, Linux) and how container images are constructed to support CI/CD.
- CI/CD and automation are supported in the “.github” directory, with multiple GitHub workflows for building, testing, and validating the project across platforms.
- This modular file layout suggests an architecture where different concerns (CLI interaction, backend service/daemon operations, cluster configuration, machine drivers, and integrations with OS services) are cleanly separated.

a. Main Components:
- CLI Interface: Represented by the binaries in “cmd/crc” and “cmd/crc-embedder.” These accept user commands (like start, stop, config, etc.) and act as the entry points.
- Daemon/Background Service: A dedicated component (found under “cmd/crc/cmd/daemon.go” and related tests) that continuously manages the environment and cluster state.
- Core Business Logic Modules:
‣ Cluster and Machine Management – from packages in “pkg/crc/cluster” and “pkg/crc/machine.” These handle bundling, VM lifecycle, driver abstraction (via sub-packages for vfkit, libvirt, libhvee, none, etc.), and state management.
‣ Configuration and Caching – organized under “pkg/crc/config” and “pkg/crc/cache,” which store settings, environment state, and manage secret configurations.
‣ Networking and Proxying – included in “pkg/crc/network” (DNS, HTTP proxy, etc.).
‣ API Interaction and Event Handling – from “pkg/crc/api” that sets up HTTP-based APIs, SSE client, and event streams.
‣ Telemetry and Logging – via “pkg/crc/telemetry” and “pkg/crc/logging” to collect usage data and maintain logs.
‣ Utility Functions such as compression, extraction, error handling, and OS interaction (in various “pkg/os” submodules).
- External Build and Packaging Components:
‣ CI/CD infrastructure from the “.github/workflows” and “Makefile” used for testing and releasing.
‣ Packaging scripts and images in the “packaging” and “images” directories that generate installable artifacts and Docker containers.

b. Relationships and Interactions:
- The CLI acts as the user’s interface, dispatching commands to the daemon or directly invoking functions from the core libraries.
- The daemon continuously monitors and manages the state of the VM/cluster using components from the machine and cluster managers.
- The configuration subsystem mediates between user-set configuration parameters (and telemetry consent) and the behavior of the core modules.
- The API components expose or coordinate internal events (e.g., cluster status updates, error reporting) and might interact with telemetry and logging modules.
- Networking, OS-specific driver integrations, and system services interconnect with the machine drivers to ensure the VM or container environment is properly bootstrapped.
- CI/CD components (images, packaging, GitHub workflows) interface with the code to build, test, and distribute the final binaries across platforms.

c. Architectural Patterns and Design Principles:
- Modular Design: Each functionality (CLI, daemon, cluster management, networking, configuration, logging) is separated into distinct packages/modules.
- Cross-platform Abstraction: There are OS-specific implementations (for Linux, macOS, Windows) indicating an abstraction layer in components like “daemon_<os>.go” and different drivers under “pkg/drivers.”
- Separation of Concerns: The clear separation between command processing, cluster/machine orchestration, and auxiliary tasks (packaging, telemetry) suggests a layered architecture.
- Extensibility: The structure supports adding new drivers, network configurations, or additional packaging targets.

d. Relevant Technologies, Frameworks, or Libraries:
- Go Language and its module system (go.mod, go.sum) are central.
- GitHub Actions and associated workflows for CI/CD.
- Containerization practices (Dockerfiles in the images directory) to build environments.
- Telemetry integration for usage data collection.
- Dependency management via Go tooling and possibly security scanning using “.snyk” and “golangci.yml.”

##### Detail and Clarity
- As many components as possible from the file tree, detailing the interdependencies (e.g., error and logging flow, handling of configuration inputs, and update mechanisms via the daemon).
- Keep labels clear (e.g., “CLI: Commands (start/stop/config)”, “Daemon: Background state management”, “Machine Drivers: VFKit / Libvirt / etc.”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Interface
    subgraph "CLI Interface"
        CRC_Binary("CRC Binary (cmd/crc)"):::cli
        Embedder_Binary("Embedder Binary (cmd/crc-embedder)"):::cli
    end

    %% Daemon/Background Service
    Daemon("Daemon/Service"):::daemon

    %% Core Business Modules
    subgraph "Core Modules"
        %% Cluster & Machine Management
        subgraph "Cluster & Machine Management"
            Cluster_Manager("Cluster Manager (pkg/crc/cluster)"):::core
            Machine_Manager("Machine Manager (pkg/crc/machine)"):::core
        end
        %% Configuration & Caching
        subgraph "Configuration & Caching"
            Configuration("Configuration (pkg/crc/config)"):::config
            Caching("Caching (pkg/crc/cache)"):::config
        end
        %% Networking & API Interaction
        subgraph "Networking & API Interaction"
            Networking("Networking (pkg/crc/network)"):::network
            API("API Interaction (pkg/crc/api)"):::network
        end
        %% Telemetry & Logging
        subgraph "Telemetry & Logging"
            Telemetry("Telemetry (pkg/crc/telemetry)"):::telemetry
            Logging("Logging (pkg/crc/logging)"):::telemetry
            RedHat("Red Hat Servers"):::external
        end
    end

    %% Build & Packaging and CI/CD
    subgraph "Build & Packaging"
        Packaging("Packaging Scripts (packaging)"):::build
        Images("Docker Images (images)"):::build
    end
    CI_CD("CI/CD Workflows (.github/workflows)"):::ci

    %% Connections from CLI to Daemon
    CRC_Binary -->|"commands"| Daemon
    Embedder_Binary -->|"commands"| Daemon

    %% Daemon interactions with core modules
    Daemon -->|"manages"| Cluster_Manager
    Daemon -->|"manages"| Machine_Manager
    Daemon -->|"configures"| Networking
    Daemon -->|"dispatches"| API

    %% Configuration influences core modules
    Configuration -->|"configures"| Daemon
    Configuration -->|"configures"| Cluster_Manager
    Configuration -->|"configures"| Machine_Manager
    Configuration -->|"configures"| Networking
    Configuration -->|"configures"| API
    Configuration -->|"configures"| Telemetry

    %% API and Logging interaction
    API -->|"logsTo"| Logging

    %% Telemetry reporting to external server
    Telemetry -->|"reportsTo"| RedHat

    %% CI/CD triggers build components
    CI_CD -->|"triggers"| Packaging
    CI_CD -->|"triggers"| Images
    Packaging -->|"builds"| CRC_Binary
    Packaging -->|"builds"| Embedder_Binary

    %% Click Events
    click CRC_Binary "https://github.com/crc-org/crc/tree/main/cmd/crc"
    click Embedder_Binary "https://github.com/crc-org/crc/tree/main/cmd/crc-embedder"
    click Daemon "https://github.com/crc-org/crc/blob/main/cmd/crc/cmd/daemon.go"
    click Cluster_Manager "https://github.com/crc-org/crc/tree/main/pkg/crc/cluster"
    click Machine_Manager "https://github.com/crc-org/crc/tree/main/pkg/crc/machine"
    click Configuration "https://github.com/crc-org/crc/tree/main/pkg/crc/config"
    click Caching "https://github.com/crc-org/crc/tree/main/pkg/crc/cache"
    click Networking "https://github.com/crc-org/crc/tree/main/pkg/crc/network"
    click API "https://github.com/crc-org/crc/tree/main/pkg/crc/api"
    click Telemetry "https://github.com/crc-org/crc/tree/main/pkg/crc/telemetry"
    click Logging "https://github.com/crc-org/crc/tree/main/pkg/crc/logging"
    click Packaging "https://github.com/crc-org/crc/tree/main/packaging"
    click Images "https://github.com/crc-org/crc/tree/main/images"
    click CI_CD "https://github.com/crc-org/crc/tree/main/.github/workflows"

    %% Styles
    classDef cli fill:#FFCCCC,stroke:#8B0000,stroke-width:2px;
    classDef daemon fill:#FFE599,stroke:#B8860B,stroke-width:2px;
    classDef core fill:#C2E0C6,stroke:#2E8B57,stroke-width:2px;
    classDef config fill:#DDEBF7,stroke:#1C4587,stroke-width:2px;
    classDef network fill:#FCE5CD,stroke:#B45F06,stroke-width:2px;
    classDef telemetry fill:#D9EAD3,stroke:#38761D,stroke-width:2px;
    classDef build fill:#D9D2E9,stroke:#674EA7,stroke-width:2px;
    classDef ci fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
    classDef external fill:#EEECE1,stroke:#666600,stroke-width:2px;
```
