Rayfin

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-app

The 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

OptionDefaultDescription
[directory]current directoryDirectory to create the project in.
--project-name <name>directory nameOverride the project name and update rayfin.yml without changing the directory.
-t, --template <uri>promptTemplate name, git URL, or local path to create the project from.
--template-name <name>prompt for multi-template sourcesPick one template from a multi-template source non-interactively.
-l, --list-templatesfalseList 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 enabledDatabase dialect. Fabric supports mssql.
--services <list>auth,data in non-interactive scratch initComma-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>fabricComma-separated auth methods. fabric is the supported value.
--static-hostingtrueScaffold a static frontend.
--overwritefalseOverwrite 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.yml with id, name, version, and a services block.
  • services.staticHosting.assetAccess: protected when static hosting is scaffolded. New in 1.35.1
  • services.functions.auth.type: application when Functions are selected. New in 1.36
  • services.storage.enabled: true and an empty rayfin/storage/ when Storage is selected. New in 2.0
  • rayfin/data/ when Data is enabled.
  • rayfin/tsconfig.json, the schema compile config, with NodeNext module and moduleResolution. Since 2.0 it also sets ESNext.Decorators in lib and node in types; when the project has a root tsconfig.json, it extends it and keeps that file's lib and types entries. Changed in 2.0
  • @types/node (^22.0.0) in devDependencies when package.json does not declare it yet. New in 2.0
  • rayfin/package.json containing { "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.
  • .gitignore entries for local Rayfin state.
  • Agent files: AGENTS.md one time, mcpServers.rayfin in .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

New in 2.0

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 .js extension, for example import { Todo } from './Todo.js';. Without it, TypeScript reports TS2835.
  • When the rayfin/package.json marker exists, rayfin/ is its own package boundary: root package.json imports aliases 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

New in 2.0

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:

package.json
{
  "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:

package.json
{
  "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 up

Use 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.

PromptScaffold a Rayfin project with Functions
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`.
PromptAdd Rayfin to my existing Vite project
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`.
Something wrong on this page?Report an issueEdit this page

On this page