# davesnx/styled-ppx architecture

> Architecture diagram of the GitHub repository davesnx/styled-ppx, 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/davesnx/styled-ppx
- Repository: https://github.com/davesnx/styled-ppx

## Overview

##### Main Components

a. Core Components:
- PPX Transformation Engine (packages/ppx)
- CSS Property Parser (packages/css-property-parser)
- CSS Spec Parser (packages/css-spec-parser)
- Runtime Libraries (packages/runtime)
- Melange Runtime
- Native Runtime
- ReScript Runtime

b. Supporting Components:
- Parser System (packages/parser)
- String Interpolation Engine (packages/string_interpolation)
- Editor Integration (packages/editors)
- Testing Infrastructure (various test directories)

##### Component Relationships

**Source Code → PPX Transform → Runtime → Final Output**
- ↑
- (uses)
- CSS Parser Components

##### Detailed Architecture

**┌─────────────────────────┐**
- Source Code        │
- (.re/.res files with   │
- styled components)    │
- ┬──────────┘
- ↓
**┌─────────────────────────┐**
- PPX Transform        │
- CSS Property Parser  │
- CSS Spec Parser      │
- String Interpolation │
- ┬──────────┘
- ↓
**┌─────────────────────────┐**
- Runtime Libraries      │
- ┌─────────────────┐   │
- Melange      │   │
- ┘   │
- ┌─────────────────┐   │
- Native       │   │
- ┘   │
- ┌─────────────────┐   │
- ReScript     │   │
- ┘   │
- ┬──────────┘
- ↓
**┌─────────────────────────┐**
- Final Output         │
- (Compiled JavaScript   │
- or Native Code)       │
- ┘

##### Additional Elements

Supporting components in a side panel:
- Editor Support (VSCode, Vim)
- Testing Infrastructure
- Build System (dune)

##### Key Interactions to Highlight

- How the PPX transformer processes the source code
- How the CSS parsers feed into the transformation
- Demonstrate the different runtime paths for Melange, Native, and ReScript
- How editor support integrates with the development workflow

##### Technical Details

- Emotion integration for web output
- CSS property parsing and validation flow
- Type-safety mechanisms
- Build system integration

##### The type-safety aspects of the system

This system design should help developers understand both the high-level architecture and the detailed interactions between components while maintaining a clear view of the project's main purpose: providing type-safe styled components for ReScript, Melange, and Native OCaml development.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        SourceCode["Source Code<br/>(.re/.res files)"]:::input
    end

    subgraph "PPX Transform"
        PPX["PPX Transformation<br/>Engine"]:::transform
        click PPX "https://github.com/davesnx/styled-ppx/tree/main/packages/ppx/src/"
        Generator["Generator"]:::transform
        click Generator "https://github.com/davesnx/styled-ppx/blob/main/packages/ppx/src/generate.re"
    end

    subgraph "Parser Components"
        CSSPropParser["CSS Property<br/>Parser"]:::parser
        click CSSPropParser "https://github.com/davesnx/styled-ppx/tree/main/packages/css-property-parser/lib/"
        CSSSpecParser["CSS Spec<br/>Parser"]:::parser
        click CSSSpecParser "https://github.com/davesnx/styled-ppx/tree/main/packages/css-spec-parser/lib/"
        ParserSystem["Parser<br/>System"]:::parser
        click ParserSystem "https://github.com/davesnx/styled-ppx/tree/main/packages/parser/lib/"
        StringInterp["String<br/>Interpolation"]:::parser
        click StringInterp "https://github.com/davesnx/styled-ppx/tree/main/packages/string_interpolation/src/"
    end

    subgraph "Runtime Layer"
        direction TB
        MelangeRT["Melange<br/>Runtime"]:::runtime
        click MelangeRT "https://github.com/davesnx/styled-ppx/tree/main/packages/runtime/melange/"
        NativeRT["Native<br/>Runtime"]:::runtime
        click NativeRT "https://github.com/davesnx/styled-ppx/tree/main/packages/runtime/native/"
        ReScriptRT["ReScript<br/>Runtime"]:::runtime
        click ReScriptRT "https://github.com/davesnx/styled-ppx/tree/main/packages/runtime/rescript/"
    end

    subgraph "Development Tools"
        direction TB
        VSCode["VSCode<br/>Extension"]:::tools
        click VSCode "https://github.com/davesnx/styled-ppx/tree/main/packages/editors/vscode/"
        Vim["Vim<br/>Plugin"]:::tools
        click Vim "https://github.com/davesnx/styled-ppx/tree/main/packages/editors/vim/"
        Testing["Testing<br/>Infrastructure"]:::tools
        click Testing "https://github.com/davesnx/styled-ppx/tree/main/packages/ppx/test/"
    end

    subgraph Output
        FinalOutput["Final Output<br/>(JS/Native Code)"]:::output
    end

    SourceCode --> PPX
    PPX --> Generator
    Generator --> |Transform| MelangeRT & NativeRT & ReScriptRT
    
    CSSPropParser & CSSSpecParser & ParserSystem & StringInterp --> PPX
    
    MelangeRT & NativeRT & ReScriptRT --> FinalOutput
    
    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef transform fill:#2ecc71,stroke:#27ae60,color:white
    classDef parser fill:#e67e22,stroke:#d35400,color:white
    classDef runtime fill:#9b59b6,stroke:#8e44ad,color:white
    classDef tools fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef output fill:#e74c3c,stroke:#c0392b,color:white

    subgraph Legend
        direction TB
        L1["Input"]:::input
        L2["Transform"]:::transform
        L3["Parser"]:::parser
        L4["Runtime"]:::runtime
        L5["Tools"]:::tools
        L6["Output"]:::output
    end
```
