# phoenixframework/phoenix_live_view architecture

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

## Overview

##### Main Components

a) Client-Side Layer:
- Browser Runtime (with WebSocket/LongPolling support)
- JavaScript Client Library (found in assets/js/phoenix_live_view/)
- DOM Management System
- Upload Handlers
- Event Handlers

b) Server-Side Layer:
- LiveView Core Engine
- Component System
- Router & Channel System
- Upload Management
- HTML Rendering Engine
- State Management
- WebSocket/LongPolling Handlers

##### Key Relationships to Highlight

a) Data Flow:
- Initial HTTP Request → Static Render
- WebSocket Connection Establishment
- Bi-directional Real-time Updates
- DOM Diff Generation and Patching
- File Upload Streams

b) Component Integration:
- LiveView Components ↔ Phoenix Components
- Template Rendering System
- Event Handling System

##### Architectural Patterns to Emphasize

**[Client Browser]**
- ↑↓ WebSocket/HTTP
**[Transport Layer]**
- ↑↓
**[Phoenix LiveView Core]**
- ↑↓
**[Phoenix Framework]**
- ↑↓
**[Elixir Runtime]**

##### Implementation Details

- Rectangles: Core components
- Hexagons: Integration points
- Circles: Event systems

- Blue: Client-side components
- Green: Server-side components
- Yellow: Communication channels
- Purple: State management
- Orange: File handling systems

##### Key Features to Highlight

- Real-time Updates System
- Component Lifecycle
- State Management
- Upload Management
- Error Handling
- Testing Infrastructure

##### Technical Elements

Specific components:
- LiveSocket (lib/phoenix_live_view/live_socket.js)
- Channel System (lib/phoenix_live_view/channel.ex)
- DOM Patch System (assets/js/phoenix_live_view/dom_patch.js)
- Upload Management (lib/phoenix_live_view/upload/)
- Component System (lib/phoenix_component/)

##### Integration Points

Connections with:
- Phoenix Framework
- WebSocket System
- Browser DOM
- File System
- External Services

For tools, I recommend using either:
- LucidChart for its professional-grade diagramming capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Browser Runtime"]
        JSLib["JavaScript Client Library"]:::jslib
        DOMSys["DOM Management System"]:::domsys
        UploadH["Upload Handlers"]:::uploadh
        EventH["Event Handlers"]:::eventh
    end

    subgraph Transport["Transport Layer"]
        WS["WebSocket Connection"]
        LP["Long Polling"]
        HTTP["HTTP Initial Request"]
    end

    subgraph Core["Phoenix LiveView Core"]
        Engine["LiveView Core Engine"]:::engine
        CompSys["Component System"]:::compsys
        Router["Router & Channel System"]:::router
        UploadM["Upload Management"]:::uploadm
        HTMLRender["HTML Rendering Engine"]:::htmlrender
        StateM["State Management"]:::statem
        WSHandler["WebSocket Handler"]:::wshandler
    end

    subgraph Base["Phoenix & Elixir Layer"]
        Phoenix["Phoenix Framework"]
        Elixir["Elixir Runtime"]
        Test["Testing Infrastructure"]:::test
    end

    %% Client Layer Connections
    Browser --> JSLib
    JSLib --> DOMSys
    JSLib --> UploadH
    JSLib --> EventH

    %% Transport Layer Connections
    Browser <--> WS
    Browser <--> LP
    Browser --> HTTP

    %% Transport to Core Connections
    WS <--> WSHandler
    LP <--> WSHandler
    HTTP --> Router

    %% Core Layer Connections
    Engine --> CompSys
    Engine --> Router
    Engine --> UploadM
    Engine --> HTMLRender
    Engine --> StateM
    WSHandler --> Engine

    %% Base Layer Connections
    Engine --> Phoenix
    Phoenix --> Elixir
    Test --> Engine

    %% Styling
    classDef jslib fill:#2196F3,color:white
    classDef domsys fill:#2196F3,color:white
    classDef uploadh fill:#FF9800,color:white
    classDef eventh fill:#2196F3,color:white
    classDef engine fill:#4CAF50,color:white
    classDef compsys fill:#4CAF50,color:white
    classDef router fill:#4CAF50,color:white
    classDef uploadm fill:#FF9800,color:white
    classDef htmlrender fill:#4CAF50,color:white
    classDef statem fill:#9C27B0,color:white
    classDef wshandler fill:#FFEB3B,color:black
    classDef test fill:#795548,color:white

    click JSLib "https://github.com/phoenixframework/phoenix_live_view/tree/main/assets/js/phoenix_live_view/"
    click DOMSys "https://github.com/phoenixframework/phoenix_live_view/blob/main/assets/js/phoenix_live_view/dom.js"
    click UploadH "https://github.com/phoenixframework/phoenix_live_view/blob/main/assets/js/phoenix_live_view/live_uploader.js"
    click EventH "https://github.com/phoenixframework/phoenix_live_view/blob/main/assets/js/phoenix_live_view/hooks.js"
    click Engine "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view.ex"
    click CompSys "https://github.com/phoenixframework/phoenix_live_view/tree/main/lib/phoenix_component/"
    click Router "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view/router.ex"
    click UploadM "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view/upload.ex"
    click HTMLRender "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view/html_engine.ex"
    click StateM "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view/socket.ex"
    click WSHandler "https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_live_view/channel.ex"
    click Test "https://github.com/phoenixframework/phoenix_live_view/tree/main/lib/phoenix_live_view/test/"
```
