Fusebase Vibe Code
Test app changes safely before your clients see them
Use Fusebase CLI environments to keep a test copy of your app, check every change there, and only then deploy it to the live app your clients use.
Guide details
- Published
- November 9, 2026
- Read time
- 15 min read
- Category
- Fusebase Vibe Code
When you change an app, you want to try the change before your clients see it. Environments let you do this.
An environment is a separate copy of your product in Fusebase. Each copy has its own apps, its own web addresses (subdomains) and its own data. Your code stays the same: you keep one product folder and deploy it to each environment.
For example, you can have two environments:
prod— the live app that your clients use.prod-test— a test copy that only your team uses.
You deploy a change to prod-test first and check it there. When the change is good, you deploy the same code to prod. Your clients see only the finished change.
This guide has three parts:
- Why you need environments
- How to set up environments in a new product
- How to move an existing product to environments
What you need: the fusebase CLI. All commands in this guide run in your product folder.
Part 1. Why you need environments
Without environments, one product goes to one place. Every deploy changes the same apps in the same organization. If you test a change, you test it on the live app that your clients use.
With environments, one product (one code folder) can deploy to several separate places. Examples:
| Environment | What it is |
|---|---|
prod | The live app in your organization |
prod-test | A test copy for your team |
prod-beta | A beta stage |
What you get:
- Safe tests. You deploy and test a change in a test environment first. Clients on
proddo not see it. - Separate data. Each environment has its own product, its own apps and its own isolated database (store). Tests do not change
proddata. - Protection for prod. You can mark an environment as
protected. Then commands that change something print a banner and ask you to confirm. - You always know where you are. Each deployed app knows its environment. An in-app panel can show it (see “The in-app environment panel” below).
How it works
- An environment is a named profile. It is a file
environments/<name>.json. You commit it to Git. It keeps the organization, the product, the app ids, the subdomains, the store ids, test users and theprotectedmarker. fusebase.jsondoes not change between environments. It describes the apps only:subdomain,name,path. It has no platform ids. The CLI adds the data of the active environment on top of it.- Ids never move between environments. The CLI finds the ids of each environment when you deploy, and writes them only into the file of that environment. Never copy an id from one environment file to another.
- A deployed app is one environment. To go from
prod-testtoprodin the browser, you open a different deployment. It is not a switch inside the app. - Each environment needs its own subdomains. Subdomains must be unique, so two environments cannot use the same subdomain. Give each extra environment a subdomain suffix, for example
-test(see “Gotchas”).
Files in your product folder
| File | Commit to Git? | What it keeps |
|---|---|---|
fusebase.json | Yes | App declarations without environment data (subdomain, name, path, dev/build, store aliases, optional key) |
environments/<name>.json | Yes | The environment file: organization, product, app ids, subdomain overrides, fixtures, protected |
.env.<name> | No (in .gitignore) | MCP tokens and secrets of that environment, for example PW_USER_<KEY>_PASSWORD for tests |
.env | No | A copy of .env.<name> of the active environment. IDE configs, the local dev server and app code read this file |
.fusebase/state.json | No | The active environment of this folder |
Part 2. Set up environments in a new product
Step 1. Sign in
fusebase auth
Do this one time. If fusebase env list shows auth legacy-key, run fusebase auth one time again.
Step 2. Create the product
fusebase init
fusebase init creates your first environment, prod, and makes it active:
- It writes
environments/prod.jsonwith the organization and product it just created. - It copies
.envto.env.prod.
You have only one environment, so later commands do not ask for --env.
Step 3. Add a test environment
Interactive (recommended when you do not know the organization id):
fusebase env add
The CLI asks for the organization (from the list of your organizations), the name, a subdomain suffix and the protected marker.
Or copy your prod environment (the CLI removes the ids for you):
fusebase env clone prod prod-test --org <orgId> --subdomain-suffix "-test"
Notes:
- Each option that you give skips its question.
- In CI (no terminal),
fusebase env addneeds all values:fusebase env add <name> --backend prod --org <orgId>. - Add
--protectedfor environments that are like production. - This step only writes the environment file. It does not change anything in Fusebase.
Step 4. Create the environment in Fusebase
fusebase env use prod-test
fusebase deploy --nocode # or: fusebase deploy --env prod-test --nocode
The first deploy of a new environment:
- creates the product in that organization (with the name of your product folder),
- connects or creates each app on its subdomain for this environment,
- writes the ids into
environments/prod-test.json.
--nocode stops after this (no code upload). A full fusebase deploy also builds and uploads the code.
Step 5. Get the MCP tokens
fusebase env tokens # tokens of the active environment go to .env.prod-test (and .env)
This command needs a product. Run it after Step 4.
Step 6. Work every day
fusebase env list # all environments: organization, sign-in state, active marker
fusebase env status [--env <name>] # organization/product, sign-in, app ids, token freshness, IDE MCP config drift
fusebase env use <name> [--tokens] # make <name> the active environment of this folder
fusebase deploy [--env <name>] # deploy to the active (or named) environment
fusebase dev start [--env <name>] # run the local dev server against the active (or named) environment
fusebase env tokens [--env <name>] # refresh MCP tokens
fusebase env provision-store [--env <name>] # create the isolated stores of each app in the environment
fusebase env remove <name> [--yes] # delete local files only (environment file and .env.<name>);
# the product and apps in Fusebase stay
Which environment does a command use? The first one that is set, from left to right:
--env <name> > FUSEBASE_ENV > fusebase env use > "defaultEnvironment" in fusebase.json > the only environment
A typical safe flow:
fusebase env use prod-test
fusebase deploy # deploy and test on prod-test
fusebase deploy --env prod # when the change is good, deploy to prod
After you switch: update the IDE MCP configs
The IDE MCP configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, opencode.json, .codex/config.toml, mcp_example.json) keep the Dashboards/Gate tokens as text. They do not read .env. After you switch the environment, they still use the tokens of the previous environment.
fusebase env use <name>finds this and offersfusebase config ide --force.fusebase env statusshows the same problem on itside mcp:line.- After you regenerate the configs, reconnect or restart the MCP servers in your IDE. An open session keeps the old token.
Postgres stores (databases) per environment
If your app has isolatedStores.sql[], each environment needs its own store.
fusebase deploy does this for you. It runs after the app setup and before the code upload. If you do not want this, use fusebase deploy --skip-store-provision.
You can also do it by hand:
fusebase env provision-store --env <name> # create the store, apply migrations, check RLS, save storeId
fusebase env provision-store --env <name> --dry-run # show the plan, change nothing
For each app with isolatedStores.sql[], the command:
- creates the Gate store, or uses the one that exists,
- applies the app’s
postgres/migrations, - checks the migration status and the row-level security (RLS). It warns if a data table has no row policy or if the runtime role can skip RLS,
- writes the
storeIdintoenvironments/<name>.jsonunderapps.<key>.stores.<alias>.
Many environments in one organization. Store aliases must be unique in an organization. So the alias on Gate gets the environment name at the end (<alias>-<env>). Your app code does not see this: it still asks for todos, and each environment gets its own store. If that alias is already used by a store of a different environment, the command stops with advice (use --alias-suffix <s> or a different organization). It does not touch the other database.
The in-app environment panel
Each deploy with environments puts a file fusebase-env.json into the app. It has the environment name, the organization/product/app ids, the subdomain and links to the same app in the other environments.
The SPA template has a floating EnvPanel that shows this data:
- Open the app with
?envpanel=1to show it (the app remembers this;?envpanel=0hides it). protectedenvironments show a red PROD badge.- Links take you to the same app in the other environments. In the same organization on
*.thefusebase.appyou stay signed in; a different organization needs a new sign-in. - The panel shows even while the app is still signing you in.
- Test ids for Playwright:
data-testid="fbs-env-panel",…-name,…-app-id.
Show the panel to staff only. Hide it behind your app’s role check before clients can use the app.
Test users per environment
Put test user identities into the environment file, and their passwords into the .env file of that environment:
// environments/prod-test.json
"fixtures": {
"testUsers": [
{ "key": "owner", "email": "qa-owner@…", "role": "owner" },
{ "key": "client", "email": "qa-client@…", "role": "client" }
]
}
# .env.prod-test (not in Git)
PW_USER_OWNER_PASSWORD=…
PW_USER_CLIENT_PASSWORD=…
Test runners read both files, so each environment has the same set of tests.
CI
FUSEBASE_API_KEY overrides all other keys:
FUSEBASE_ENV=<name> FUSEBASE_API_KEY=<key> fusebase deploy
Part 3. Move an existing product to environments
Old products stay as they are (one environment, “legacy mode”) until you run fusebase env init. This part is a checklist for the change.
Result after the move
fusebase.jsonhas no environment data. Apps have stable keys,subdomain,nameandpath. No platform ids.environments/<name>.jsonis in Git and keeps organization, product, app ids, subdomains, store ids, fixtures andprotected..env.<name>is not in Git and keeps tokens and secrets..envis made from the active.env.<name>.- App code finds organization and app from the deployed environment data, the request host or platform env vars — not from fixed prod values.
- Tests can run the same read-only smoke suite against at least one environment, and fail quickly on a wrong deployment.
Step 1. Look before you change
fusebase env status || true
find . -maxdepth 3 -name fusebase.json -o -name package.json
rg -n "orgId|productId|storeId|thefusebase|FUSEBASE_|FBS_|GATE_|DASHBOARDS_|APP_SESSION|magiclink|createAppMagicLink|isolated|callAppApi|webhook|cron|email|file|upload" .
Find out what type of product you have:
- One app or a product with many apps.
- Frontend only, with a backend, backend only, sidecar, cron or webhook.
- What it uses: dashboards only, Gate APIs, isolated SQL/NoSQL stores, files, email, magic links, calls to other apps, custom domains.
- Tests: automated, manual QA only, or none.
- The current production organization and who has access to the app.
Do not change live data while you look. Do not create, update, apply migrations, change app access or deploy until the owner agrees.
Step 2. Clean up fusebase.json
Give each app a stable key:
{
"key": "benchmarking",
"subdomain": "benchmarking",
"name": "Benchmarking",
"path": "apps/benchmarking"
}
Rules:
- Keep
keythe same in all environments. Use it in scripts, tests and CI. - Keep
subdomainandnameinfusebase.jsonas defaults. - Do not write
apps[].idby hand. - Do not copy platform ids between environments.
- Keep app permissions and backend/build/dev config in
fusebase.json. They describe the app, not an environment. - Move product/app/store ids into environment files with CLI commands, not by hand.
Make the current deployed setup your first environment:
fusebase env init --name prod --strip
- The current data of
fusebase.json(organization, product, app ids, store ids) becomes the first environment,prod. --stripmoves the ids fromfusebase.jsoninto the environment file (recommended). Without it, the old ids do no harm — the environment file wins. If you forgot--strip, runfusebase env strip [--into <name>]later.- Your
.envis copied to.env.<name>. - If the current setup is not production, use a different name.
Mark real production environments as protected in the environment file:
{
"protected": true
}
Then check:
fusebase env status --env prod
git diff -- fusebase.json environments/prod.json .gitignore
Step 3. Add a test environment
Copy prod with a subdomain suffix, so the subdomains do not conflict:
fusebase env clone prod prod-test --org <orgId> --subdomain-suffix "-test"
fusebase env use prod-test
To create the product and app bindings in Fusebase without a code upload:
fusebase deploy --env prod-test --nocode
fusebase env status --env prod-test
Get tokens after the product exists:
fusebase env tokens --env prod-test
Never commit .env, .env.prod-test, .env.prod, tokens, passwords or traces.
Step 4. Fix app code that is not safe for many environments
The most frequent problem: the app is deployed to one environment, but its code still calls a different organization or app.
Frontend:
- Use same-origin
/api/*or platform proxy paths. - Do not use
VITE_FUSEBASE_HOST,VITE_FUSEBASE_ORG_IDor app ids as the main source of context. - Read the deployed environment data first:
window.__FUSEBASE_ENV__when it is there, then/fusebase-env.json. - Use
getMeonly for the current user. Do not let it replace the deployedorgIdorappId. - When sign-in fails, show a shell or a local error. Do not block the full app because
getMefailed.
Backend:
- Use platform env vars, for example
FBS_ORG_IDandFBS_FEATURE_TOKEN. - When you need a full Gate/Dashboards host for a request, find it from the incoming app host (
*.thefusebase.app). - Use host overrides only as an emergency option, not as the default.
- Do not write fixed prod organization ids, product ids, app ids or Gate hosts in the code.
- Do not make app secrets for public platform values: organization ids, product ids, app subdomains, store ids or Fusebase hosts.
Search for code to review:
rg -n "app-api\\.thefusebase|api\\.thefusebase|thefusebase\\.app|orgId|productId|storeId|FUSEBASE_HOST|FUSEBASE_APP_HOST|VITE_FUSEBASE|FBS_ORG_ID|FBS_FEATURE_TOKEN" apps
Step 5. Special cases
Products with many apps
- Give each app a stable
key. - Put per-app environment overrides in
environments/<name>.jsonunderapps.<key>. - Make one Playwright project per app key.
- Put flows that use many apps into integration specs, not into one app’s tests.
Isolated stores (Postgres)
- Keep aliases and permissions in
fusebase.json. - Let deploy write the real store ids into the environment files.
- App code finds stores through Gate/app scope by alias or platform binding.
- Do not put
storeIdinto app runtime secrets.
Backend-only permissions
- Keep
isolated_store.*,gate.*,app_api.*and other app permissions infusebase.json. - After you change permissions, use the normal app update/deploy for the selected environment.
- Check with read-only tests before you run tests that write data.
Magic links and access
- Do not run magic-link tests on production without approval.
- Before the first magic-link test, make sure the app access list is explicit. Creating links can change access if the list was empty.
- Use backend exchange routes of the app for long app sessions when the app needs them.
Email, files, automations, cron, webhooks and sidecars
- Keep external provider credentials as secrets per environment, in
.env.<name>or in platform secrets. - Callback URLs, public app URLs and webhook origins are different in each environment.
- Keep read-only smoke tests separate from tests that change data.
Custom domains
- Write down the app URL of the environment from
fusebase env status. - Do not find the environment from a custom domain alone, unless the platform also gives environment data or a trusted server env var.
Step 6. Add simple read-only E2E tests
If production is your only environment, start with read-only smoke tests only:
fusebase scaffold --template e2e --dir tests/e2e
cd tests/e2e
npm install
FUSEBASE_ENV=prod npm test
Minimum test set:
- Get
/fusebase-env.jsonand checkenv,orgIdand the app key. - Open the app and check that it does not show an empty page or a wrong-environment error.
- If the app needs sign-in, check the expected “access denied” or login screen. Do not create data.
- If the environment panel is on for staff, check
data-testid="fbs-env-panel"and the active environment name.
Add tests that write data only after you have a dedicated prod-test environment and test users. For full setup, including GitLab CI, read the local guide E2E Playwright Setup Guide.
Step 7. Connect CI
Use the e2e scaffold templates:
- GitLab: add
tests/e2e/ci/gitlab-e2e.ymlto your root.gitlab-ci.yml(include or job). - GitHub: copy
tests/e2e/ci/github-e2e.ymlto.github/workflows/e2e.yml.
CI command:
FUSEBASE_ENV=<env> npm test --prefix tests/e2e
CI variables:
FUSEBASE_API_KEY— your Fusebase API key.- Passwords, for example
PW_USER_CLIENT_PASSWORD, or with an environment suffix, for examplePW_USER_CLIENT_PASSWORD_PROD_TEST. GATE_MCP_TOKENonly when tests need read-only API checks.
Run protected environments manually or on a schedule until you are sure the tests are read-only.
Step 8. Check everything
Run the checks that your product has:
fusebase env list
fusebase env status --env prod
fusebase env status --env prod-test
npm test
npm run typecheck
FUSEBASE_ENV=prod-test npm test --prefix tests/e2e
FUSEBASE_ENV=prod npm test --prefix tests/e2e
If a script does not exist, skip it. Do not make a replacement. Write down which checks passed, which you skipped and why.
Before you deploy, make sure that:
git diffshows no secrets,fusebase.jsonhas no app ids that you added by hand,- each environment file has only ids of its own organization,
- app code finds host and organization in a way that is safe for many environments,
- CI has at least one read-only smoke job.
Step 9. Hand off
Write a short summary:
- environments that you created or adopted,
- changes in
fusebase.json, - fixed values that you removed from app code,
- tests and CI that you added,
- commands that you ran and their results,
- manual steps that are still open, for example deploys, permission changes or secrets that need human approval.
Help inside your product folder
Your local CLI ships these skills and guides. Use them by name:
- Skill
fusebase-cli— commands, environment commands, deploy andfusebase.jsonrules. - Skill
app-e2e-tests— Playwright tests for many environments and CI. - Skill
app-backend— when the app has a backend or readsprocess.env. - Skill
fusebase-gate— when app code calls Gate APIs (org access, magic links, isolated stores, email, files, automations). - Guides “App Environments Guide”, “App Environment Migration Guide” and “E2E Playwright Setup Guide”.
Gotchas
- Same code, other environment, “no changes”. The CLI compares a hash of the source files. If you deploy the same code to another environment, it can skip the upload. Then the app keeps the old
fusebase-env.json. After you change environment files, runfusebase deploy --env <name> --force. - Subdomain conflicts. Two environments cannot use the same subdomain. Set
subdomainSuffixor per-appsubdomainin the environment file.fusebase env clone --subdomain-suffixdoes it for you. - App returns 401 after a fresh deploy. The environment has no store. Store setup was skipped (
--skip-store-provision) or never ran. Runfusebase env provision-store --env <name>. fusebase env tokensfails on a new environment. It has no product yet. Runfusebase deploy --env <name> --nocodefirst.- Do not edit ids by hand.
id,productIdand store ids in environment files come from deploy. Ids that you write by hand cause double registration. - Edit
.env.<name>, not.env..envis generated. - Do not put hosts into the frontend build.
fusebase deploy --env <name>gives the values of.env.<name>to the build, but app code must find hosts at runtime: same-origin paths orwindow.location.hostname. IfgetMefails with status 0 (network/CORS), a wrong host is probably in the build.
Quick reference
| Task | Command |
|---|---|
| Sign in | fusebase auth |
| New product | fusebase init (creates one active environment, prod) |
| Move an existing product | fusebase env init --strip |
| New environment | fusebase env add (interactive) |
| Copy an environment | fusebase env clone <from> <to> --org <orgId> --subdomain-suffix <s> |
| Switch | fusebase env use <name> |
| Look | fusebase env list / fusebase env status |
| Create in Fusebase | fusebase deploy --env <name> --nocode |
| Deploy | fusebase deploy [--env <name>] |
| Create stores | fusebase env provision-store [--env <name>] (deploy runs it for you) |
| Tokens | fusebase env tokens [--env <name>] |
| Remove (local files only) | fusebase env remove <name> (--yes for CI) |
| CI | FUSEBASE_ENV=<name> FUSEBASE_API_KEY=<key> fusebase deploy |