# bazel-contrib/bazel-lib architecture

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

- Interactive diagram: https://gitdiagram.com/bazel-contrib/bazel-lib
- Repository: https://github.com/bazel-contrib/bazel-lib

## Overview

- How rules interact with Bazel's build system
- How toolchains are resolved and used
- Demonstrate file transformation pipelines

- Relationship with bazel-skylib
- Internal component dependencies
- Optional vs. required dependencies

##### Key Architectural Patterns

a. Toolchain Pattern (Highlight with a boundary):
- Toolchain definitions
- Toolchain resolution flow
- Platform-specific implementations

b. Rule Pattern (Highlight with a boundary):
- Rule implementation structure
- Provider definitions
- Extension points

##### Specific Elements

a. Directory Structure (Use nested containers):
- /lib (core implementation)
- /tools (binary implementations)
- /docs (documentation)
- /tests (test suite)

b. Integration Points (Use interface symbols):
- Bazel Rule Interface
- Starlark API Surface
- Toolchain Registration Points

##### Implementation Details Layer

Specific implementations for:
- File operations (copy, transform)
- Template expansion
- JSON/YAML processing
- Testing infrastructure

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style Definitions
    classDef core fill:#a8d1f0,stroke:#333
    classDef toolchain fill:#90EE90,stroke:#333
    classDef infra fill:#D3D3D3,stroke:#333
    classDef file fill:#FFE4B5,stroke:#333
    classDef test fill:#FFB6C1,stroke:#333
    classDef docs fill:#DDA0DD,stroke:#333

    %% Main Sections
    subgraph CoreLib["Core Library Components"]
        Pack["Packaging Tools"]
        FileOps["File Operations"]
        FileTrans["File Transformers"]
        PathMan["Path Manipulators"]
        RuleWrite["Rule Writers"]
        TestTools["Testing Tools"]
        DocGen["Documentation Generator"]
    end

    subgraph Infra["Infrastructure Components"]
        Bazel["Bazel Build System"]
        ExtDep["External Dependencies"]
        PlatImpl["Platform-specific Implementations"]
    end

    subgraph Tools["Toolchains"]
        JQTool["JQ Toolchain"]
        YQTool["YQ Toolchain"]
        TarTool["Tar Toolchain"]
        ExpTool["Expand Template Toolchain"]
    end

    subgraph Impl["Implementation Details"]
        BinImpl["Binary Implementations"]
        TestImpl["Test Infrastructure"]
        PlatUtils["Platform Utilities"]
        CommonUtils["Common Utilities"]
    end

    %% Relationships
    CoreLib --> Bazel
    Tools --> CoreLib
    Impl --> CoreLib
    ExtDep -.-> CoreLib
    PlatImpl --> Tools

    %% Component Styling
    class Pack,FileOps,FileTrans,PathMan,RuleWrite,TestTools,DocGen core
    class JQTool,YQTool,TarTool,ExpTool toolchain
    class Bazel,ExtDep,PlatImpl infra
    class BinImpl,TestImpl,PlatUtils,CommonUtils file

    %% Click Events
    click Pack "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/tar.bzl"
    click FileOps "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/copy_directory.bzl"
    click FileTrans "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/jq.bzl"
    click PathMan "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/paths.bzl"
    click RuleWrite "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/expand_make_vars.bzl"
    click TestTools "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/bats.bzl"
    click DocGen "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/docs.bzl"
    click JQTool "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/private/jq_toolchain.bzl"
    click YQTool "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/private/yq_toolchain.bzl"
    click TarTool "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/private/tar_toolchain.bzl"
    click ExpTool "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/private/expand_template_toolchain.bzl"
    click BinImpl "https://github.com/bazel-contrib/bazel-lib/blob/main/tools/copy_directory/main.go"
    click TestImpl "https://github.com/bazel-contrib/bazel-lib/tree/main/lib/tests/"
    click PlatUtils "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/platform_utils.bzl"
    click CommonUtils "https://github.com/bazel-contrib/bazel-lib/blob/main/lib/utils.bzl"

    %% Legend
    subgraph Legend
        L1[Core Library Functions]:::core
        L2[Toolchains]:::toolchain
        L3[Infrastructure]:::infra
        L4[Implementation]:::file
    end
```
