Status: Draft Target: v1.0 (Evolution from Library to Framework)
Transform violetear into a hybrid, full-stack Python web framework. It will support both Server-Side Rendering (SSR) for high-performance static content and Client-Side Rendering (CSR) via Pyodide for rich interactivity. The architecture remains modular: the core library stays zero-dependency, while the framework layer (violetear.app) leverages FastAPI and standard WebAssembly tools.
Objective: Prepare the codebase for modern standards and faster iteration.
- Dependency Update: Bump minimum Python version to 3.12+.
- Migrate to
uv: Replacepoetrywithuvfor lightning-fast package management and CI/CD resolution. - Project Structure: Establish the folder structure for the new modules (
violetear.app,violetear.client).
Objective: Build a robust engine for serving Server-Side Rendered applications with zero unused CSS.
- Add
fastapianduvicornas optional extras (pip install violetear[server]).
- Initialization: Create the
Appclass that wraps aFastAPIinstance. - Routing: Implement the
@app.route(path)decorator.- Handle standard
GETrequests returningDocumentobjects. - Handle standard
POSTform submissions.
- Handle standard
- Asset Registry: Implement
app.add_style(name, sheet).- Automatically mount a route to serve these rendered stylesheets from memory.
- Provide helpers to inject
<link>tags for registered styles into Documents.
- Server Side: Implement
app.mount_static(dir, path)and auto-discover a./staticfolder. - Markup Side: Extend
Documentinvioletear/markup.py:- Add
.link_css(url)for CDNs/local files. - Add
.add_script(src)for external JS.
- Add
- HTML Helpers: Extend
Elementinvioletear/markup.py:- Add
.link(href)helper for anchors. - Add
.form(action, method)and.input()helpers.
- Add
- Scanner: Implement
Document.get_used_classes()to scan the rendered element tree. - Filter: Implement
StyleSheet.render_subset(classes)invioletear/stylesheet.py. - Optimization: Update
App.render_documentto inline only the used CSS for SSR routes, eliminating unused bytes.
- Create
violetear.presets.Tailwindclass usingUtilitySystem.- Pre-configure standard Tailwind scales (spacing, colors, typography).
- Allow users to customize defaults (colors/screens) in the constructor.
Objective: Enable "Smart Hydration" where Python runs in the browser only when needed.
- Update
Elementto support event listeners.- Implement
.on("click", func)and.onclick(func). - Server Behavior: Serialize function name to
data-py-on-clickattribute. - Client Behavior: Bind the actual Python callable to the DOM.
- Implement
- Hydration Script: Create a generic Python script (to run in Pyodide) that:
- Scans the DOM for
data-py-on-*attributes. - Maps attributes to loaded Python functions from the user's bundle.
- Scans the DOM for
- RPC Stubs: Create the client-side mechanism to intercept calls to
@app.serverfunctions and performfetch()requests.
- Detection Logic: Update
Appto inspect the generatedDocument.- If
data-py-on-*attributes exist -> Inject Pyodide bootstrap + Client Bundle. - If no attributes exist -> Serve pure HTML (SSR Mode).
- If
Objective: Turn apps into installable software with offline capabilities.
- Manifest Generator: Create a class to generate
manifest.jsonfromAppmetadata. - Route Configuration: Add
pwa=Trueparameter to@app.route.- Serves the manifest linked to that specific scope.
- Injects
<meta>tags for theme color and icons.
- Service Worker: Implement a default Service Worker generator.
- Automatically cache the Pyodide runtime and the app's registered CSS/JS assets (from the Asset Registry).