rayfin init
Scaffold a new Rayfin project, add Rayfin to an existing directory, select templates, and choose services with rayfin init.
Use rayfin init to create or update rayfin/rayfin.yml. Use
npm create @microsoft/rayfin@latest when you want the same initializer wrapped in npm's
project-creation flow.
Create a new project
npm create @microsoft/rayfin@latest my-appThe project name is positional. Bare names with whitespace are slugified for the folder
(My App → my-app/); pass ./My App to keep spaces in the directory name.
Add Rayfin to an existing project
npm install --save-dev @microsoft/rayfin-cli
npx rayfin init [directory][directory] defaults to the current directory and doubles as the default project name.
When you choose Start from scratch, init also moves an existing dev script to
dev:frontend and sets dev to rayfin dev; see Existing dev script.
New in 2.0
Interactive prompts
Without flags, rayfin init asks for the template/source first. In scratch mode it then
asks which services to enable (Auth, Data, Storage, and Functions), which auth method to
use, and whether static hosting should be configured. Storage is listed without a feature
flag. Changed in 2.0 Fabric SSO is the supported
auth method. The Data dialect defaults to mssql because managed Fabric apps use MSSQL.
The default interactive template path is the blankapp built-in, displayed as
✨ Use default template and backed by the Universal App since 1.36. Choose Start from scratch only when you want the CLI to write
a minimal rayfin.yml instead of copying a template.
Reconfiguring an existing project
Running rayfin init again in a directory with rayfin/rayfin.yml reruns configuration.
Existing entity files under rayfin/data/ are preserved. Use --overwrite only when you
intend to replace scaffold-level files that already exist.
When a template ships rayfin.yml, the initializer preserves template-authored service
settings and applies only explicit command-line choices such as --project-name,
--dialect, or --services.
Options
| Option | Default | Description |
|---|---|---|
[directory] | current directory | Directory to create the project in. |
--project-name <name> | directory name | Override the project name and update rayfin.yml without changing the directory. |
-t, --template <uri> | prompt | Template name, git URL, or local path to create the project from. |
--template-name <name> | prompt for multi-template sources | Pick one template from a multi-template source non-interactively. |
-l, --list-templates | false | List available templates (built-in, local registry, and, with --template <url>, the remote source) as JSON and exit. Listing a remote git source is new. Changed in 2.0 |
--dialect <dialect> | mssql when Data is enabled | Database dialect. Fabric supports mssql. |
--services <list> | auth,data in non-interactive scratch init | Comma-separated services to enable: auth, data, storage, functions. functions is accepted without a feature flag Changed in 1.36; storage is accepted and requires data Changed in 2.0 |
--auth-methods <list> | fabric | Comma-separated auth methods. fabric is the supported value. |
--static-hosting | true | Scaffold a static frontend. |
--overwrite | false | Overwrite existing configuration files. |
-w, --workspace <name> | — | Fabric workspace display name. Mutually exclusive with --workspace-id. |
--workspace-id <id> | — | Fabric workspace ID. Mutually exclusive with --workspace. |
--item-id <id> | — | Fabric App Item ID to pre-associate with the project. |
Root -y, --yes, --output <mode>, --json, and --verbose also apply.
Services
Auth and Data are regular services. Functions are generally available since 1.36; use
--services auth,data,functions to scaffold the Functions block and starter package.
Storage is generally available in 2.0 and no longer needs a feature flag.
Changed in 2.0 Selecting it writes
services.storage.enabled: true and creates an empty rayfin/storage/ folder. Storage
requires Data, so --services auth,storage fails with Storage requires the Data service.;
pass --services auth,data,storage. To add Storage to an existing app with a starter
folder, dependencies, and client wiring, run rayfin storage init instead — see
Storage.
What init writes
For a scratch project (Start from scratch), rayfin init writes:
rayfin/rayfin.ymlwithid,name,version, and aservicesblock.services.staticHosting.assetAccess: protectedwhen static hosting is scaffolded. New in 1.35.1services.functions.auth.type: applicationwhen Functions are selected. New in 1.36services.storage.enabled: trueand an emptyrayfin/storage/when Storage is selected. New in 2.0rayfin/data/when Data is enabled.rayfin/tsconfig.json, the schema compile config, with NodeNextmoduleandmoduleResolution. Since 2.0 it also setsESNext.Decoratorsinlibandnodeintypes; when the project has a roottsconfig.json, it extends it and keeps that file'slibandtypesentries. Changed in 2.0@types/node(^22.0.0) indevDependencieswhenpackage.jsondoes not declare it yet. New in 2.0rayfin/package.jsoncontaining{ "type": "module" }when the app's package scope is not ESM and the file does not exist yet. New in 2.0- A Functions package when Functions are enabled, unless the template already supplies one.
.gitignoreentries for local Rayfin state.- Agent files:
AGENTS.mdone time,mcpServers.rayfinin.mcp.json, and Rayfin skills under.agents/skills/.
When a template already ships rayfin.yml, the CLI preserves the authored service shape
and only applies explicit identity, dialect, and --services edits.
Schema files under NodeNext
The schema files under rayfin/ compile as ES modules, either because the app's
package.json sets "type": "module" or because init added the rayfin/package.json
marker. That has two consequences:
- Relative imports between schema files need a
.jsextension, for exampleimport { Todo } from './Todo.js';. Without it, TypeScript reportsTS2835. - When the
rayfin/package.jsonmarker exists,rayfin/is its own package boundary: rootpackage.jsonimportsaliases and package self-references do not resolve there. Use relative imports.
Schema compilation uses the app's TypeScript first, and an installed TypeScript must match
^5.7.2 || ^6.0.2.
Existing dev script
A scratch scaffold rewires an existing project's dev script to match the bundled
templates: the previous command moves to dev:frontend, and dev becomes rayfin dev.
Before:
{
"name": "my-app",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@microsoft/rayfin-cli": "^2.0.0"
}
}After npx rayfin init . --project-name my-app --yes, which also installs the Rayfin
packages and declares @types/node:
{
"name": "my-app",
"scripts": {
"dev": "rayfin dev",
"build": "vite build",
"dev:frontend": "vite"
},
"devDependencies": {
"@microsoft/rayfin-cli": "^2.0.0",
"@types/node": "^22.0.0"
},
"dependencies": {
"@microsoft/rayfin-auth": "^2.0.0",
"@microsoft/rayfin-client": "^2.0.0",
"@microsoft/rayfin-core": "^2.0.0",
"@microsoft/rayfin-data": "^2.0.0"
}
}The CLI prints
🔧 Updated package.json: "dev" now runs "rayfin dev" (previous command moved to "dev:frontend").
The rewrite happens only when @microsoft/rayfin-cli was installed by the run or is
already declared as a dependency. It is skipped when dev already runs rayfin dev, and
dev is left unchanged when dev:frontend already holds a different command. Template
scaffolds keep the template's scripts.
Template selection
Built-in templates use stable CLI names such as dataapp, gettingstartedauth, and
todoapp. The blankapp built-in remains the visible default template name; since 1.36 it is backed by universal-app and displayed as ✨ Use default template. Plugin automation can still pass --template universal-app.
Changed in 1.36
Run npx rayfin init --list-templates in the target project to see names accepted by the
installed CLI. Add --template <git-url> to also list the entries in a remote template
source. Changed in 2.0 See
Templates.
Next steps
npx rayfin login
npm run dev
npx rayfin upUse npm run dev for the local Fabric-backed session. Use rayfin up to publish static
content and Functions and to apply Data and Storage declarations.
Agent files subcommand
rayfin init ai-files is documented on Ai-files.
Create a new Rayfin project named orders-app with the current CLI. Use
`npm create @microsoft/rayfin@latest orders-app -- --services auth,data,functions --auth-methods fabric --yes`,
then show the generated rayfin/rayfin.yml and confirm it contains
`services.staticHosting.assetAccess: protected` and `services.functions.auth.type: application`.Add Rayfin 2.0 to my existing Vite + TypeScript project. Run
`npm install --save-dev @microsoft/rayfin-cli@^2.0.0`, then
`npx rayfin init . --project-name <name> --services auth,data --yes` from the project
root. Afterwards confirm that package.json has "dev": "rayfin dev" with my previous dev
command moved to "dev:frontend", that @types/node is in devDependencies, that
rayfin/tsconfig.json uses NodeNext, and that rayfin/package.json contains
{"type": "module"} unless my package.json already sets "type": "module". Then run
`npx rayfin login` and `npm run dev`.