Railway monorepo: deploy a frontend and backend
Short answer: deploy a frontend and backend from one repository as separate Railway services, then choose the build context each needs. Independent projects can use separate root directories. A shared workspace must retain the root configuration and sibling packages needed to build each app; use per-service commands to choose what runs.
Identify the dependency boundary first
An AI-generated repository might contain two independent folders, or several applications importing common code. Those layouts can look similar in a file browser while requiring different deployment settings.
| Repository layout | What to evaluate |
|---|---|
frontend/ and backend/, each with independent dependencies |
A separate root directory for each service |
apps/web, apps/api and packages/shared |
Repository-root context and application-specific commands |
| A root workspace file and one lockfile | Whether both applications depend on root-level installation |
| Multiple processes launched by one development script | Separate production commands for the actual deployable processes |
Ask your coding assistant to list each app’s inputs and explain which files its production build reads. Check that answer against imports and package manifests. Selecting the smallest folder is useful only if the folder contains everything that build needs.
Configure independent folders
For a standalone JavaScript frontend and Python API, prepare two services in the same Railway project. Point both at the intended repository and branch. Set the frontend’s Root Directory to /frontend and the API’s to /backend, replacing those example names with the real directories.
Then verify each service’s production commands and variables separately. The frontend command must serve its production output, and the API command must start the API. Do not use a local script that starts both together simply because it worked in the editor preview.
Railway’s build configuration guide explains how Root Directory affects build and deploy commands. Run the equivalent commands from those directories locally before diagnosing the hosting build.
Use the Cursor deployment guide for repository preparation or the FastAPI guide for the Python server’s host and port. This article addresses the repository boundary around those applications.
Keep a shared workspace available
If apps/web imports a package from packages/shared, restricting its build context to the app folder can hide that dependency. Keep the required repository files available and use workspace commands to target the app. Railway documents this distinction in its monorepo guide.
For a pnpm workspace whose package is named @example/web, an illustrative pair of commands is:
pnpm --filter @example/web... build
pnpm --filter @example/web start
The first line targets the app and its dependencies; the second starts only that app. Substitute the actual package name and ensure the selected packages have the scripts your build expects. This is not a complete workspace configuration or a universal framework start command.
The ellipsis selector is documented by pnpm filtering. If your repository already uses another build orchestrator, use its supported dependency-aware build rather than mixing two orchestration schemes without checking the result.
Give the API service its own commands. Review any services proposed by automatic import: an app, a shared library and a configuration package are not necessarily three independent running servers.
Include every input in watch paths
Watch paths decide whether a changed file triggers a deployment; they do not install a missing dependency. For a web app using a shared package, an example list is:
/apps/web/**
/packages/shared/**
/package.json
/pnpm-lock.yaml
/pnpm-workspace.yaml
These are repository-root patterns. Adjust them to the actual dependency graph, including other root files your build reads. An API with different dependencies needs its own list.
Check three changes in a test environment: web-only code, shared code and a lockfile update. Confirm which services deploy each time. If a shared change fails to rebuild a dependent app, widen the watch coverage before relying on it. Railway documents pattern behavior in build configuration.
Connect the processes after they deploy
Separate services also have separate runtime configuration. Determine whether an API request originates in browser JavaScript or in server-side frontend code. A browser cannot reach a private Railway hostname; same-environment server code can use the private network. See working with domains.
For browser calls, configure the public HTTPS API destination and the API’s permitted frontend origin. Keep database credentials and privileged API keys behind the backend. Public frontend configuration can be embedded at build time, so rebuild when its destination changes. The environment-variable guide explains that boundary.
Review inherited deployment configuration
Checked on November 22, 2026: Railway marks legacy Config as Code deprecated and says existing legacy-service files keep working until December 1, 2026. Review its deprecation notice and Infrastructure as Code migration guidance before copying an old railway.toml recipe. The setup above uses service settings and package scripts.
Finally, deploy a known commit and complete a user action through the frontend into the API. Record the service, commit, root and commands that passed. If a service never answers, follow the 502 checklist; if uploaded files disappear, check persistent storage separately from the repository layout.
FAQ
Can one GitHub repository deploy multiple Railway services?
Yes. Configure a separate service for each application process. Independent folders can use their own root directories; shared workspaces need the root files and packages required by their dependency graph.
Why does selecting apps/web break my pnpm workspace build?
That folder may depend on the root lockfile, workspace configuration or sibling packages. A root directory that excludes those files removes required build inputs. Keep the workspace available and select the application with the package manager's commands.
Are watch paths relative to the service's root directory?
Railway documents watch paths as repository-root patterns even when a service has a different root directory. Include shared dependencies and root configuration changes that should rebuild the service.
Can the frontend call a private Railway API hostname?
Server-side code in the same Railway project environment can use private networking. JavaScript running in a visitor's browser needs a public endpoint or a public server route that forwards the request internally.