# aghasemi/streamlit_js_eval architecture

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

## Overview

##### Main Components

a) Core Components:
- Streamlit Application Layer
- Streamlit-JS-Eval Component
- Browser JavaScript Runtime
- Web APIs

##### Component Relationships

**[Streamlit Application]**
- ↕
**[Streamlit-JS-Eval Component]**
- ↕
**[Browser JavaScript Runtime]**
- ↕
**[Web APIs (Geolocation, Clipboard, etc.)]**

##### Specific Implementation Details

- Rectangles for main components (Streamlit App, SJE Component)
- Rounded rectangles for runtime environments (Browser JS Runtime)
- Hexagons for APIs and interfaces (Web APIs)

- Blue: Streamlit components
- Yellow: JavaScript-related components
- Green: Web APIs
- Grey: Runtime environments

##### Specific Elements

**[Streamlit App Layer]**
- Python function calls (streamlit_js_eval)
- Helper functions (get_geolocation, get_page_location)

**[Streamlit-JS-Eval Component]**
- JavaScript expression evaluator
- Component initialization
- State management (key handling)

**[Browser JavaScript Runtime]**
- Expression evaluation
- Result serialization

**[Web APIs]**
- Screen properties
- Geolocation
- Page location
- Other browser APIs

##### Notes Section

A notes section mentioning:
- Known limitations (st.button issues)
- Version-specific features
- Browser compatibility considerations

Remember to emphasize the bidirectional nature of the communication between Streamlit and the browser's JavaScript environment, as this is crucial for understanding how the component operates.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        SA["Streamlit Application"]:::streamlit
    end

    subgraph "Component Layer"
        SJE["Streamlit-JS-Eval Component"]:::component
        Init["Component Initialization"]:::component
        State["State Management"]:::component
    end

    subgraph "Runtime Layer"
        JSR["Browser JavaScript Runtime"]:::runtime
        Eval["Expression Evaluator"]:::runtime
        Serial["Result Serialization"]:::runtime
    end

    subgraph "Web APIs Layer"
        Screen["Screen Properties"]:::api
        Geo["Geolocation"]:::api
        Page["Page Location"]:::api
        Other["Other Browser APIs"]:::api
    end

    %% Connections
    SA -->|"Python Calls"| SJE
    SJE -->|"Initialize"| Init
    SJE -->|"Manage State"| State
    Init -->|"Setup"| JSR
    SJE -->|"Evaluate"| Eval
    Eval -->|"Process"| Serial
    Serial -->|"Return"| SJE

    JSR -->|"Access"| Screen
    JSR -.->|"Async Call"| Geo
    JSR -->|"Query"| Page
    JSR -->|"Interface"| Other

    %% Styles
    classDef streamlit fill:#3366FF,color:white
    classDef component fill:#6699FF,color:white
    classDef runtime fill:#FFB366,color:black
    classDef api fill:#66CC66,color:white

    %% Click Events
    click SA "https://github.com/aghasemi/streamlit_js_eval/blob/master/example.py"
    click SJE "https://github.com/aghasemi/streamlit_js_eval/blob/master/streamlit_js_eval/__init__.py"
    click JSR "https://github.com/aghasemi/streamlit_js_eval/blob/master/streamlit_js_eval/index.html"

    %% Legend
    subgraph Legend
        L1["Streamlit Components"]:::streamlit
        L2["Component Layer"]:::component
        L3["Runtime Elements"]:::runtime
        L4["Web APIs"]:::api
        L5["--> Sync Call"]
        L6["--> Async Call"]
    end
```
