# pola-rs/nodejs-polars architecture

> Architecture diagram of the GitHub repository pola-rs/nodejs-polars, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pola-rs/nodejs-polars
- Repository: https://github.com/pola-rs/nodejs-polars

## Overview

##### Main Components Identification

The system should be represented with these key components:

a. Core Components:
- Rust Core (Polars Engine)
- Node.js Bindings Layer
- TypeScript API Layer

b. Supporting Components:
- I/O Systems
- Data Type System
- Query Engine
- Lazy Evaluation Engine

**┌─ Application Layer ─────────────────────┐**
- TypeScript API                          │
- (polars/*.ts files)                    │
- ┤
- Node.js Bindings                        │
- (src/*.rs files)                       │
- ┤
- Rust Core Engine                        │
- (Polars Core Library)                  │
- ┘

##### Component Details

a. Data Processing Components (Rectangle):
- DataFrame Operations
- Series Operations
- Lazy Evaluation System
- SQL Query Engine

b. Data Types (Hexagon):
- Complex Types
- DateTime
- Strings
- Structs
- Lists

- CSV
- JSON
- Feather
- TSV

##### Interaction Flows

- User Code → TypeScript API
- TypeScript API → Node.js Bindings
- Node.js Bindings → Rust Core
- Bidirectional data flow between components

##### Implementation Details

- Series Operations (/polars/series/)
- DataFrame Operations (/polars/dataframe.ts)
- Lazy Operations (/polars/lazy/)
- SQL Interface (/polars/sql.ts)

##### Additional Notes

- The bridge between Node.js and Rust
- The lazy evaluation system
- Type safety across language boundaries
- Platform-specific optimizations

Remember to include version compatibility information and system requirements as supplementary documentation.

This architecture reflects the project's focus on high-performance data processing with a user-friendly TypeScript interface, while maintaining the power of Rust's memory safety and performance characteristics.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        A[API Component]:::api
        B[(I/O Component)]:::io
        C{Type System}:::type
        D[[Processing Engine]]:::engine
        E[/Platform Build/]:::platform
    end

    subgraph "Application Layer"
        TS_API[TypeScript API]:::api
        click TS_API "https://github.com/pola-rs/nodejs-polars/tree/main/polars/"
        DF[DataFrame Operations]:::api
        click DF "https://github.com/pola-rs/nodejs-polars/blob/main/polars/dataframe.ts"
        SO[Series Operations]:::api
        click SO "https://github.com/pola-rs/nodejs-polars/tree/main/polars/series/"
        CF[Core Functions]:::api
        click CF "https://github.com/pola-rs/nodejs-polars/blob/main/polars/functions.ts"
        SQL_IF[SQL Interface]:::api
        click SQL_IF "https://github.com/pola-rs/nodejs-polars/blob/main/polars/sql.ts"
        IO_IF[I/O Interface]:::api
        click IO_IF "https://github.com/pola-rs/nodejs-polars/blob/main/polars/io.ts"
    end

    subgraph "Data Types"
        DT{DateTime}:::type
        click DT "https://github.com/pola-rs/nodejs-polars/blob/main/polars/series/datetime.ts"
        STR{Strings}:::type
        click STR "https://github.com/pola-rs/nodejs-polars/blob/main/polars/series/string.ts"
        LST{Lists}:::type
        click LST "https://github.com/pola-rs/nodejs-polars/blob/main/polars/series/list.ts"
        STRUCT{Structs}:::type
        click STRUCT "https://github.com/pola-rs/nodejs-polars/blob/main/polars/series/struct.ts"
        TS_TYPES{TypeScript Types}:::type
        click TS_TYPES "https://github.com/pola-rs/nodejs-polars/tree/main/polars/datatypes/"
    end

    subgraph "Node.js Bindings Layer"
        CORE_BIND[Core Bindings]:::bridge
        click CORE_BIND "https://github.com/pola-rs/nodejs-polars/blob/main/src/lib.rs"
        DF_BIND[DataFrame Bindings]:::bridge
        click DF_BIND "https://github.com/pola-rs/nodejs-polars/blob/main/src/dataframe.rs"
        SER_BIND[Series Bindings]:::bridge
        click SER_BIND "https://github.com/pola-rs/nodejs-polars/blob/main/src/series.rs"
        TYPE_CONV[Type Conversions]:::bridge
        click TYPE_CONV "https://github.com/pola-rs/nodejs-polars/blob/main/src/conversion.rs"
        RUST_TYPES[Rust Types]:::bridge
        click RUST_TYPES "https://github.com/pola-rs/nodejs-polars/blob/main/src/datatypes.rs"
    end

    subgraph "Processing Engines"
        LAZY_TS[[Lazy Evaluation TS]]:::engine
        click LAZY_TS "https://github.com/pola-rs/nodejs-polars/tree/main/polars/lazy/"
        LAZY_RS[[Lazy Evaluation Rust]]:::engine
        click LAZY_RS "https://github.com/pola-rs/nodejs-polars/tree/main/src/lazy/"
        SQL_BE[[SQL Backend]]:::engine
        click SQL_BE "https://github.com/pola-rs/nodejs-polars/blob/main/src/sql.rs"
    end

    subgraph "I/O System"
        IO_IMPL[(I/O Implementation)]:::io
        click IO_IMPL "https://github.com/pola-rs/nodejs-polars/blob/main/src/file.rs"
        CSV[(CSV)]:::io
        JSON[(JSON)]:::io
        FEATHER[(Feather)]:::io
        TSV[(TSV)]:::io
    end

    subgraph "Platform Builds"
        DARWIN[/Darwin/]:::platform
        click DARWIN "https://github.com/pola-rs/nodejs-polars/tree/main/npm/darwin-x64/"
        LINUX[/Linux/]:::platform
        click LINUX "https://github.com/pola-rs/nodejs-polars/tree/main/npm/linux-x64-gnu/"
        WINDOWS[/Windows/]:::platform
        click WINDOWS "https://github.com/pola-rs/nodejs-polars/tree/main/npm/win32-x64-msvc/"
    end

    %% Connections
    TS_API --> |uses| DF
    TS_API --> |uses| SO
    TS_API --> |uses| CF
    TS_API --> |uses| SQL_IF
    TS_API --> |uses| IO_IF

    DF & SO & SQL_IF --> |interact with| CORE_BIND
    CORE_BIND --> |uses| DF_BIND
    CORE_BIND --> |uses| SER_BIND
    CORE_BIND --> |uses| TYPE_CONV

    IO_IF --> IO_IMPL
    IO_IMPL --> CSV & JSON & FEATHER & TSV

    TS_TYPES --> |converts via| TYPE_CONV
    TYPE_CONV --> RUST_TYPES

    SQL_IF --> SQL_BE
    LAZY_TS --> LAZY_RS

    DT & STR & LST & STRUCT --> |type system| TS_TYPES

    classDef api fill:#3498db,stroke:#2980b9,color:white
    classDef io fill:#2ecc71,stroke:#27ae60,color:white
    classDef type fill:#f1c40f,stroke:#f39c12,color:black
    classDef engine fill:#e74c3c,stroke:#c0392b,color:white
    classDef bridge fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef platform fill:#9b59b6,stroke:#8e44ad,color:white
```
