# Rayfin — instructions for coding agents

You are reading the machine-readable entry point for the official Rayfin documentation.
Rayfin is a TypeScript backend platform: you define entities as decorated TypeScript
classes and Rayfin generates the database schema, REST and GraphQL APIs, and type-safe
clients, then runs them on Microsoft Fabric with auth, functions, blob storage, and static
hosting built in.

## How to read these docs

- **Every** documentation route has a raw Markdown mirror: append `.md` to the URL.
  `https://rayfin.ai/docs/data/querying` -> `https://rayfin.ai/docs/data/querying.md`
- [`/llms.txt`](https://rayfin.ai/llms.txt) — index of every page with descriptions, plus the
  size of every bulk download so you can budget a fetch.
- [`/docs/reference/agent-rules`](https://rayfin.ai/docs/reference/agent-rules) — the condensed do/don't list. **Read this before generating Rayfin code.**

Every mirror carries `sdk_version`, `cli_version` and `last_updated` in its frontmatter,
plus `applies_to` when a page only applies to a narrower range of releases.
Check them before copying a snippet: API shapes differ between SDK releases, and mixing
them produces code that does not compile.

## Version tags

Anything added or changed after Rayfin 1.35.0 is tagged inline with a link into the
[changelog](https://rayfin.ai/docs/reference/changelog.md), for example
`[New in 1.36](/docs/reference/changelog#rayfin-136)` or
`[Changed in 1.36](/docs/reference/changelog#rayfin-136)`. All `@microsoft/rayfin-*`
packages share one version number. If the project's installed packages are older than a
tag, that feature or behavior is not available there — read `package.json` first, and
either upgrade every Rayfin package together or use the older form. Untagged content
applies to Rayfin 1.35.0 and later; the changelog lists what 1.35 changed from 1.34.
`[Preview](/docs/reference/changelog#feature-status)` and
`[Experimental](/docs/reference/changelog#feature-status)` mark status, not version.

## Bulk downloads

Prefer a section bundle over the full corpus unless you genuinely need everything.

- [`/llms-full.txt`](https://rayfin.ai/llms-full.txt) — the entire documentation set in one file.
- [`/llms-full/auth.txt`](https://rayfin.ai/llms-full/auth.txt)
- [`/llms-full/connectors.txt`](https://rayfin.ai/llms-full/connectors.txt)
- [`/llms-full/data.txt`](https://rayfin.ai/llms-full/data.txt)
- [`/llms-full/deploy.txt`](https://rayfin.ai/llms-full/deploy.txt)
- [`/llms-full/docs.txt`](https://rayfin.ai/llms-full/docs.txt)
- [`/llms-full/functions.txt`](https://rayfin.ai/llms-full/functions.txt)
- [`/llms-full/hosting.txt`](https://rayfin.ai/llms-full/hosting.txt)
- [`/llms-full/recipes.txt`](https://rayfin.ai/llms-full/recipes.txt)
- [`/llms-full/reference.txt`](https://rayfin.ai/llms-full/reference.txt)
- [`/llms-full/start.txt`](https://rayfin.ai/llms-full/start.txt)
- [`/llms-full/storage.txt`](https://rayfin.ai/llms-full/storage.txt)

## Before you write any Rayfin code

Read [`https://rayfin.ai/docs/reference/agent-rules.md`](https://rayfin.ai/docs/reference/agent-rules.md) and
[`https://rayfin.ai/docs/reference/known-limitations.md`](https://rayfin.ai/docs/reference/known-limitations.md).
Rayfin has platform constraints (text length caps on MSSQL, no many-to-many, foreign key
naming rules) that silently break deployments if ignored.

## All pages

- [Rayfin](https://rayfin.ai/docs.md): Define your data model in TypeScript. Rayfin generates the database and type-safe APIs, then runs them on Microsoft Fabric — with auth, functions, storage, and hosting built in.
- [Auth](https://rayfin.ai/docs/auth.md): Choose a Microsoft Entra sign-in path for Rayfin apps: Fabric SSO, direct Entra token exchange, external embed host, and sessions.
- [Delegated and application access](https://rayfin.ai/docs/auth/delegated-access.md): Which identity each server-side Rayfin surface uses — the signed-in user or the app — and what access to grant at each data source.
- [Embed in your own portal](https://rayfin.ai/docs/auth/embed-host.md): Use the external embed host to sign a Rayfin app in when your own portal embeds it in an iframe.
- [Sign in with an Entra token](https://rayfin.ai/docs/auth/entra-token.md): Exchange an existing delegated Microsoft Entra access token for a Rayfin session in browser or Node.js code.
- [Fabric SSO](https://rayfin.ai/docs/auth/fabric-sso.md): Sign users in with Microsoft Entra ID through Fabric SSO, using the popup flow for browser apps or embedded flow in the Fabric portal.
- [React integration](https://rayfin.ai/docs/auth/react.md): Add a Rayfin AuthProvider, useAuth hook, route guard, Fabric SSO startup, and sign-in button to a React app.
- [Sessions](https://rayfin.ai/docs/auth/sessions.md): Use Rayfin's opaque auth session safely: read documented fields, subscribe with onSessionChange, refresh, and sign out.
- [Connectors](https://rayfin.ai/docs/connectors.md): Read and write existing Microsoft Fabric data — warehouses, SQL databases, Lakehouse SQL endpoints, semantic models, and KQL databases — from a Rayfin app.
- [Adding a connector](https://rayfin.ai/docs/connectors/adding.md): Discover Fabric sources, add a connector to rayfin.yml, install its pinned packages, and manage connector entries safely.
- [Connector authentication](https://rayfin.ai/docs/connectors/auth.md): Configure connector auth.type values, validation rules, and caller identity for delegated and application connector access.
- [Wiring connectors into your app](https://rayfin.ai/docs/connectors/client-setup.md): Configure ConnectorsRayfinClient with connector schemas, runtime hooks, and generated connectorConfig maps.
- [Generating entity files](https://rayfin.ai/docs/connectors/entity-generation.md): Generate Category A connector entity files from metadata.json, including keys, relationships, permissions, aggregate schema, and apply steps.
- [KQL databases](https://rayfin.ai/docs/connectors/kusto.md): Run KQL queries and Kusto management commands against a Fabric KQL Database from a Rayfin app.
- [Semantic models](https://rayfin.ai/docs/connectors/semantic-models.md): Run DAX against a Fabric semantic model from a Rayfin app and handle typed table results, row limits, and connector diagnostics.
- [Fabric SQL sources](https://rayfin.ai/docs/connectors/sql-sources.md): Read and write Fabric SQL connector entities from Rayfin apps, including query chains, by-key reads, mutations, defaults, and troubleshooting.
- [Data](https://rayfin.ai/docs/data.md): Model entities once as decorated TypeScript classes and get a database schema, GraphQL API, type-safe client, permissions, and validation from the same source.
- [Aggregations](https://rayfin.ai/docs/data/aggregations.md): Compute sums, averages, minimums, maximums, and counts over your entities with groupBy() and aggregate(), including grand totals and having filters.
- [Field types](https://rayfin.ai/docs/data/field-types.md): Complete reference for Rayfin's field decorators — @uuid, @text, @int, @decimal, @boolean, @date, @email, @set, and @blob — and the options each accepts.
- [Schema changes](https://rayfin.ai/docs/data/migrations.md): Apply Rayfin entity changes to the database with rayfin up and rayfin up db apply, and verify the schema actually reached the server.
- [Modeling entities](https://rayfin.ai/docs/data/modeling.md): Define Rayfin entities as decorated TypeScript classes in rayfin/data/ and register them in schema.ts to get a database table and a typed API.
- [Creating, updating, deleting](https://rayfin.ai/docs/data/mutations.md): Create, update, and delete Rayfin records through the type-safe client, and set relationship fields correctly in mutations.
- [Permissions and row-level security](https://rayfin.ai/docs/data/permissions.md): Secure Rayfin entities with @role, @anonymous, and @authenticated, including row-level policies, field visibility, action-specific rules, and multi-tenant scoping.
- [Querying](https://rayfin.ai/docs/data/querying.md): Read Rayfin entities with the type-safe select/where/orderBy/execute chain, including filtering, sorting, and cursor pagination.
- [Relationships](https://rayfin.ai/docs/data/relationships.md): Model one-to-many associations between Rayfin entities with @one and @many, and work around the lack of native many-to-many support.
- [Seeding data](https://rayfin.ai/docs/data/seeding.md): Populate @anonymous() Rayfin entities with RayfinServerClient in a Node.js script — @authenticated() entities have no scripted seeding path today.
- [Validation](https://rayfin.ai/docs/data/validation.md): Generate a Standard Schema validator directly from a Rayfin entity to validate form input without a separate validation library.
- [Deploy](https://rayfin.ai/docs/deploy.md): Deploy Rayfin projects to managed Fabric apps, manage deployment targets, and understand capacity and static hosting.
- [Deployment pipelines](https://rayfin.ai/docs/deploy/deployment-pipelines.md): Prepare Rayfin apps for Microsoft Fabric Deployment Pipelines by resolving runtime config instead of baking stage values into the bundle.
- [Environments and configuration](https://rayfin.ai/docs/deploy/environments.md): Understand Rayfin environment files, deployment records, frontend variables, and workspace targeting rules.
- [Fabric apps](https://rayfin.ai/docs/deploy/fabric-apps.md): Understand the Fabric App (preview) item Rayfin deploys into, including services, permissions, capacity, and portal creation.
- [Capacity and billing](https://rayfin.ai/docs/deploy/pricing.md): Learn which Fabric services behind a Rayfin app consume capacity units and which deployment operations have no separate Rayfin charge.
- [Deploying with rayfin up](https://rayfin.ai/docs/deploy/rayfin-up.md): Deploy a Rayfin project with rayfin up, including login, capacity readiness, targeting flags, dry runs, and deployment metadata.
- [Secrets](https://rayfin.ai/docs/deploy/secrets.md): Set, list, delete, and type Rayfin secrets so functions can read server-only values without exposing them to client code.
- [Deployment troubleshooting](https://rayfin.ai/docs/deploy/troubleshooting.md): Fix common rayfin up, capacity, static hosting, and deployment-target errors using exact CLI messages.
- [Functions](https://rayfin.ai/docs/functions.md): Run server-side TypeScript in Rayfin with typed frontend calls, typed secrets, and app-identity connections to Azure and Fabric resources.
- [Calling functions from your app](https://rayfin.ai/docs/functions/calling-functions.md): Invoke Rayfin functions from the frontend with RayfinClient, AppFunctionsSchema, per-call options, and local Vite routing.
- [Connections](https://rayfin.ai/docs/functions/connections.md): Give Rayfin functions app-identity tokens for Fabric SQL, OneLake, Fabric REST, Azure AI Foundry, and Azure DevOps.
- [Deploying functions](https://rayfin.ai/docs/functions/deploying.md): Deploy Rayfin functions with rayfin up, deploy only function code, skip function deploys, and understand deploy-time packaging.
- [Run functions locally](https://rayfin.ai/docs/functions/local-development.md): Start the local Rayfin Functions host with rayfin dev, route frontend calls, attach a debugger, and troubleshoot local host errors.
- [Secrets in functions](https://rayfin.ai/docs/functions/secrets.md): Declare Rayfin secrets with the CLI, read them as typed ctx.Secrets properties, and supply local values through local.settings.json.
- [Writing a function](https://rayfin.ai/docs/functions/writing-functions.md): Register Rayfin functions with udf.func, use RayfinContext for typed data access, and keep generated frontend types in sync.
- [Static content hosting](https://rayfin.ai/docs/hosting.md): Configure Rayfin static hosting, asset access, package version declarations, deployment commands, and the 100 MB archive limit.
- [Deep linking](https://rayfin.ai/docs/hosting/deep-linking.md): Use @microsoft/rayfin-app-state-fabric to store shareable app state in Fabric portal URLs for embedded Rayfin apps.
- [Redirect URIs](https://rayfin.ai/docs/hosting/redirect-uris.md): Configure allowedRedirectUris for Fabric SSO, local rayfin dev ports, static hosting origins, and retained frontend port aliases.
- [Recipes](https://rayfin.ai/docs/recipes.md): End-to-end walkthroughs that combine Rayfin's data, auth, and deployment features into complete application patterns.
- [Testing a Rayfin app](https://rayfin.ai/docs/recipes/testing.md): Test Rayfin data and auth logic in Vitest with injectable auth stubs and the todo template's in-memory data seam.
- [Build a todo app](https://rayfin.ai/docs/recipes/todo-app.md): Build a Fabric-authenticated todo app end to end, from a per-user data model through a React UI to a deploy on Microsoft Fabric.
- [Reference overview](https://rayfin.ai/docs/reference.md): Landing page for the complete Rayfin reference — CLI commands, configuration schema, SDK packages, rules for coding agents, known limitations, deprecations, and troubleshooting.
- [Rules for coding agents](https://rayfin.ai/docs/reference/agent-rules.md): The condensed set of rules and anti-patterns for writing Rayfin code — read this before generating entities, queries, permissions, functions, connectors, or deployment commands.
- [Changelog](https://rayfin.ai/docs/reference/changelog.md): What changed in each Rayfin release these docs cover — new features, behavior changes, and step-by-step upgrade instructions, linked to the pages that document them.
- [CLI](https://rayfin.ai/docs/reference/cli.md): Overview of the rayfin CLI — root options, the Fabric development workflow, and links to every visible command in Rayfin 1.36.2.
- [rayfin init ai-files](https://rayfin.ai/docs/reference/cli/ai-files.md): Install, refresh, disable, and audit Rayfin-managed agent files with rayfin init ai-files install and status.
- [rayfin connector](https://rayfin.ai/docs/reference/cli/connector.md): rayfin connector manages external Fabric sources, from discovery and registration through inspection and invocation.
- [rayfin dev](https://rayfin.ai/docs/reference/cli/dev.md): Start a local frontend and optional Functions runtime against a deployed Fabric Rayfin backend with rayfin dev.
- [rayfin docs](https://rayfin.ai/docs/reference/cli/docs.md): Search, list, fetch, discover, and inspect Rayfin package documentation from the terminal with rayfin docs.
- [rayfin env](https://rayfin.ai/docs/reference/cli/env.md): Emit framework-specific .env.local files from rayfin/.env for Vite, Next.js, or plain frontend tooling.
- [rayfin functions](https://rayfin.ai/docs/reference/cli/functions.md): Command reference for scaffolding, running, and deploying Rayfin Functions projects with functions init and related dev/up commands.
- [rayfin init](https://rayfin.ai/docs/reference/cli/init.md): Scaffold a new Rayfin project, add Rayfin to an existing directory, select templates, and choose services with rayfin init.
- [CLI installation](https://rayfin.ai/docs/reference/cli/installation.md): Install @microsoft/rayfin-cli for a project, verify the version, and keep the CLI aligned with the Rayfin packages in package.json.
- [rayfin login](https://rayfin.ai/docs/reference/cli/login.md): Sign in to Rayfin for Fabric operations, inspect status, sign out, and understand token cache storage.
- [rayfin secret](https://rayfin.ai/docs/reference/cli/secret.md): Command reference for setting, listing, deleting, describing, bulk importing, and typing Rayfin secrets for Functions.
- [Telemetry](https://rayfin.ai/docs/reference/cli/telemetry.md): What Rayfin CLI telemetry records, what it never records, and the environment variables that control telemetry.
- [Templates](https://rayfin.ai/docs/reference/cli/templates.md): Use built-in, local, git, and registered Rayfin templates, including the 1.36 universal-app starter and registry behavior.
- [rayfin up](https://rayfin.ai/docs/reference/cli/up.md): Deploy a Rayfin project to Fabric, resolve workspace and capacity, apply schema and settings, and run deploy-only up subcommands.
- [Configuration](https://rayfin.ai/docs/reference/config.md): Reference for Rayfin project configuration, environment variables, and rayfin.yml interpolation in Rayfin 1.36.2.
- [Environment variable interpolation](https://rayfin.ai/docs/reference/config/env-interpolation.md): Use ${VAR} and ${VAR:-default} in rayfin.yml with Rayfin's .env resolution, type coercion, and missing-variable errors.
- [Environment variables](https://rayfin.ai/docs/reference/config/environment-variables.md): Exhaustive Rayfin 1.36.2 environment variable reference for frontend builds, CLI overrides, feature flags, telemetry, and file locations.
- [rayfin.yml reference](https://rayfin.ai/docs/reference/config/rayfin-yml.md): Complete Rayfin 1.36.2 rayfin.yml schema for services, static hosting, Functions, storage, connectors, and secret declarations.
- [Deprecations](https://rayfin.ai/docs/reference/deprecations.md): APIs, settings, and flags deprecated or removed in recent Rayfin releases with their replacements, and how to silence Rayfin's deprecation warnings.
- [Errors and troubleshooting](https://rayfin.ai/docs/reference/errors.md): A symptom-to-fix index of the errors Rayfin builders hit most — deployment, capacity, static hosting, schema apply, secrets, functions, connectors, and Fabric auth.
- [Known limitations](https://rayfin.ai/docs/reference/known-limitations.md): Current constraints in Rayfin — service availability, functions, connectors, the data client, Data API Builder, relationships, auth, and schema apply — each with a workaround.
- [SDK](https://rayfin.ai/docs/reference/sdk.md): Choose the right @microsoft/rayfin-* package, keep package versions in lockstep, and find each SDK reference page.
- [@microsoft/rayfin-app-state-fabric](https://rayfin.ai/docs/reference/sdk/rayfin-app-state-fabric.md): SDK reference for Fabric-hosted deep-link state: createFabricAppStateClient, state limits, capabilities, listeners, and errors.
- [@microsoft/rayfin-auth](https://rayfin.ai/docs/reference/sdk/rayfin-auth.md): Auth client reference for sessions, storage options, refresh, sign-out, events, and provider integration points in Rayfin apps.
- [@microsoft/rayfin-auth-provider-fabric](https://rayfin.ai/docs/reference/sdk/rayfin-auth-provider-fabric.md): Fabric auth provider reference for Fabric SSO, direct Entra token exchange, embedded handoff, and external embed support.
- [@microsoft/rayfin-client](https://rayfin.ai/docs/reference/sdk/rayfin-client.md): RayfinClient construction, configuration options, and the client.data, client.auth, and client.functions facades, with exact signatures from the SDK.
- [@microsoft/rayfin-connector-fabric-graphql](https://rayfin.ai/docs/reference/sdk/rayfin-connector-fabric-graphql.md): Marker APIs for Category A Fabric SQL connectors that expose typed entity CRUD through client.connectors.
- [@microsoft/rayfin-connector-fabric-semanticmodel](https://rayfin.ai/docs/reference/sdk/rayfin-connector-fabric-semanticmodel.md): Marker, runtime, direct execution, URL parsing, Arrow decoding, and normalized result APIs for Fabric semantic model connectors.
- [@microsoft/rayfin-connector-kusto](https://rayfin.ai/docs/reference/sdk/rayfin-connector-kusto.md): Marker, runtime, config, raw response, and normalization APIs for Fabric KQL Database connectors.
- [@microsoft/rayfin-connectors](https://rayfin.ai/docs/reference/sdk/rayfin-connectors.md): Connector runtime APIs for mounting typed Fabric SQL, semantic model, and KQL Database connectors on the Rayfin client.
- [@microsoft/rayfin-core](https://rayfin.ai/docs/reference/sdk/rayfin-core.md): Complete decorator reference for @microsoft/rayfin-core — entities, field types, relationships, and permissions that generate Data API Builder configuration.
- [@microsoft/rayfin-data](https://rayfin.ai/docs/reference/sdk/rayfin-data.md): The fluent GraphQL query and mutation API behind client.data — select, where, orderBy, pagination, and CRUD methods with exact signatures.
- [@microsoft/rayfin-embed-host](https://rayfin.ai/docs/reference/sdk/rayfin-embed-host.md): Parent-page SDK reference for brokering external Entra authentication into a Rayfin app embedded in an iframe.
- [@microsoft/rayfin-functions](https://rayfin.ai/docs/reference/sdk/rayfin-functions.md): SDK reference for FunctionClient, FunctionsSchema, InvokeOptions, FunctionsError, and typed client.functions invocations.
- [@microsoft/rayfin-lib](https://rayfin.ai/docs/reference/sdk/rayfin-lib.md): The shared ApiClient, error classes, and small utilities every other Rayfin SDK package builds on — an internal dependency most builders never import directly.
- [@microsoft/rayfin-storage](https://rayfin.ai/docs/reference/sdk/rayfin-storage.md): Type-safe client SDK for experimental Rayfin Storage folders, including client composition, operation options, result shapes, and error codes.
- [Deploy to Fabric](https://rayfin.ai/docs/start/deploy-to-fabric.md): Enable Fabric apps, sign in, deploy a Rayfin project with rayfin up, and confirm the static hosting URL.
- [Develop locally](https://rayfin.ai/docs/start/develop-locally.md): Use rayfin dev to provision or reuse a Fabric backend while running the frontend and Functions locally.
- [Installation](https://rayfin.ai/docs/start/installation.md): Install Node.js 20+ and the Rayfin project CLI workflow before scaffolding or deploying a Fabric app.
- [Project structure](https://rayfin.ai/docs/start/project-structure.md): Understand the Rayfin scaffold layout, including rayfin.yml, deployment metadata, environment files, and the 1.36 universal app workspace.
- [Quickstart](https://rayfin.ai/docs/start/quickstart.md): Scaffold a Rayfin project, sign in to Fabric, run the local development loop, and deploy the app with rayfin up.
- [Storage](https://rayfin.ai/docs/storage.md): Enable experimental Rayfin Storage, declare blob folders, configure object rules, and call the typed storage client.
