Application scaffolding
Application scaffolding is the path from one command to a new React on Rails application that can run, render React, and continue through the first development steps. The create-react-on-rails-app CLI chooses a supported setup, checks the local tool chain, and hands the app to the React on Rails generator for its first integration. It is the application-creation part of the developer toolchain; related build and runtime checks are described in build, test, and release automation and Rails engine and configuration.
Scaffolding workflow
Command entry
The create-react-on-rails-app command is the public entry point for a new app. It accepts an app name and a small set of choices for language, package manager, bundler, product mode, styling, and agent guidance. The command is non-interactive, so the selected flags describe the whole initial setup before any files are written. It does not change this behavior based on whether it runs in a terminal. (packages/create-react-on-rails-app/bin/create-react-on-rails-app.js#L1-L16, packages/create-react-on-rails-app/src/index.ts#L142-L219, packages/create-react-on-rails-app/tests/index-tty.test.ts#L50-L102)
The CLI turns those choices into one resolved setup. It then checks the local tools, creates the Rails base, adds the needed gems, runs the React on Rails generator, and reports the first commands for the new app. This keeps the user-facing flow simple while leaving Rails and React on Rails as the systems that define the generated app. (packages/create-react-on-rails-app/src/index.ts#L32-L139, packages/create-react-on-rails-app/src/create-app.ts#L503-L686)
The main flow is:
flowchart LR
A[App name and CLI flags] --> B[Resolve setup choices]
B --> C[Validate local tools]
C --> D[Create Rails PostgreSQL app]
D --> E[Add React on Rails gems]
E --> F[Run React on Rails generator]
F --> G[Align package manager]
G --> H[Ready development app]
References: packages/…/index.ts• L13-139 packages/…/create-app.ts• L503-686 packages/…/index-tty.test.ts• L50-102
Setup modes
Product modes
The product mode selects the React on Rails feature set that the new app uses. The CLI permits one mode at a time and resolves an omitted mode to Pro, because the current React 19.2 support is on the Pro path. Standard remains the explicit choice for an open-source-only app. (packages/create-react-on-rails-app/src/mode.ts#L1-L35, packages/create-react-on-rails-app/src/index.ts#L85-L100)
| Mode | Initial product path | Generated focus |
|---|---|---|
Default or --pro | React on Rails Pro | Standard server-side rendering example with Pro Node renderer support |
--standard | Open-source React on Rails | Standard server-side rendering example without the Pro gem |
--rsc | React on Rails Pro with React Server Components | RSC example with the hello_server route |
--rsc includes Pro and uses its own generator path. The CLI rejects combinations such as --standard --pro before it starts the app. (packages/create-react-on-rails-app/src/mode.ts#L67-L88, packages/create-react-on-rails-app/src/index.ts#L32-L39, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L246-L272)
References: packages/…/mode.ts• L1-88 packages/…/index.ts• L32-39 packages/…/index-tty.test.ts• L104-149 react_on_rails/…/install_generator.rb• L298-337
Build and language choices
Language, bundler, styling, and package manager are independent setup choices. TypeScript selects typed component files. Rspack is the default bundler for a fresh app, while --no-rspack and its --webpack alias select Webpack. The CLI accepts both Webpack flags together, but rejects --rspack --webpack because those requests conflict. Tailwind adds the Tailwind CSS v4 example style. The package manager is either npm or pnpm and is detected when the user does not choose one. (packages/create-react-on-rails-app/src/index.ts#L22-L82, packages/create-react-on-rails-app/tests/index-tty.test.ts#L152-L207, react_on_rails/lib/generators/react_on_rails/generator_helper.rb#L391-L435)
The CLI passes the resolved choices as one generator request. This matters because the language and bundler must agree across the JavaScript files, asset config, and installed dependencies. The generator also maps the RSC plugin and config to the active bundler. (packages/create-react-on-rails-app/src/create-app.ts#L166-L205, react_on_rails/lib/generators/react_on_rails/generator_helper.rb#L437-L467)
References: packages/…/index.ts• L14-82 packages/…/index.ts• L143-163 packages/…/index-tty.test.ts• L152-207 packages/…/create-app.ts• L166-205 react_on_rails/…/generator_helper.rb• L391-467
Prerequisite validation
Local tool checks
The CLI validates the tools that must exist before it can create a usable app. It checks Node.js, Ruby, Rails, git, and the selected package manager before it calls Rails. The current minimums are Node.js 18, Ruby 3.3, and Rails 7.0. (packages/create-react-on-rails-app/src/validators.ts#L4-L9, packages/create-react-on-rails-app/src/validators.ts#L10-L127)
Validation stops the flow before directory creation when a required tool is absent or too old. This gives the user a direct repair message instead of leaving a partial app that fails later during gem or JavaScript setup. App names also need a safe directory form and must not name an existing directory. (packages/create-react-on-rails-app/src/validators.ts#L130-L146, packages/create-react-on-rails-app/src/create-app.ts#L473-L500)
References: packages/…/validators.ts• L4-146 packages/…/create-app.ts• L473-500
Command boundary
The CLI utility layer provides the boundary between the scaffold flow and local commands. It runs commands with separate argument values, preserves the parent environment, and distinguishes captured output from live output. This lets the scaffold pass app names, flags, and paths as values rather than as shell text. (packages/create-react-on-rails-app/src/utils.ts#L82-L147)
The same layer detects npm or pnpm from the launch context or the available commands. Its output helpers keep progress, success, and error messages readable in both terminals and captured logs. Color output follows explicit FORCE_COLOR and NO_COLOR settings before it considers terminal support. (packages/create-react-on-rails-app/src/utils.ts#L4-L80, packages/create-react-on-rails-app/src/utils.ts#L149-L180)
References: packages/…/utils.ts• L4-180
Creation lifecycle
Rails and gem baseline
The first created state is a Rails application backed by PostgreSQL. The scaffold starts without Rails JavaScript so that React on Rails can own the asset setup, and it restores the Rails git ignore and attribute files after Rails skips git setup. It renders the installed Rails templates for supported Rails 7 and 8 releases, then uses bundled defaults when that render is not available. The restored ignore file also excludes credential key files before the first commit. The flow then adds the open-source react_on_rails gem. Pro and RSC modes add react_on_rails_pro before the React on Rails generator runs. (packages/create-react-on-rails-app/src/create-app.ts#L18-L108, packages/create-react-on-rails-app/src/create-app.ts#L254-L285, packages/create-react-on-rails-app/src/create-app.ts#L552-L627)
Local gem paths and prerelease CLI versions can change where the gems come from. These choices support development of the gems and prerelease versions without changing the shape of the generated application. (packages/create-react-on-rails-app/src/create-app.ts#L124-L164, packages/create-react-on-rails-app/src/create-app.ts#L503-L517)
References: packages/…/create-app.ts• L18-108 packages/…/create-app.ts• L124-164 packages/…/create-app.ts• L254-285 packages/…/create-app.ts• L503-627
React on Rails integration
The React on Rails install generator is the integration point after the Rails base and gems are ready. It installs or confirms Shakapacker, creates the asset and React configuration, adds the selected example component, and adds Pro or RSC support when the mode requires it. Pro setup also creates the renderer and process entry needed for server rendering, then upgrades only a recognized generated bundler configuration pair. The generated app therefore starts with a working server-rendered React path rather than only a set of empty folders. (react_on_rails/lib/generators/react_on_rails/install_generator.rb#L282-L337, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L1030-L1075, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L59-L94, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L433-L489)
The CLI always sends an explicit bundler choice to this generator. That keeps the JavaScript dependencies and the generated config on the same bundler, even when the generator has its own default for other install contexts. (packages/create-react-on-rails-app/src/create-app.ts#L166-L205, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L274-L280)
RSC setup also gives the generated bundler configs a client-reference source. The source uses the discovery manifest when one is available, uses a broad source scan only in supported fallback cases, and adds the Pro package's own client components. This connects server-component output to the client code that must be present at render time. New RSC apps install react-on-rails-rsc 19.3.1 with React and React DOM on the ~19.3.0 line. The generator warns when an existing app uses a different React line and points to the doctor task for a final pairing check. (react_on_rails/lib/generators/react_on_rails/rsc_setup/client_references.rb#L31-L240, react_on_rails/lib/generators/react_on_rails/js_dependency_manager.rb#L147-L166, react_on_rails/lib/generators/react_on_rails/js_dependency_manager.rb#L256-L266, react_on_rails/lib/generators/react_on_rails/rsc_setup.rb#L74-L110)
References: packages/…/create-app.ts• L166-205 react_on_rails/…/install_generator.rb• L282-337 react_on_rails/…/install_generator.rb• L1030-1075 react_on_rails/…/client_references.rb• L31-240 react_on_rails/…/js_dependency_manager.rb• L147-166 react_on_rails/…/rsc_setup.rb• L74-110
Package manager alignment
The generator can first produce npm-shaped files because Rails and Shakapacker create the base app. When pnpm is selected, the CLI converts the app to pnpm, records the package manager in package.json, imports or creates the pnpm lock file, removes the npm lock file, and updates bin/setup. This leaves later local and CI installs using the same package manager. (packages/create-react-on-rails-app/src/create-app.ts#L208-L235, packages/create-react-on-rails-app/src/create-app.ts#L287-L327)
References: packages/…/create-app.ts• L208-235 packages/…/create-app.ts• L287-327
Educational history
Each major scaffold stage can become a separate git commit. The history shows the Rails base, gem additions, React on Rails integration, and pnpm alignment as separate learning points. The baseline commit includes the restored Rails git scaffold but never includes credential key files. If git commit automation fails, app creation continues and the history is marked as partial rather than blocking the new app. (packages/create-react-on-rails-app/src/create-app.ts#L329-L387, packages/create-react-on-rails-app/src/create-app.ts#L524-L549, packages/create-react-on-rails-app/src/create-app.ts#L552-L560, packages/create-react-on-rails-app/src/create-app.ts#L665-L690, packages/create-react-on-rails-app/tests/create-app-git-history.test.ts#L123-L139)
References: packages/…/create-app.ts• L329-387 packages/…/create-app.ts• L524-549 packages/…/create-app.ts• L552-560 packages/…/create-app.ts• L665-690 packages/…/create-app-git-history.test.ts• L123-139
Generated application integration
Application templates
The templates give the new app a small working product path. The base set supplies a home page, a hello_world example, server and client React entry points, asset config, and layouts. Pro adds a Node renderer, its initializer, and the process entry that starts it. When Pro upgrades an existing app, it changes the two active bundler config files only when they exactly match a supported generated pair. RSC replaces the usual example path with a hello_server route and its server component example. (react_on_rails/lib/generators/react_on_rails/install_generator.rb#L298-L337, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L793-L820, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L269-L358, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L433-L489)
The selected language changes the example file type, while Tailwind changes the example layout and style path. These choices are parts of one generated experience: the route, component, asset entry, and layout must point to the same example. (packages/create-react-on-rails-app/src/create-app.ts#L406-L429, react_on_rails/lib/generators/react_on_rails/generator_helper.rb#L100-L148)
When the generator updates an existing RSC config, it first aligns the plugin with the active bundler. It then adds scoped client references only when the config can be read safely. Custom or unclear sections remain unchanged with a warning so a manual edit can protect app-owned config. (react_on_rails/lib/generators/react_on_rails/rsc_setup/client_references.rb#L347-L371, react_on_rails/lib/generators/react_on_rails/rsc_setup/client_references.rb#L505-L565)
References: react_on_rails/…/install_generator.rb• L298-337 react_on_rails/…/install_generator.rb• L793-820 react_on_rails/…/generator_helper.rb• L100-148 react_on_rails/…/client_references.rb• L347-371 react_on_rails/…/client_references.rb• L505-565
Pro upgrade boundary
The Pro generator also serves existing React on Rails apps. It replaces the open-source gem with the Pro gem, updates JavaScript package imports, and adds the Pro renderer path. It protects app-owned work by leaving customized, incomplete, ambiguous, or unsupported bundler config pairs unchanged and reports the manual migration path instead. (react_on_rails/lib/generators/react_on_rails/pro_generator.rb#L33-L57, react_on_rails/lib/generators/react_on_rails/pro_generator.rb#L94-L183, react_on_rails/lib/generators/react_on_rails/pro_generator.rb#L276-L307, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L433-L489)
The same Pro setup is shared by a fresh Pro or RSC install and by the standalone upgrade command. This keeps the renderer, process entry, package choice, and bundler configuration on one upgrade path while preserving legacy renderer and companion-config names when the generator cannot prove that a rename is safe. (react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L11-L30, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L320-L379, react_on_rails/lib/generators/react_on_rails/pro_setup.rb#L455-L475)
References: react_on_rails/…/USAGE• L1-32 react_on_rails/…/pro_generator.rb• L15-57 react_on_rails/…/pro_setup.rb• L433-489 react_on_rails/…/generated_webpack_config_pair.rb• L7-32
Development and CI scripts
The generated scripts connect the app to its first run and its first automated check. bin/dev starts the development processes through the generated Procfiles and points to the selected example route. A fresh app points to the home page and can open it once after a successful boot. The generated CI workflow installs the chosen JavaScript dependencies, prepares the database when needed, builds the bundles, and runs the available Rails test command. (react_on_rails/lib/generators/react_on_rails/templates/base/base/bin/dev#L1-L92, react_on_rails/lib/generators/react_on_rails/templates/base/base/.github/workflows/ci.yml.tt#L1-L92, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L673-L706)
Existing custom bin/dev and CI files are treated as app-owned unless the caller asks to overwrite them. This lets the scaffolder improve a stock Rails app without replacing a project's own process rules. (react_on_rails/lib/generators/react_on_rails/install_generator.rb#L348-L359, react_on_rails/lib/generators/react_on_rails/install_generator.rb#L742-L790)
References: react_on_rails/…/dev• L64-92 react_on_rails/…/ci.yml.tt• L47-92 react_on_rails/…/install_generator.rb• L348-359 react_on_rails/…/install_generator.rb• L673-790
Agent guidance files
New apps receive a canonical AGENTS.md and small pointers for common coding tools unless the user passes --no-agent-files. The files explain the generated app to coding agents without changing the app's runtime behavior. Existing AGENTS.md content is kept, and pointer files are not added when they would point to guidance that the scaffold did not own. (react_on_rails/lib/generators/react_on_rails/install_generator.rb#L708-L739, packages/create-react-on-rails-app/src/index.ts#L158-L163)
References: react_on_rails/…/install_generator.rb• L708-739 packages/…/types.ts• L1-12
Scaffold verification
CLI contract checks
The CLI contract tests verify that setup mode, bundler, and styling flags resolve to the intended creation choices before app creation starts. They also verify that the mode default stays Pro in both terminal and non-terminal runs, and that contradictory mode or bundler requests stop before createApp runs. (packages/create-react-on-rails-app/tests/index-tty.test.ts#L50-L207)
References: packages/…/index-tty.test.ts• L50-149 packages/…/index-tty.test.ts• L152-207
Generated-app smoke checks
The local-gem smoke script checks the scaffold as a product path rather than only as a command. It builds the CLI, creates representative Standard, Pro, and RSC apps across JavaScript, TypeScript, Webpack, Rspack, and pnpm choices, then checks routes, files, package-manager state, git history, credential-key exclusion, bundle builds, and HTTP responses. (packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L46-L102, packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L114-L216, packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L237-L296, packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L302-L386)
The smoke scope can run OSS cases alone or include local Pro gem cases. This gives gem contributors a way to check the open-source path without requiring the Pro source while keeping the full matrix available when both gems are present. (packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L8-L24, packages/create-react-on-rails-app/scripts/smoke-test-local-gems.sh#L295-L388)
The git-history tests run the real scaffold flow in temporary app directories while replacing only the slow external creation steps. They verify that every generated commit tracks the Rails scaffold without tracking config key files, including when installed Rails templates cannot be rendered. (packages/create-react-on-rails-app/tests/create-app-git-history.test.ts#L9-L22, packages/create-react-on-rails-app/tests/create-app-git-history.test.ts#L123-L198)
References: packages/…/smoke-test-local-gems.sh• L8-102 packages/…/smoke-test-local-gems.sh• L114-216 packages/…/smoke-test-local-gems.sh• L230-388 packages/…/create-app-git-history.test.ts• L9-22 packages/…/create-app-git-history.test.ts• L123-198
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the CLI mode rules, the gem selection, and the generator flags aligned. A new mode or renamed flag can otherwise create an app with the wrong gem set.
- Keep the bundler choice aligned across CLI defaults,
--webpackand--no-rspackconflict rules, Shakapacker setup, generated config paths, and example dependencies. - Keep the RSC React range and
react-on-rails-rscpackage pin aligned. Move them together when the supported React line changes, and keep the warning and doctor guidance consistent with that pairing. - Keep RSC client-reference discovery aligned with the generated RSC configs, the precompile hook, the manifest path, and the Pro client components that must be registered.
- Keep Pro config migration recognition aligned with the rendered Webpack and Rspack templates. Changes to either template can turn a safe upgrade into a manual migration.
- Keep legacy companion-config and renderer paths aligned with the generator's detection and warning messages. A path change can otherwise leave a process entry pointing at an old file.
- Keep package-manager normalization aligned with package.json, lock files,
bin/setup, and the generated CI install step. - Keep route defaults aligned with the generated example and with the first-run behavior in
bin/dev. - Keep agent-file names and overwrite rules aligned between the CLI opt-out and the generator templates.
- Keep educational commit subjects aligned with the stages that can fail or continue independently.
- Keep the supported Rails template versions, the rendered and fallback git scaffold, and the credential-key ignore rules aligned. A change can otherwise expose local keys or produce a different baseline commit.
- Keep git-history checks aligned with the stage commits and with the files that must remain outside every generated commit.
- Keep CLI contract checks aligned with the user-facing defaults and with the rule that setup remains non-interactive.
- Keep smoke coverage representative of the supported mode, language, bundler, and package-manager combinations.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| More than one product mode flag is passed | The CLI exits before creating an app | Resolve exactly one of Standard, Pro, or RSC |
--rspack and --webpack are passed together | The CLI exits before creating an app | Use Rspack or Webpack; use --no-rspack and --webpack together only when both express the same Webpack choice |
| Node.js, Ruby, Rails, git, or the selected package manager is missing or too old | Setup stops before the Rails app is created | Run the prerequisite checks and repair the reported tool |
| Rails, gem, or React on Rails generator setup fails | The new app directory is removed when cleanup succeeds | Fix the reported local tool or dependency issue and rerun with a new app path |
| pnpm conversion fails after generation | The app exists but may still contain npm artifacts or an incomplete install | Complete the printed pnpm import and install steps before using the app |
| Git commit automation fails | The app continues with partial educational history | Inspect the scaffold state and do not treat the commit list as complete |
| Rails git templates cannot be rendered or use an unsupported major version | The scaffold uses bundled Rails git defaults instead of the installed templates | Keep the fallback current and confirm that both scaffold paths ignore credential key files |
| Credential-key ignore rules are removed from the restored scaffold | A generated commit can expose config key files even though the files remain local | Preserve the /config/*.key and /config/credentials/*.key rules and verify every commit |
A custom bin/dev, CI workflow, or AGENTS.md already exists | The scaffold keeps the existing file instead of silently replacing it | Review the skipped file and use an explicit overwrite choice only when intended |
The Pro or RSC path cannot install react_on_rails_pro | Setup stops after the Rails base and OSS gem work | Make the Pro gem available, then remove the partial directory and rerun |
| An RSC app uses a React major or minor line other than 19.3 | The generator warns, and the Pro renderer can refuse to start when the React and RSC lines differ | Use React and React DOM ~19.3.0 with react-on-rails-rsc@19.3.1, then run bundle exec rake react_on_rails:doctor |
| An RSC package install fails | The generator warns and leaves the pinned package specification for a later manual install | Install the exact react-on-rails-rsc@19.3.1 package and its matching React line manually |
| The RSC client-reference manifest is missing while a server-component registration entry exists | The RSC setup stops instead of building with an unknown client-reference set | Run bin/shakapacker-precompile-hook before bin/shakapacker |
| The RSC manifest is older than the server-component registration entry | The build warns that client references may be stale | Rerun the precompile hook to refresh the manifest |
| An older generated RSC resolver lacks Pro client-component registrations | The config stays unchanged and RSC rendering can fail when it uses Pro client components | Add the required Pro references manually or rerun the generator after removing the old resolver |
| An RSC plugin section is custom or cannot be read safely | Automatic client-reference migration is skipped and a warning requests manual setup | Add clientReferences: rscClientReferences to the intended plugin sections and verify the active bundler |
| Pro setup finds a missing, ambiguous, customized, or unsupported bundler config pair | The app keeps its existing config and Pro SSR bundling may need manual migration | Use the Pro upgrade guide and verify the active Webpack or Rspack config before building SSR |
| A legacy client/node-renderer.js or stale Procfile entry remains | The generator does not add a duplicate process, but the app can still launch the old renderer path | Move the renderer and update each process command so the password and path match |
Key files
| File | Why to read it |
|---|---|
| packages/…/index.ts | Defines the public CLI options, non-interactive defaults, flag validation, resolved choices, and user-facing flow. |
| packages/…/index-tty.test.ts | Shows the CLI contracts for TTY-independent mode defaults, mode exclusivity, bundler aliases, and conflicting bundler flags. |
| packages/…/mode.ts | Defines the relationship between Standard, Pro, and RSC modes. |
| packages/…/create-app.ts | Shows the lifecycle from Rails creation through gem setup, Rails git scaffold restoration, generator invocation, package-manager alignment, and git history. |
| packages/…/create-app.test.ts | Verifies app-name rules, generator flags, cleanup behavior, gem sources, package-manager conversion, and Rails git scaffold restoration. |
| packages/…/create-app-git-history.test.ts | Verifies real generated commit history, restored Rails git files, and exclusion of credential key files. |
| packages/…/validators.ts | Defines the local tool gate that runs before app creation. |
| packages/…/utils.ts | Defines command execution, package-manager detection, and terminal output behavior. |
| react_on_rails/…/install_generator.rb | Shows how the Ruby generator turns the CLI choices into the initial React on Rails integration. |
| react_on_rails/…/js_dependency_manager.rb | Defines the dependency groups and the version pairing used for React, RSC, Pro, bundlers, and transpilers. |
| react_on_rails/…/rsc_setup.rb | Shows the RSC setup flow and the compatibility warning for the generated React and RSC package line. |
| react_on_rails/…/client_references.rb | Shows how RSC setup finds client references, registers Pro client components, and limits automatic config migration to safe cases. |
| react_on_rails/…/pro_setup.rb | Shows the shared Pro setup for new installs and upgrades, including renderer files, process entries, and safe bundler-config migration. |
| react_on_rails/…/generated_webpack_config_pair.rb | Shows how the generator recognizes supported generated config pairs before enabling Pro settings. |
react_on_rails/lib/generators/react_on_rails/pro/USAGE | States the user-facing Pro upgrade contract and the cases that require manual migration. |
| react_on_rails/…/generator_helper.rb | Shows shared bundler and generated-path decisions used by the templates. |
react_on_rails/lib/generators/react_on_rails/templates/base/base/bin/dev | Shows the generated development entry point and default route behavior. |
react_on_rails/lib/generators/react_on_rails/templates/base/base/.github/workflows/ci.yml.tt | Shows the generated CI path from dependency install to bundle build and tests. |
| packages/…/smoke-test-local-gems.sh | Shows the supported scaffold matrix and the checks applied to generated apps. |