How flet-dev/flet works
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.