reflex-state-and-architecture

Guides Reflex.dev state design, event handlers, repositories, and feature package architecture.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/jenreh/project-kit-template --skill reflex-state-and-architecture-jenreh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: reflex-state-and-architecture
Source: https://github.com/jenreh/project-kit-template/tree/main/.agents/agent-skills/skills/reflex-state-and-architecture
Command: npx skills add https://github.com/jenreh/project-kit-template --skill reflex-state-and-architecture-jenreh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires reflex, appkit_mantine, appkit_commons, appkit_user, sqlalchemy, pandas.

What problem does it solve? Building Reflex.dev applications without consistent patterns leads to mixed concerns, broken reactivity, and state bugs such as storing SQLAlchemy entities in state or mutating state without yielding. This Skill provides canonical patterns for structuring Reflex apps with the appkit ecosystem. ## Core Features & Use Cases - State Management Patterns: Covers rx.State subclasses, computed vars with @rx.var, async event handlers, background tasks with @rx.event(background=True), and LocalStorage persistence. - Architecture Conventions: Defines the feature package layout (backend/, state/, components/, pages.py), page factory pattern, service registry dependency injection, and BaseRepository-based data access. - Form Validation & Anti-Patterns: Provides an isolated validation state pattern with per-field errors and async uniqueness checks, plus a table of common mistakes and their corrections. - Use Case: When adding a new feature to a Reflex app, follow the annotated examples in examples/ to create the state class, components, page factory, and repository without architectural drift. ## Quick Start Ask the AI to create a new Reflex feature with a state class, page factory, and repository following the reflex-state-and-architecture patterns.

Frequently Asked Questions about reflex-state-and-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure state management in a Reflex.dev app?

Create rx.State subclasses with typed variables and defaults, use @rx.var for derived values, and @rx.event for handlers. Async handlers should yield after each mutation to push updates to the frontend, and background tasks must mutate state inside async with self blocks.

How do I implement form validation in Reflex?

Use a dedicated rx.State subclass holding string fields and per-field error strings. Decorate validators with @rx.event for on_blur binding, expose is_form_valid as @rx.var for the submit button, and call validate_all before submitting.

Can I store SQLAlchemy models directly in Reflex state?

No, storing SQLAlchemy entities in Reflex state fails because lazy-loaded relationships break outside the session context. Convert entities to rx.Base display models using a to_dict method before assigning them to state variables.

Why does my Reflex background task not update the UI?

Background tasks decorated with @rx.event(background=True) only push updates when you yield after mutations inside async with self blocks. Also invoke them by yielding the method reference, never by calling them directly from another handler.

When should I use get_asyncdb_session instead of rx.asession?

Use get_asyncdb_session for all repository access, especially in background tasks and callbacks outside the Reflex request lifecycle. rx.asession only works within the request lifecycle and fails in background processors.