# dataform-co/dataform architecture

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

- Interactive diagram: https://gitdiagram.com/dataform-co/dataform
- Repository: https://github.com/dataform-co/dataform

## Overview

##### Project type and purpose
- This is Dataform Core: an open‑source TypeScript/Node.js “meta‑language” and CLI for defining, compiling, and running SQL transformations and dependency graphs on BigQuery. It also includes a VSCode extension and gRPC/protobuf APIs for remote orchestration.

##### File structure
- Top‑level Bazel config (BUILD, WORKSPACE), tsconfig.json, package.json, scripts/ and tools/ for repo-level automation.
- cli/: the CLI application, commands (build, compile, run, test, query, etc.), yargs wrapper, VM compile, dbadapters (BigQuery, generic SQL execution).
- core/: the heart of the system—Actions, Compilers, Session, Contextables, Path, WorkflowSettings. Transforms SQLX ASTs into SQL.
- common/: shared utilities—errors, promises, flags, protos definitions.
- protos/ & common/protos: .proto files describing RPC contracts (configs, compilation, execution, evaluation, profiles).
- sqlx/: custom SQLX parser/lexer.
- packages/: Bazel TS packages (@dataform/cli, @dataform/core), rollup configs, worker.ts.
- vscode/: the VSCode extension client (extension.ts) and language‑server (server.ts), grammar, schemas.
- tests/: unit, API, integration tests covering CLI->core APIs and BigQuery end‑to‑end.
- examples/: sample Dataform projects.
- scripts/ and tools/: CI/CD (cloudbuild, GitHub workflows), publishing, linting, versioning.

##### README
- Confirms purpose: dependency management, data‑quality testing, docs generation for BigQuery pipelines.
- Highlights two interfaces: the managed GCP environment and local CLI.
- Points to core features (tables, views, assertions, JavaScript API).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Project"
        User["User Project<br/>(dataform.json, definitions/*.sqlx/.js)"]:::code
    end

    subgraph "CLI Layer"
        Yargs["Yargs Wrapper"]:::code
        Commands["Commands<br/>(build, compile, run, test, query)"]:::code
        CLIIndex["cli/api/index"]:::code
        Worker["worker.ts"]:::code
    end

    subgraph "Core Library"
        CoreIndex["core/index.ts"]:::code
        Compilers["compilers.ts"]:::code
        Session["session.ts"]:::code
        Path["path.ts"]:::code
        Workflow["workflow_settings.ts"]:::code
        Actions["actions/*"]:::code
    end

    subgraph "SQLX Parser"
        Lexer["lexer.ts"]:::code
        Format["format.ts"]:::code
    end

    subgraph "DB Adapters"
        BigQuery["bigquery.ts"]:::code
        ExecSQL["execution_sql.ts"]:::code
        DBIndex["index.ts"]:::code
    end

    subgraph "Protobuf/gRPC API"
        Configs["configs.proto"]:::code
        CoreProto["core.proto"]:::code
        ExecutionProto["execution.proto"]:::code
        EvalProto["evaluation.proto"]:::code
        Profiles["profiles.proto"]:::code
        CommonProtos["common/protos/index.ts"]:::code
    end

    subgraph "VSCode Extension"
        Extension["extension.ts"]:::code
        Server["server.ts"]:::code
        Grammar["sqlx.grammar.json"]:::code
        Schema["workflow_settings_yaml.schema.json"]:::code
    end

    subgraph "Build & Packaging"
        Bazel["BUILD, WORKSPACE"]:::infra
        PackageCLI["packages/@dataform/cli/BUILD"]:::infra
        PackageCore["packages/@dataform/core/BUILD"]:::infra
        Rollup["rollup.config.js<br/>rollup_dts.config.js"]:::infra
    end

    subgraph "CI/CD"
        Tests["scripts/run_tests*<br/>cloudbuild-test.yaml"]:::infra
        Publish["scripts/publish<br/>cloudbuild-publish.yaml"]:::infra
        Version["scripts/update_version<br/>cloudbuild-version.yaml"]:::infra
        GHActions[".github/workflows/test.yaml"]:::infra
    end

    subgraph "External Services"
        BigQueryExt["BigQuery"]:::external
        GCS["GCS"]:::external
        NPM["npm Registry"]:::external
        GitHub["GitHub"]:::external
    end

    User --> Yargs
    User <--> Extension
    Yargs --> CLIIndex
    Yargs --> Commands
    CLIIndex --> Worker
    Worker --> CoreIndex
    CoreIndex --> Lexer
    CoreIndex --> Format
    Lexer --> Compilers
    Format --> Compilers
    Compilers --> Actions
    Actions --> Compilers
    Compilers --> ExecSQL
    ExecSQL --> BigQueryExt
    ExecSQL --> GCS
    CoreIndex --> Session
    Session --> Path
    Session --> Workflow
    CoreIndex --> DBIndex
    DBIndex --> BigQueryExt
    CoreIndex --> CommonProtos
    CommonProtos -.-> Server
    CommonProtos -.-> CoreIndex
    Server --> CoreIndex
    Server --> Lexer

    Bazel --> PackageCLI
    Bazel --> PackageCore
    Rollup --> PackageCLI
    Rollup --> PackageCore
    PackageCLI --> NPM
    PackageCore --> NPM

    GHActions --> Tests
    GHActions --> Publish
    Tests --> CoreIndex
    Tests --> CLIIndex
    Publish --> NPM
    Version --> NPM

    GitHub --> GHActions

    classDef code fill:#cce5ff,stroke:#0366d6,color:#0366d6;
    classDef infra fill:#fff3cd,stroke:#f1c40f,color:#7a6e00;
    classDef external fill:#d4edda,stroke:#28a745,color:#155724;

    click Yargs "https://github.com/dataform-co/dataform/blob/main/cli/yargswrapper.ts"
    click Commands "https://github.com/dataform-co/dataform/tree/main/cli/api/commands/"
    click CLIIndex "https://github.com/dataform-co/dataform/blob/main/cli/api/index.ts"
    click Worker "https://github.com/dataform-co/dataform/blob/main/packages/@dataform/cli/worker.ts"

    click CoreIndex "https://github.com/dataform-co/dataform/blob/main/core/index.ts"
    click Compilers "https://github.com/dataform-co/dataform/blob/main/core/compilers.ts"
    click Session "https://github.com/dataform-co/dataform/blob/main/core/session.ts"
    click Path "https://github.com/dataform-co/dataform/blob/main/core/path.ts"
    click Workflow "https://github.com/dataform-co/dataform/blob/main/core/workflow_settings.ts"
    click Actions "https://github.com/dataform-co/dataform/tree/main/core/actions/"

    click Lexer "https://github.com/dataform-co/dataform/blob/main/sqlx/lexer.ts"
    click Format "https://github.com/dataform-co/dataform/blob/main/sqlx/format.ts"

    click BigQuery "https://github.com/dataform-co/dataform/blob/main/cli/api/dbadapters/bigquery.ts"
    click ExecSQL "https://github.com/dataform-co/dataform/blob/main/cli/api/dbadapters/execution_sql.ts"
    click DBIndex "https://github.com/dataform-co/dataform/blob/main/cli/api/dbadapters/index.ts"

    click Configs "https://github.com/dataform-co/dataform/blob/main/protos/configs.proto"
    click CoreProto "https://github.com/dataform-co/dataform/blob/main/protos/core.proto"
    click ExecutionProto "https://github.com/dataform-co/dataform/blob/main/protos/execution.proto"
    click EvalProto "https://github.com/dataform-co/dataform/blob/main/protos/evaluation.proto"
    click Profiles "https://github.com/dataform-co/dataform/blob/main/protos/profiles.proto"
    click CommonProtos "https://github.com/dataform-co/dataform/blob/main/common/protos/index.ts"

    click Extension "https://github.com/dataform-co/dataform/blob/main/vscode/extension.ts"
    click Server "https://github.com/dataform-co/dataform/blob/main/vscode/server.ts"
    click Grammar "https://github.com/dataform-co/dataform/blob/main/vscode/sqlx.grammar.json"
    click Schema "https://github.com/dataform-co/dataform/blob/main/vscode/workflow_settings_yaml.schema.json"

    click Bazel "https://github.com/dataform-co/dataform/tree/main/BUILD"
    click PackageCLI "https://github.com/dataform-co/dataform/tree/main/packages/@dataform/cli/BUILD"
    click PackageCore "https://github.com/dataform-co/dataform/tree/main/packages/@dataform/core/BUILD"
    click Rollup "https://github.com/dataform-co/dataform/blob/main/packages/rollup.config.js"
    click Rollup "https://github.com/dataform-co/dataform/blob/main/packages/rollup_dts.config.js"

    click Tests "https://github.com/dataform-co/dataform/tree/main/scripts/run_tests"
    click Publish "https://github.com/dataform-co/dataform/tree/main/scripts/publish"
    click Version "https://github.com/dataform-co/dataform/tree/main/scripts/update_version"
    click GHActions "https://github.com/dataform-co/dataform/blob/main/.github/workflows/test.yaml"
```
