# janestreet/base architecture

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

- Interactive diagram: https://gitdiagram.com/janestreet/base
- Repository: https://github.com/janestreet/base

## Overview

##### Main Components and Structure

a. Core Library Components:
- Base Module System
- Standard Data Types
- Utility Functions
- PPX Extensions Integration

b. Supporting Components:
- Build System (Dune)
- Test Framework
- Code Generation Tools

##### Architectural Layers

**┌─────────────────────────────────────────────────────┐**
- Client Code                        │
- ┤
- Base Public API                    │
- ┤
- Core Functionality                    │
- ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────┐  │
- Data Types│ │Containers│ │Utilities │ │PPX    │  │
- ┘ └──────────┘ └──────────┘ └───────┘  │
- ┤
- Platform Abstraction                   │
- ┘

##### Component Details

- Rectangles (Blue): Core modules (String, Array, List, etc.)
- Hexagons (Green): PPX integration points
- Diamonds (Yellow): Extension points

##### Key Relationships to Highlight

Important relationships:

**┌─────────────────┐     ┌─────────────────┐**
- Base Modules   │────▶│  Shadow Stdlib  │
- ┘     └─────────────────┘

- ▼
**┌─────────────────┐     ┌─────────────────┐**
- PPX Derivers   │◀───▶│  Generated Code │
- ┘     └─────────────────┘

##### Implementation Details

Technical aspects:

- Native code bridges (C stubs)
- PPX code generation points
- Test framework integration
- Build system integration

##### Notes

Important notes:

- "Stdlib replacement - no direct stdlib usage"
- "PPX generators for development only"
- "Platform-independent implementation"
- "Zero runtime dependencies"

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Code Layer"
        Client["Client Applications"]
    end

    subgraph "Base Public API Layer"
        BaseAPI["Base Public Interface"]:::api
    end

    subgraph "Core Functionality Layer"
        DataTypes["Data Types"]:::core
        Containers["Containers"]:::core
        Utils["Utilities"]:::core
        PPX["PPX Extensions"]:::ppx
    end

    subgraph "Platform Abstraction Layer"
        Platform["Platform Layer"]:::platform
        JSRuntime["JavaScript Runtime"]:::runtime
        WASMRuntime["WebAssembly Runtime"]:::runtime
        NativeCode["Native Code Implementation"]:::native
    end

    %% Data Types Components
    Arrays["Arrays"]:::datatype
    Lists["Lists"]:::datatype
    Strings["Strings"]:::datatype
    HashTables["Hash Tables"]:::datatype
    Maps["Maps"]:::datatype
    Sets["Sets"]:::datatype

    %% Utility Components
    Comparisons["Comparisons"]:::util
    HashFuncs["Hash Functions"]:::util
    PrettyPrint["Pretty Printing"]:::util
    ErrorHandling["Error Handling"]:::util

    %% Build and Test Components
    BuildSystem["Build System"]:::build
    TestFramework["Test Framework"]:::test
    CodeGen["Code Generation"]:::gen

    %% Special Components
    StdlibShadow["Stdlib Shadow"]:::shadow
    PPXDeriver["PPX Deriver"]:::ppx
    CStubs["C Stubs"]:::native

    %% Relationships
    Client --> BaseAPI
    BaseAPI --> DataTypes
    BaseAPI --> Containers
    BaseAPI --> Utils
    BaseAPI --> PPX

    DataTypes --> Arrays & Lists & Strings & HashTables & Maps & Sets
    Utils --> Comparisons & HashFuncs & PrettyPrint & ErrorHandling

    PPX --> PPXDeriver
    PPXDeriver --> CodeGen

    Platform --> JSRuntime & WASMRuntime & NativeCode
    NativeCode --> CStubs

    BaseAPI --> StdlibShadow

    %% Click Events
    click Arrays "https://github.com/janestreet/base/blob/master/src/array.ml"
    click Lists "https://github.com/janestreet/base/blob/master/src/list.ml"
    click Strings "https://github.com/janestreet/base/blob/master/src/string.ml"
    click HashTables "https://github.com/janestreet/base/blob/master/src/hashtbl.ml"
    click Maps "https://github.com/janestreet/base/blob/master/src/map.ml"
    click Sets "https://github.com/janestreet/base/blob/master/src/set.ml"
    click Comparisons "https://github.com/janestreet/base/blob/master/src/comparisons.ml"
    click HashFuncs "https://github.com/janestreet/base/blob/master/src/hash.ml"
    click PrettyPrint "https://github.com/janestreet/base/blob/master/src/pretty_printer.ml"
    click ErrorHandling "https://github.com/janestreet/base/blob/master/src/error.ml"
    click PPXDeriver "https://github.com/janestreet/base/blob/master/ppx/src/ppx_base_internal.ml"
    click JSRuntime "https://github.com/janestreet/base/blob/master/src/runtime.js"
    click WASMRuntime "https://github.com/janestreet/base/blob/master/src/runtime.wat"
    click StdlibShadow "https://github.com/janestreet/base/blob/master/shadow-stdlib/src/shadow_stdlib.ml"
    click BuildSystem "https://github.com/janestreet/base/tree/master/dune-project"
    click TestFramework "https://github.com/janestreet/base/blob/master/test/base_test.ml"
    click CodeGen "https://github.com/janestreet/base/tree/master/generate/"
    click CStubs "https://github.com/janestreet/base/blob/master/src/bytes_stubs.c"

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef api fill:#90caf9,stroke:#333,stroke-width:2px
    classDef platform fill:#c8e6c9,stroke:#333,stroke-width:2px
    classDef runtime fill:#fff59d,stroke:#333,stroke-width:2px
    classDef native fill:#ffcc80,stroke:#333,stroke-width:2px
    classDef datatype fill:#ce93d8,stroke:#333,stroke-width:2px
    classDef util fill:#80cbc4,stroke:#333,stroke-width:2px
    classDef build fill:#b0bec5,stroke:#333,stroke-width:2px
    classDef test fill:#bcaaa4,stroke:#333,stroke-width:2px
    classDef gen fill:#ffab91,stroke:#333,stroke-width:2px
    classDef shadow fill:#9fa8da,stroke:#333,stroke-width:2px
    classDef ppx fill:#f48fb1,stroke:#333,stroke-width:2px
```
