# bazelbuild/reclient architecture

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

- Interactive diagram: https://gitdiagram.com/bazelbuild/reclient
- Repository: https://github.com/bazelbuild/reclient

## Overview

##### Main components
- Frontend/Integration Layer: This includes the rewrapper binary that intercepts build commands. Rewrapper is responsible for “wrapping” the original invocation so that it connects with the remote execution infrastructure.
- Coordinator/Orchestration Component: The reproxy component acts as the central hub. It is started by and stopped through the bootstrap process. Reproxy manages communication with the remote build server and coordinates fetching and caching build artifacts.
- Dependency Scanner Service: The scandeps_server (and its corresponding CLI clients) handles scanning and processing C/C++ include dependencies.
- API Modules: Under the “api” directory you see various subcomponents (auth, credshelper, log, proxy, scandeps, stat, stats) that define or handle the protocol buffers (with corresponding .proto files) and generated Go implementations. These represent the interfaces and data structures used for communication (for example, with remote execution servers or for internal logging/credential management).
- Internal Processing and Utility Libraries: The “internal” and “pkg” directories contain a wealth of packages (such as auth, inputprocessor, reproxy, rewrapper, stats, etc.) that implement the business logic, input processing, dependency analysis, logging, and other utility functions. They form the backbone of the re-client system.
- Configuration & Build Environment: Files and directories (like BUILD.bazel, WORKSPACE, configs/, and the module extensions) indicate a Bazel-centric build that also supports multiple platforms (Linux, Windows, Mac). These components ensure that all binaries and tools are built from a consistent code base.

##### Relationships and interactions
- The reproxy, in turn, communicates with the external Remote Execution API server to schedule build actions remotely, upload toolchains and inputs, and download resulting artifacts. Also, it interacts with the scandeps_server to process C++ dependencies.
- Bootstrap manages the lifecycle of reproxy (starting and stopping it) and aggregates build metrics. It also interacts with the configuration sources (command-line flags, environment variables, configuration file) to drive how all these components behave.
- The API components (auth, credshelper, etc.) play a role in ensuring that the correct credentials are attached to the remote requests and that logging is standardized across the system.
- The internal packages support the processing of build inputs (using flags parsing, file-system path translation, toolchain files, etc.), making sure that the environment is faithfully replicated for remote execution.

##### Architectural patterns and design principles
- Modularity: The project is broken into discrete binaries (rewrapper, reproxy, bootstrap, scandeps, etc.) as well as well-defined internal modules. This separation makes it easier to update or replace parts without affecting the whole system.
- Client-Server Architecture: The rewrapper acts as a client component communicating with reproxy (the local server), which then connects to a remote execution service.
- Dependency Processing: Modules within the “inputprocessor” and subdirectories illustrate a detailed pipeline for processing compilation flags, toolchain inputs, and dependency scanning – crucial for correctly reproducing build environments remotely.

##### Additional notes based on project type
- Since this is a full-stack build integration system, explicitly separate front-end (client invocation via rewrapper) from the backend (remote execution, caching, and result processing in reproxy). Emphasize the network boundary where reproxy communicates with a remote execution server.

##### Final checklist
- Clearly label every component using the project’s terminology (rewrapper, reproxy, bootstrap, scandeps_server, API modules, internal processing libraries).
- Annotations for important design decisions such as dependency scanning with two supported modes (goma vs. clang-scan-deps) and the integration patterns for various build systems (GN, CMake, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend / Integration Layer"
        RWrapper["rewrapper – intercepts build commands"]
    end

    subgraph "Coordinator / Orchestration"
        Bootstrap["bootstrap – manages lifecycle & aggregates metrics"]
        RProxy["reproxy – central communication hub"]
    end

    subgraph "Dependency Scanning Service"
        ScanDeps["scandeps_server – scans C/C++ dependencies"]
    end

    subgraph "API Modules"
        API_Auth["Auth – credential management"]
        API_Creds["CredsHelper – assists with credentials"]
        API_Log["Log – standardized logging"]
        API_Proxy["Proxy – remote communication definitions"]
        API_Scandeps["Scandeps – dependency API"]
        API_Stat["Stat – build statistics interface"]
        API_Stats["Stats – aggregated metrics"]
    end

    subgraph "Internal Processing & Utility Libraries"
        InputProc["InputProcessor – processes build inputs & flags"]
        Logger["Logger – logging utility"]
        IPC["IPC – inter-process communication"]
        PathTrans["PathTranslator – file-system path mapping"]
    end

    subgraph "Configuration & Build Environment"
        BuildEnv["Bazel/Build Environment"]
    end

    External["Remote Execution Server"]

    %% Relationships
    RWrapper -->|"IPC"| RProxy
    Bootstrap -->|"manages"| RProxy
    RProxy -->|"schedules"| External
    RProxy -->|"triggers"| ScanDeps
    BuildEnv -.->|"config"| Bootstrap
    BuildEnv -.->|"config"| RProxy

    %% API integrations from reproxy
    RProxy -->|"API"| API_Auth
    RProxy -->|"API"| API_Creds
    RProxy -->|"API"| API_Log
    RProxy -->|"API"| API_Proxy
    RProxy -->|"API"| API_Scandeps
    RProxy -->|"API"| API_Stat
    RProxy -->|"API"| API_Stats

    %% Internal libraries support both RWrapper and RProxy
    InputProc ---|"supports"| RWrapper
    Logger ---|"supports"| RWrapper
    IPC ---|"supports"| RWrapper
    PathTrans ---|"supports"| RWrapper

    InputProc ---|"supports"| RProxy
    Logger ---|"supports"| RProxy
    IPC ---|"supports"| RProxy
    PathTrans ---|"supports"| RProxy

    %% Click Events for Frontend/Integration (rewrapper)
    click RWrapper "https://github.com/bazelbuild/reclient/blob/main/cmd/rewrapper/main.go"
    click RWrapper "https://github.com/bazelbuild/reclient/blob/main/internal/pkg/rewrapper/rewrapper.go"

    %% Click Events for Coordinator/Orchestration (reproxy)
    click RProxy "https://github.com/bazelbuild/reclient/blob/main/cmd/reproxy/main.go"
    click RProxy "https://github.com/bazelbuild/reclient/blob/main/internal/pkg/reproxy/server.go"

    %% Click Events for Bootstrap
    click Bootstrap "https://github.com/bazelbuild/reclient/blob/main/cmd/bootstrap/main.go"
    click Bootstrap "https://github.com/bazelbuild/reclient/blob/main/internal/pkg/bootstrap/bootstrap.go"

    %% Click Events for Dependency Scanner Service (scandeps_server)
    click ScanDeps "https://github.com/bazelbuild/reclient/blob/main/cmd/scandeps/server/server.cc"
    click ScanDeps "https://github.com/bazelbuild/reclient/blob/main/cmd/scandeps/server/server.h"
    click ScanDeps "https://github.com/bazelbuild/reclient/blob/main/api/scandeps/cppscandeps.proto"
    click ScanDeps "https://github.com/bazelbuild/reclient/blob/main/api/scandeps/cppscandeps.pb.go"

    %% Click Events for API Modules
    click API_Auth "https://github.com/bazelbuild/reclient/blob/main/api/auth/auth.proto"
    click API_Auth "https://github.com/bazelbuild/reclient/blob/main/api/auth/auth.pb.go"

    click API_Creds "https://github.com/bazelbuild/reclient/blob/main/api/credshelper/credshelper.proto"
    click API_Creds "https://github.com/bazelbuild/reclient/blob/main/api/credshelper/credshelper.pb.go"

    click API_Log "https://github.com/bazelbuild/reclient/blob/main/api/log/log.proto"
    click API_Log "https://github.com/bazelbuild/reclient/blob/main/api/log/log.pb.go"

    click API_Proxy "https://github.com/bazelbuild/reclient/blob/main/api/proxy/proxy.proto"
    click API_Proxy "https://github.com/bazelbuild/reclient/blob/main/api/proxy/proxy.pb.go"

    click API_Scandeps "https://github.com/bazelbuild/reclient/blob/main/api/scandeps/cppscandeps.proto"
    click API_Scandeps "https://github.com/bazelbuild/reclient/blob/main/api/scandeps/cppscandeps.pb.go"

    click API_Stat "https://github.com/bazelbuild/reclient/blob/main/api/stat/stat.proto"
    click API_Stat "https://github.com/bazelbuild/reclient/blob/main/api/stat/stat.pb.go"

    click API_Stats "https://github.com/bazelbuild/reclient/blob/main/api/stats/stats.proto"
    click API_Stats "https://github.com/bazelbuild/reclient/blob/main/api/stats/stats.pb.go"

    %% Click Events for Internal Processing & Utility Libraries
    click InputProc "https://github.com/bazelbuild/reclient/tree/main/internal/pkg/inputprocessor"
    click InputProc "https://github.com/bazelbuild/reclient/tree/main/pkg/inputprocessor"
    click Logger "https://github.com/bazelbuild/reclient/tree/main/internal/pkg/logger"
    click IPC "https://github.com/bazelbuild/reclient/tree/main/internal/pkg/ipc"
    click PathTrans "https://github.com/bazelbuild/reclient/tree/main/internal/pkg/pathtranslator"

    %% Click Events for Configuration & Build Environment
    click BuildEnv "https://github.com/bazelbuild/reclient/blob/main/BUILD.bazel"
    click BuildEnv "https://github.com/bazelbuild/reclient/tree/main/WORKSPACE"
    click BuildEnv "https://github.com/bazelbuild/reclient/tree/main/configs/"

    %% Styles
    classDef binary fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef api fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef internal fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef config fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef external fill:#f5d5a3,stroke:#333,stroke-width:2px;

    class RWrapper,Bootstrap,RProxy,ScanDeps binary;
    class API_Auth,API_Creds,API_Log,API_Proxy,API_Scandeps,API_Stat,API_Stats api;
    class InputProc,Logger,IPC,PathTrans internal;
    class BuildEnv config;
    class External external;
```
