Introducing a new way to review your PRs.

Read the announcement

reflex-dev / reflex

🕸️ Web apps in pure Python 🐍

View on GitHub

30 documents · Updated Nov 23, 2026

docs / developer-workflows

Developer workflows and extensibility

Reflex gives an engineer one path from a new project to a running and deployable web app. The path creates the project, prepares its frontend, compiles the Python app into browser output, runs the app locally, exports deployable artifacts, and supports extension through plugins and custom component packages. See CLI and project workflows, deployment and hosting, and extensions and custom components for focused views.

Workflow map

The developer workflow connects project setup to two runtime targets: a local process pair for development and a production package for hosting. The same app settings guide both paths so local checks can expose problems before deployment.

The main flow is:

flowchart LR
    A[Create project] --> B[Resolve app settings]
    B --> C[Compile app]
    C --> D{Run target}
    D -->|Development| E[Reload frontend and backend]
    D -->|Preview or production| F[Build frontend and serve app]
    C --> G[Export frontend and backend]
    G --> H[Deploy or self-host]
    B --> I[Load plugins and extensions]
    I --> C

Project creation

Project creation gives an engineer a runnable Reflex app with the files and frontend support needed for the next command. The initializer can use a default starter or a named or remote template. It then adapts the app name and imports to the new project.

Project initialization

reflex init validates the app name and local prerequisites before it creates the Python app, rxconfig.py, dependency files, and the .web frontend workspace. It also creates project guidance and ignore rules. A project with pyproject.toml follows a different dependency path from one with requirements.txt.

The initializer keeps frontend dependency state usable across fresh setup. It persists package metadata and lockfiles in the project, mirrors them into .web for frontend tools, and saves changes back after frontend work. It also refreshes framework-managed guidance while preserving user content.

Version checks are advisory. The CLI stores a separate timestamp for each checked package in the project state. A successful check stays fresh for one day. A failed network attempt uses a one-hour cool-down so offline commands do not repeat the same wait.

References: reflex/reflex.py• L270-331 reflex/…/frontend_skeleton.py• L126-160 reflex/…/frontend_skeleton.py• L233-267 reflex/…/frontend_skeleton.py• L270-411 reflex/…/prerequisites.py• L86-186 reflex/…/prerequisites.py• L603-633 reflex/…/prerequisites.py• L762-819

Frontend workspace

The .web workspace is the handoff area between Python app definitions and the JavaScript tool chain. Initialization places the frontend template there, restores compatible dependency state, writes package and router settings, and creates the public asset area. Compile and build steps refresh generated files in this workspace rather than changing the app's Python source model.

The workspace also carries the frontend path and asset rules that connect browser routes to the configured app. Framework-owned package scripts and dependency overrides are refreshed while user metadata and dependency pins remain part of the project state.

References: reflex/…/frontend_skeleton.py• L270-411 reflex/…/frontend_skeleton.py• L452-494 reflex/…/frontend_skeleton.py• L496-538 reflex/…/frontend_skeleton.py• L541-617 reflex/…/frontend_skeleton.py• L619-671 reflex/…/path_ops.py• L257-367

Local execution

Local execution turns the configured app into processes that an engineer can inspect while editing. Development uses a frontend development server and a reloadable backend. Preview and production use built frontend output and can serve both sides from one port.

Development mode

reflex run compiles the app when the frontend is part of the run. It then starts the frontend and backend together. The frontend runs in a separate process while the backend serves the app module. A frontend-only run stays attached to that frontend process and stops it when the command exits.

File changes in selected reload paths restart the relevant backend process. Package changes can restart the frontend. The development backend records whether a worker is making its first startup or a later hot reload, even when the first compile fails. During reload, the supervisor keeps the listening socket available while a replacement worker starts, then releases it when no worker can serve requests. Clean worker stops are not treated as unexpected failures during supervisor shutdown. Compile workers also flush telemetry before they exit.

References: reflex/reflex.py• L366-415 reflex/reflex.py• L494-571 reflex/reflex.py• L715-769 reflex/…/exec.py• L41-87 reflex/…/exec.py• L239-369 reflex/…/exec.py• L591-638 reflex/…/exec.py• L654-745 reflex/…/exec.py• L748-984 reflex/…/exec.py• L1095-1154

Preview and production modes

Preview mode keeps backend reload behavior from development but serves a fresh, readable frontend build from the backend. Production builds the frontend once, skips a second compile in the backend process, and serves the result through a production server. The two parts can share one port.

The effective server-rendering setting can come from a run or build flag or from REFLEX_SSR. When no setting is provided, production enables route prerendering and development does not. The production server serves compiled static files with route-aware fallback behavior. It can compress assets and mount the frontend beside the backend. Development and production workers inherit the same resolved rendering setting.

References: reflex/reflex.py• L573-663 reflex/reflex.py• L665-795 reflex/reflex.py• L798-906 reflex/…/exec.py• L423-495 reflex/…/exec.py• L987-1210 reflex/…/exec.py• L1279-1315

Runtime selection

The run command can select the full stack or only one side. It also selects ports and the backend host. Configuration supplies a port only to the side that the command starts, so a stopped side does not silently affect validation. Preview and production require the frontend and backend to share a port when both run together. Production can also use a single-port layout through the run command.

References: reflex/reflex.py• L665-906 reflex/…/prerequisites.py• L691-707 reflex/…/exec.py• L987-1210

Compilation and packaging

Compilation is the shared preparation step for local preview, production runs, export, and deployment. It evaluates pages and component trees, collects frontend dependencies and generated files, then writes a frontend project that the JavaScript tool chain can build.

Application compilation

The compiler collects app pages and plugin pages before it evaluates them. It processes page trees, validates state and route results, writes generated frontend modules, installs requested packages, and updates router and entry files. A backend-only path can reuse compiled information without a full frontend compile.

When an app has a database and migration setup, compilation can check whether the schema matches the models after page evaluation. This integration remains outside the ordinary startup path until the app needs it. Page evaluation makes models imported by pages or plugin route hooks visible to migration checks.

References: reflex/…/prerequisites.py• L238-345 reflex/…/prerequisites.py• L408-445 reflex/…/prerequisites.py• L840-892 reflex/…/compiler.py• L1142-1190 reflex/…/compiler.py• L1191-1236 reflex/…/compiler.py• L1395-1439 reflex/…/migrations.py• L90-125

Database migration workflow

The database workflow keeps model changes and database schema changes in step. reflex db init creates the migration environment and an initial revision. reflex db makemigrations creates a revision only when model changes exist. reflex db migrate applies revisions and then checks the resulting schema. reflex db status shows migration history and the current database revision.

The workflow uses the app configuration for the database URL and loads the app so models are registered. It evaluates pages before revision generation and after migration where needed, so models that pages or plugin route hooks import lazily are included in schema checks. Older migration environments are upgraded in place while their previous env.py is retained as a backup. A custom migration environment reports its own failures rather than hiding them. Startup logs such a failure and continues, while a reflex db command exits with an error.

References: reflex/reflex.py• L1084-1233 reflex/…/prerequisites.py• L314-345 reflex/…/prerequisites.py• L840-892 reflex/…/migrations.py• L45-219

Production build

The production build turns the compiled frontend project into static output. It adds route-aware fallback files, lets active plugins process the final static tree, and can create compressed asset forms. The result can serve from a static host or beside the backend.

References: reflex/…/build.py• L194-300

Application export

reflex export packages the frontend and backend as separate deployable artifacts or leaves them unpacked. It sets the selected environment, compiles the app, prepares frontend dependencies, builds the production frontend, and creates the requested archives. This boundary lets managed hosting and self-managed infrastructure consume the same app output.

References: reflex/reflex.py• L939-1034 reflex/…/export.py• L19-117 reflex/…/build.py• L124-168

Deployment handoff

Deployment adds a host and an operational control plane to application export. The local CLI resolves authentication and target settings, prepares the same production artifacts, and sends them to a managed Reflex service or exposes them for a self-managed target. Read deployment and hosting for provider, secret, rollout, and recovery details.

Managed deployment

reflex deploy and reflex cloud load their hosting implementation only when used. If the optional hosting package is missing, the command accepts the supplied flags and reports the package to install instead of failing during unrelated CLI commands. The hosting CLI then uses the export path to prepare and submit deployment data.

References: reflex/reflex.py• L50-267 reflex/reflex.py• L1037-1297 packages/…/cli.py• L448-539

Self-managed deployment

Self-managed deployment uses the production run or export result without the managed hosting control plane. An operator supplies the runtime, static file host, or cloud provider. The public frontend address, backend address, route prefixes, and proxy behavior must match the generated app settings.

References: reflex/…/export.py• L47-67 reflex/…/exec.py• L343-381 packages/…/config.py• L152-213

Extensibility

Extensibility lets an app change framework behavior at defined boundaries instead of forking the core workflow. Plugins participate in route collection, compilation, frontend setup, and production output. Custom component packages add reusable Python descriptions of frontend libraries. Read extensions and custom components for authoring and package details.

Plugin configuration

An app adds plugin instances to Config.plugins, normally through rxconfig.py. Configuration normalizes classes and instances. It can add plugin classes from environment settings and disable selected plugin types. The active list then guides compilation and build in a defined order.

References: packages/…/config.py• L152-193 packages/…/config.py• L258-286 packages/…/config.py• L425-475 packages/…/config.py• L477-559

Plugin lifecycle

Plugins can add frontend packages, styles, routes, generated files, environment entries, static assets, and post-build work. They can also inspect or replace page and component results during compilation. The compiler stages route contributions before page evaluation, then applies compile and build hooks as the app moves toward frontend output.

References: packages/…/base.py• L121-322 reflex/…/compiler.py• L1129-1160 reflex/…/compiler.py• L1338-1450

Custom component packages

The current CLI does not create or build custom component packages. The hidden reflex component compatibility command accepts old subcommands and flags, then directs engineers to wrap React components directly in an app or start a reusable package from the component template. Read extensions and custom components for the supported extension path.

References: reflex/reflex.py• L1250-1278

Optional integrations

Some integrations load only when their settings or workflow require them. Database schema checks load the database model only for an app with a configured database and migration state. Redis support is also optional. When enabled, health checks reuse one client and close it with the app lifecycle. A configured Redis connection cap makes callers wait for an available connection instead of opening an unbounded number of connections.

References: reflex/…/prerequisites.py• L447-600 reflex/…/prerequisites.py• L840-892 reflex/reflex.py• L1112-1130

Experimental features

The rx._x namespace exposes early extension features without the stability promise of the main API. These features can provide browser state or React hook expressions for cases that normal server state and component props do not cover.

ClientStateVar is a client-side state slot backed by React state. A local slot serves one component scope. A global slot shares its value and setter across mounted components. Frontend events can set it. Backend events can retrieve or push it when the slot is global. A push made before mount becomes the starting value for that component.

References: reflex/…/__init__.py• L1-78 reflex/…/client_state.py• L69-115 reflex/…/client_state.py• L218-332 reflex/…/hooks.py• L1-91

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep reflex init, template naming, dependency-file selection, and .web workspace setup aligned. A project can initialize successfully but fail on its first run when these paths disagree.
  • Keep persisted root dependency files and their .web copies consistent. Package scripts and framework overrides must remain compatible with the lockfile used by the frontend installer.
  • Keep development, preview, production, export, and deploy compile contexts aligned with the output each mode expects.
  • Preserve the frontend/backend artifact contract when changing export or build behavior. Managed hosting and self-managed operators consume those outputs in different ways.
  • Keep runtime URL and path settings aligned with generated frontend configuration and proxy rules. A build can succeed while browser-to-backend requests fail.
  • Keep migration initialization, app and page evaluation, revision generation, and schema checks in the same order. Lazy model imports can otherwise be absent from the first revision or health check.
  • Keep custom migration-environment handling aligned across startup schema checks and reflex db commands. A failure must remain visible without turning a startup check into an unexpected app exit.
  • When adding a plugin hook or generated file, check hook order, output ownership, and collisions with framework-generated files.
  • When changing the plugin or custom-component contract, update configuration normalization and frontend dependency collection together.
  • Keep the managed deployment export callback separate from standalone provider workflows. They use different control planes and recovery behavior.
  • Preserve lazy command loading when changing optional CLI commands. Help, argument parsing, missing-package hints, and Typer-to-Click conversion must still work when the hosting package is absent.
  • When changing package version checks, preserve package-specific cache keys and the separate cool-downs for successful checks and failed attempts in reflex.json.
  • When changing worker-based compilation or optional integrations, keep worker cleanup and deferred import boundaries intact. Telemetry flushes and configured service checks must not disappear.
  • When changing development process startup or reload handling, preserve the reload marker that distinguishes backend startup from hot reload, the supervisor listener handoff, clean worker shutdown, and socket release when no worker remains.
  • When changing JSON state files, keep the external lock location, atomic replacement, and unlocked fallback behavior compatible with frontend directory replacement.
  • When changing client state, preserve the distinction between local and global slots and the value handoff between backend events and mounted components.
  • When changing SSR or prerender selection, keep the command flag, REFLEX_SSR, and worker environment consistent so all build and run processes use the same effective mode.
  • When changing the component extension path, keep the removed command's guidance aligned with direct React wrapping and the component template.
  • When changing Redis settings, keep URL validation, connection limits, wait time, and health-client cleanup compatible with the app lifecycle.

Important failure modes

TriggerConsequenceGuard
The app module or configured app name does not match the project layoutInitialization or backend startup cannot find the app instanceUse the generated project layout or update the app configuration as one change
Frontend dependencies are missing or the JavaScript runtime is unavailableDevelopment, production build, or export stops before serving the appLet initialization validate and install the frontend workspace before running
Frontend-only and backend-only options are used togetherThe run command exits without starting either valid modeSelect one side or run the full stack
Preview or production receives different frontend and backend portsThe run command rejects the layout or the frontend cannot reach the backendUse one port for the combined built runtime
A production frontend is built with an unreachable api_url or wrong path prefixPages load but state events and backend requests failSet public URLs and proxy prefixes to match the deployed topology
A plugin writes a generated path already owned by another sourceOne output replaces another and the final frontend can be incompleteReserve unique paths and declare ownership for generated files
A custom wrapper names the wrong library export or uses a browser-only library during server renderingThe component fails to import or render in the built appMatch the library export and use the client-only component path when required
A migration environment uses the old stock env.pyModel metadata is not loaded and schema commands cannot manage the app correctlyRun reflex db init or let a database command replace it while keeping the backup
Models are imported only by pages or plugin route hooksInitial revisions or schema checks omit those modelsEvaluate all pages before migration generation and schema checks
No model changes exist when reflex db makemigrations runsAn empty revision adds noise and can mislead later upgradesRun the change check first and write a revision only when it finds a difference
A custom env.py fails during a startup schema checkThe app starts without a useful schema resultReport the failure and direct the engineer to restore the Reflex migration environment
A managed deploy lacks a usable non-interactive tokenCI cannot resolve or submit the hosted targetPass a protected deploy token rather than relying on browser login
The hosting package is absent when deploy or cloud is usedThe selected command stops with an install messageInstall the optional hosting package before using cloud commands
A package index is unavailable during a version checkThe update warning is skipped while the command continuesTreat the check as advisory and use the stored retry cool-down
A worker exits before its compile telemetry is flushedDevelopment compile traces are incompleteKeep the compile worker's cleanup flush in place
A backend worker fails during reload or the supervisor shuts down while it still owns the listenerRequests can be refused too late or the port can remain bound after the app stopsKeep supervisor socket handoff, worker replacement, clean-stop handling, and final socket release aligned
A persisted package file is copied without its matching lockfile or framework-owned fieldsThe frontend install can use stale versions or fail in frozen modeRestore the dependency pair together and render required framework fields before install
A JSON writer cannot obtain its external lock or replaces a file in placeConcurrent setup can race, or readers can observe incomplete JSONUse the external lock when available and retain atomic file replacement
A global client state is retrieved or pushed before it is mounted with a local scopeThe event is rejected or no reader receives the valueUse a global slot for backend access and let its shared value seed the first mounted component
The effective SSR setting differs between the command and its worker processesThe generated frontend and served app can use different rendering or prerender behaviorResolve REFLEX_SSR once and let worker processes inherit that value
A Redis URL uses an unsupported scheme or its pool limit is below the required minimumRedis-backed state or health checks cannot create a valid clientUse a supported Redis URL and a valid pool limit and wait time
An engineer uses the removed reflex component commandThe CLI stops and points to direct React wrapping or the component templateUse the supported extension workflow instead of the removed command
An optional hosting command receives flags while its package is unavailableThe command reports a usage error instead of the package install pathKeep the placeholder permissive and pass unknown arguments through to its missing-package message

Key files

FileWhy to read it
reflex/reflex.pyDefines the main CLI and connects init, run, compile, export, database, deployment, and extension-related command entry points. It also defines lazy command loading and run-mode boundaries.
reflex/…/frontend_skeleton.pyShows how initialization creates the .web workspace, persists frontend dependency state, and writes frontend tool configuration.
reflex/…/path_ops.pyDefines the file and JSON update boundaries that keep generated state safe during concurrent setup and frontend replacement.
reflex/…/templates.pyShows how a new app is created from local or remote templates.
reflex/…/prerequisites.pyDefines app validation, compile checks, frontend setup, optional service checks, migration checks, and throttled package version checks.
reflex/…/migrations.pyDefines the boundary between reflex db commands, Alembic, app model loading, page evaluation, and legacy migration upgrades.
reflex/…/exec.pyShows how development and production frontend and backend processes are selected, started, reloaded, and served. It also coordinates worker startup, listener handoff, reload state, and SSR or prerender settings.
reflex/…/compiler.pyShows the shared compile boundary used by run, export, and deploy.
reflex/…/export.pyDefines the production export sequence and its artifact handoff.
reflex/…/build.pyDefines production frontend output and archive creation.
packages/…/config.pyDefines app settings, environment overrides, and plugin activation.
packages/…/base.pyDefines the extension hooks available to plugins.
reflex/…/client_state.pyDefines the experimental client state boundary between frontend events, mounted components, and backend event handlers.
packages/…/cli.pyDefines the managed hosting handoff after local export.