# flet-dev/flet architecture

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

- Interactive diagram: https://gitdiagram.com/flet-dev/flet
- Repository: https://github.com/flet-dev/flet

## Overview

##### Project Type and Purpose
- Flet is a framework that lets developers create real-time, multi-user apps (web, mobile, and desktop) in one language (Python today, with other languages coming). It’s purposely built as a monolithic, stateful “all-in-one” app architecture where you write a single Python application and get a real-time SPA without needing a separate frontend.
- It leverages Flutter under the hood for building rich user interfaces across platforms, so the UI components are powered by Flutter “controls” that wrap Flutter widgets but are exposed in a simplified, imperative programming model.

##### Main Components
a. Client / Frontend:
- Located in the “client” directory: Contains a Flutter project structure with platform-specific folders (Android, iOS, macos, windows, linux, web).
- This part encapsulates the presentation layer, asset management, platform-specific configurations, and bootstrapping for Flutter.
b. Core Flet Framework / SDK:
- Found in packages (e.g., packages/flet) and in the sdk/python folder.
- Includes the core libraries that define Flet’s controls, protocol messages, routing, and state management. The files under packages/flet/lib/src/controls, models, protocol, utils, and routing represent the fundamental classes and utilities.
c. Command-line Interface and Backends:
- The sdk/python/packages directory contains several subpackages (flet-cli, flet-desktop, flet-web) which serve as entry points for running or packaging apps.
- Flet’s CLI commands, server protocols, and deployment tools reside here, and they work together to manage the app’s runtime.
d. Communication and Protocol Layer:
- Within packages and the SDK, there are multiple protocol-related files (e.g., flet_server_protocol_xxx) that define how the client (Flutter) communicates with the backend (Python) – typically using web sockets, TCP models and even JavaScript I/O for web integration.
- This layer is critical because it seamlessly connects the Python business logic with the Flutter-prompted UI.
e. CI, Docs, and Assets:
- The “ci” directory houses scripts for building, deploying, or patching configurations. This shows that the project is built with continuous integration in mind.

##### Relationships and Data Flow
- How the Flet CLI and auxiliary tools (flet-desktop, flet-web) interact with the framework, offering various deployment or packaging routes.
- It’s also useful to note that while the Flet app is a monolith, it still internally distinguishes presentation, business logic, and protocol handling – conveying a “layered” approach.

##### Architectural Patterns and Principles
- “batteries-included” nature; the server, assets hosting, and connections are embedded within the framework.
- Separation of concerns: the Flutter UI (frontend) is clearly isolated from the Python backend along with a defined protocol for their communication.

##### Detail Level
- Do not shy away from breaking the project into as many meaningful components as possible – clarity in separation of responsibilities is beneficial.

– The multi-platform Flutter client residing in the “client” directory.
– The core Flet framework’s library and control definitions from “packages/flet” and corresponding Python SDK modules in “sdk/python”.
– The communication layer that handles protocol messages between the UI and the backend.
– The CLI and deployment tools that launch and package the app.

This structured approach will help stakeholders quickly understand the high-level design, responsibilities of each subsystem, and how user actions flow through the entire Flet system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Level: User Interaction
    User["User Interaction"]:::user

    %% Client / Frontend Layer
    subgraph "Client / Frontend (Flutter)"
        Client["Flutter Client (Multi-platform UI)"]:::frontend
    end

    %% Communication / Protocol Layer
    subgraph "Communication / Protocol Layer"
        DartProto["Dart Protocol Handler"]:::protocol
        PythonProto["Python Protocol Handler"]:::protocol
    end

    %% Core Flet Framework
    subgraph "Flet Core"
        DartCore["Dart Library (Controls, Models, Utils, Routing)"]:::backend
        PythonSDK["Python SDK (Application Logic)"]:::backend
    end

    %% CLI & Deployment Tools
    subgraph "CLI & Deployment Tools"
        CLI["Flet CLI"]:::cli
        Desktop["Flet Desktop"]:::cli
        Web["Flet Web"]:::cli
    end

    %% CI, Docs, and Assets
    subgraph "CI / Docs / Assets"
        CI["CI Scripts"]:::external
        Docs["Documentation"]:::external
        Media["Media & Diagrams"]:::external
    end

    %% Data Flow Arrows
    User -->|"triggers"| Client
    Client -->|"sends events"| DartProto
    DartProto -->|"transmits"| PythonProto
    PythonProto -->|"updates"| PythonSDK
    PythonSDK -->|"utilizes"| DartCore

    CLI -->|"manages runtimes"| PythonSDK
    Desktop -->|"packages app"| PythonSDK
    Web -->|"packages app"| PythonSDK

    %% Styles
    classDef frontend fill:#fceabb,stroke:#e8b433,stroke-width:2px;
    classDef backend fill:#c2e7da,stroke:#34a853,stroke-width:2px;
    classDef protocol fill:#ffdfba,stroke:#f57c00,stroke-width:2px;
    classDef cli fill:#d0e1ff,stroke:#0b5394,stroke-width:2px;
    classDef external fill:#f8cecc,stroke:#e06666,stroke-width:2px;
    classDef user fill:#e7e7ff,stroke:#8e44ad,stroke-width:2px;

    %% Click Events
    click Client "https://github.com/flet-dev/flet/tree/main/client"
    click DartCore "https://github.com/flet-dev/flet/tree/main/packages/flet/lib/src"
    click PythonSDK "https://github.com/flet-dev/flet/tree/main/sdk/python/packages/flet/src/flet"
    click CLI "https://github.com/flet-dev/flet/tree/main/sdk/python/packages/flet-cli"
    click Desktop "https://github.com/flet-dev/flet/tree/main/sdk/python/packages/flet-desktop"
    click Web "https://github.com/flet-dev/flet/tree/main/sdk/python/packages/flet-web"
    click DartProto "https://github.com/flet-dev/flet/tree/main/packages/flet/lib/src/protocol"
    click PythonProto "https://github.com/flet-dev/flet/blob/main/sdk/python/packages/flet/src/flet/core/protocol.py"
    click CI "https://github.com/flet-dev/flet/tree/main/ci"
    click Docs "https://github.com/flet-dev/flet/tree/main/docs"
    click Media "https://github.com/flet-dev/flet/tree/main/media"
```
