# vincenzobaz/spark-scala3 architecture

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

- Interactive diagram: https://gitdiagram.com/vincenzobaz/spark-scala3
- Repository: https://github.com/vincenzobaz/spark-scala3

## Overview

Key Components to Include:

##### Main Library Modules
a. "Encoders Module" (from /encoders directory)
b. "UDF Module" (from /udf directory)

##### Integration Layer
- How the library integrates with Apache Spark:
- Connections to both Spark SQL and Spark Core
- Cross-version compatibility (Scala 2.13 → Scala 3)

##### Component Details

For the Encoders Module:
- Derivation pipeline:
a. EncoderDerivation (main entry point)
b. Serializer component
c. Deserializer component
d. Helper utilities

For the UDF Module:
- Display:
a. UDF registration mechanism
b. Exporter functionality
c. Connection to Spark SQL functions

- [Client Application Layer]
- ↓
- [Spark-Scala3 Library Layer]
- ↓
- [Apache Spark Integration Layer]

##### Connection Types
- Double lines: API boundaries

Specific Elements to Include:

##### Entry Points
- `scala3encoders.given` import point
- `scala3udf.Udf` entry point

##### Integration Flows
- How encoders are derived at compile-time
- UDF registration flow to Spark Session

##### Testing Components
- A separate section showing test infrastructure
- Example implementations to main components

Key Relationships to Highlight:

##### Compile-Time vs Runtime
- Clearly distinguish between compile-time derivation (encoders)
- Runtime registration (UDFs)

##### Version Compatibility
- Spark 3.2+ requirement
- Scala 2.13 to Scala 3 bridging

##### External Dependencies
- Apache Spark dependencies
- Build tool integration

Additional Guidelines:

##### Notes about
- Version compatibility requirements
- Important configuration points
- Common usage patterns

##### Creating separate detailed views for
- Encoder derivation pipeline
- UDF registration process
- Example implementations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        ClientApp["Client Application"]:::client
        Examples["Example Implementations"]:::client
    end

    subgraph Library["Spark-Scala3 Library Layer"]
        subgraph Encoders["Encoders Module"]
            EncoderEntry["Encoder Entry Point"]:::core
            EncoderDeriv["Encoder Derivation"]:::core
            Serializer["Serializer"]:::core
            Deserializer["Deserializer"]:::core
            HelperUtils["Helper Utilities"]:::core
        end

        subgraph UDFs["UDF Module"]
            UdfEntry["UDF Entry Point"]:::core
            UdfExporter["UDF Exporter"]:::core
            UdfReg["UDF Registration"]:::core
        end
    end

    subgraph Testing["Testing Infrastructure"]
        EncoderTests["Encoder Tests"]:::test
        UdfTests["UDF Tests"]:::test
    end

    subgraph Spark["Apache Spark Integration Layer"]
        SparkSQL["Spark SQL"]:::spark
        SparkCore["Spark Core"]:::spark
    end

    %% Relationships
    ClientApp --> EncoderEntry
    ClientApp --> UdfEntry
    Examples --> EncoderEntry
    Examples --> UdfEntry

    EncoderEntry --> EncoderDeriv
    EncoderDeriv --> Serializer
    EncoderDeriv --> Deserializer
    Serializer --> HelperUtils
    Deserializer --> HelperUtils

    UdfEntry --> UdfExporter
    UdfEntry --> UdfReg
    UdfReg --> SparkSQL

    EncoderDeriv --> SparkCore
    EncoderDeriv --> SparkSQL

    EncoderTests -.-> Encoders
    UdfTests -.-> UDFs

    %% Click Events
    click Encoders "https://github.com/vincenzobaz/spark-scala3/tree/main//encoders/src/main/scala/scala3encoders"
    click EncoderEntry "https://github.com/vincenzobaz/spark-scala3/blob/main//encoders/src/main/scala/scala3encoders/EncoderDerivation.scala"
    click Serializer "https://github.com/vincenzobaz/spark-scala3/blob/main//encoders/src/main/scala/scala3encoders/derivation/Serializer.scala"
    click Deserializer "https://github.com/vincenzobaz/spark-scala3/blob/main//encoders/src/main/scala/scala3encoders/derivation/Deserializer.scala"
    click HelperUtils "https://github.com/vincenzobaz/spark-scala3/blob/main//encoders/src/main/scala/scala3encoders/derivation/Helper.scala"
    click UDFs "https://github.com/vincenzobaz/spark-scala3/tree/main//udf/src/main/scala/scala3udf"
    click UdfEntry "https://github.com/vincenzobaz/spark-scala3/blob/main//udf/src/main/scala/scala3udf/Udf.scala"
    click UdfExporter "https://github.com/vincenzobaz/spark-scala3/blob/main//udf/src/main/scala/scala3udf/Exporter.scala"
    click EncoderTests "https://github.com/vincenzobaz/spark-scala3/blob/main//encoders/src/test/scala/sql/EncoderDerivationSpec.scala"
    click UdfTests "https://github.com/vincenzobaz/spark-scala3/blob/main//udf/src/test/scala/scala3udf/UdfSpec.scala"
    click Examples "https://github.com/vincenzobaz/spark-scala3/tree/main//examples/src/main/scala"

    %% Styles
    classDef client fill:#FFE5CC,stroke:#FF9933
    classDef core fill:#CCE5FF,stroke:#3399FF
    classDef spark fill:#E5FFCC,stroke:#66CC00
    classDef test fill:#FFE6E6,stroke:#FF6666

    %% Legend
    subgraph Legend
        Client_Component["Client Component"]:::client
        Core_Component["Core Component"]:::core
        Spark_Component["Spark Component"]:::spark
        Test_Component["Test Component"]:::test
    end
```
