# prisma/query-compiler-benchmarks architecture

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

- Interactive diagram: https://gitdiagram.com/prisma/query-compiler-benchmarks
- Repository: https://github.com/prisma/query-compiler-benchmarks

## Overview

##### Project Type and Purpose
- This project is a benchmarking suite focused on testing different configurations and variants of Prisma-based database interactions.
- It uses Node.js with TypeScript and leverages Docker Compose to manage external dependencies like the target database.
- The README shows that it’s designed for running benchmark tests (seeding data, executing tests, and reporting results) with options to generate JSON, CSV, and visual charts.

##### File Structure
- Top-level Elements:
- “main.ts”: Likely the main entry point that orchestrates benchmark tests.
- “docker-compose.yml”: Used to spin up external services, such as the database.
- “pnpm-workspace.yaml”, “package.json”, “tsconfig.json”: Indicating use of a TypeScript monorepo structure managed via pnpm.
- “.github/workflows”: Contains CI/CD pipeline configuration (e.g., automation of benchmarks).
- The “benches” Directory:
- Contains multiple subdirectories such as “prisma-common”, “prisma-native-qe”, “prisma-pg-napi-qe”, “prisma-pg-qc”, and “prisma-pg-wasm-qe”.
- Each subdirectory holds an “index.ts”, “setup.ts”, a “package.json”, and a "prisma" folder with its own “schema.prisma”. This pattern indicates that each module is an isolated benchmark targeting a different Prisma configuration or performance scenario.
- The “bin” Directory:

##### Gather Insights from the README
- The setup instructions (docker-compose up, pnpm install, environment variable configuration) emphasize initial environment setup including database connectivity.
- The customization instructions for reporting show that the outputs (in JSON) can be transformed and visualized—implying a two-stage process: execution of benchmarks followed by result processing and visualization.

##### Main Components
a. External Services:
- Docker-managed Database: Represent the database service started with docker-compose.
- CI/CD Pipeline: The GitHub workflows (bench.yml) to run tests/benchmarks automatically.
b. Application Execution:
- Main Runner: “main.ts” as the entry point that kicks off the benchmark tests.
- Benchmark Modules: The various subdirectories under “benches” (e.g., “prisma-common”, “prisma-native-qe”, etc.) which each execute a set of benchmark tests. They include their own Prisma schema and setup code, indicating self-contained test scenarios.
c. Utility and Reporting Tools:
- JSON to CSV conversion: “bin/json_to_csv”
d. Configuration and Environment:
- Environment configuration via “.envrc” (or manual set of DATABASE_URL) for database connectivity and custom reporting options.
- Configuration files (pnpm, tsconfig) suggesting a monorepo structure.

##### Relationships and Interactions
- The docker-compose setup spins up the external database service.
- “main.ts” (the application’s entry point) triggers the execution of the various benchmark modules.
- Each benchmark module connects to the database using the environment variable (DATABASE_URL) defined by .envrc.
- Benchmark modules generate results in JSON format.
- JSON outputs can be piped to “json_to_csv” for CSV conversion.
- The CI/CD pipeline (GitHub workflows) monitors and automates these tests to ensure consistent performance testing in integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure Subgraph
    subgraph "Infrastructure"
        dockerCompose("Docker Compose Setup"):::external
        dbService("External Database Service"):::external
        dockerCompose -->|"spins-up"| dbService
    end

    %% CI/CD Pipeline
    ciPipeline("CI/CD Pipeline"):::external

    %% Application Execution
    mainRunner("Main Runner (main.ts)"):::app
    envConfig("Environment Config (.envrc)"):::app

    %% Benchmark Modules Subgraph
    subgraph "Benchmark Modules"
        prasCommon("Prisma Common Benchmark"):::app
        prasNative("Prisma Native QE Benchmark"):::app
        prasPGNapi("Prisma PG NAPI QE Benchmark"):::app
        prasPGQC("Prisma PG QC Benchmark"):::app
        prasPGWasm("Prisma PG WASM QE Benchmark"):::app
    end

    %% Reporting Tools Subgraph
    subgraph "Reporting Tools"
        bmResults("Benchmark Results (JSON)"):::reporting
        jsonToCsv("JSON to CSV Converter"):::reporting
        vizTool("Visualization Tool"):::reporting
        bmResults -->|"passes-data"| jsonToCsv
        jsonToCsv -->|"generates"| vizTool
    end

    %% Connections between Components
    ciPipeline -->|"triggers"| mainRunner
    mainRunner -->|"executes"| prasCommon
    mainRunner -->|"executes"| prasNative
    mainRunner -->|"executes"| prasPGNapi
    mainRunner -->|"executes"| prasPGQC
    mainRunner -->|"executes"| prasPGWasm

    envConfig -->|"configures"| prasCommon
    envConfig -->|"configures"| prasNative
    envConfig -->|"configures"| prasPGNapi
    envConfig -->|"configures"| prasPGQC
    envConfig -->|"configures"| prasPGWasm

    prasCommon -->|"outputs"| bmResults
    prasNative -->|"outputs"| bmResults
    prasPGNapi -->|"outputs"| bmResults
    prasPGQC -->|"outputs"| bmResults
    prasPGWasm -->|"outputs"| bmResults

    prasCommon -->|"queries"| dbService
    prasNative -->|"queries"| dbService
    prasPGNapi -->|"queries"| dbService
    prasPGQC -->|"queries"| dbService
    prasPGWasm -->|"queries"| dbService

    %% Styling Definitions
    classDef external fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef app fill:#C3FDB8,stroke:#27AE60,stroke-width:2px;
    classDef reporting fill:#F7C6C7,stroke:#C0392B,stroke-width:2px;

    %% Click Events
    click dockerCompose "https://github.com/prisma/query-compiler-benchmarks/blob/main/docker-compose.yml"
    click ciPipeline "https://github.com/prisma/query-compiler-benchmarks/blob/main/.github/workflows/bench.yml"
    click mainRunner "https://github.com/prisma/query-compiler-benchmarks/blob/main/main.ts"
    click prasCommon "https://github.com/prisma/query-compiler-benchmarks/tree/main/benches/prisma-common"
    click prasNative "https://github.com/prisma/query-compiler-benchmarks/tree/main/benches/prisma-native-qe"
    click prasPGNapi "https://github.com/prisma/query-compiler-benchmarks/tree/main/benches/prisma-pg-napi-qe"
    click prasPGQC "https://github.com/prisma/query-compiler-benchmarks/tree/main/benches/prisma-pg-qc"
    click prasPGWasm "https://github.com/prisma/query-compiler-benchmarks/tree/main/benches/prisma-pg-wasm-qe"
    click jsonToCsv "https://github.com/prisma/query-compiler-benchmarks/tree/main/bin/json_to_csv"
    click vizTool "https://github.com/prisma/query-compiler-benchmarks/blob/main/bin/visualize.py"
```
