RAIQL 1.0
The normative surface implemented by the current RAIQL compiler. This specification defines supported top-level statements and their structural meaning.
Lexical model
Keywords are case-insensitive. Application names are double-quoted strings. Top-level statements terminate with a semicolon. Comments beginning with -- are removed to end of line; lines beginning with # are also treated as comments.
Grammar overview
program := statement*
statement := application | appType | stack | entity | userEntity | tenantEntity | relation
| ownership | tenancy | crud | api | authentication | roles | defaultRole
| permission | environment | secret | observability | event | job | generateOpenApi | generateSdk | generateTests | build | deploy
application := CREATE APPLICATION STRING [TYPE APP_TYPE] ;
appType := TYPE (WEB | MOBILE | API) ;
stack := USE STACK stackEntry (, stackEntry)* ;
entity := CREATE ENTITY IDENTIFIER ( field (, field)* ) ;
userEntity := CREATE USER ENTITY IDENTIFIER ;
tenantEntity := CREATE TENANT ENTITY IDENTIFIER ;
relation := RELATE reference TO reference ;
ownership := OWN IDENTIFIER BY IDENTIFIER ;
tenancy := TENANT IDENTIFIER BY IDENTIFIER ;
crud := CREATE CRUD IDENTIFIER ;
api := CREATE API IDENTIFIER ;
authentication := ADD AUTHENTICATION IDENTIFIER (, IDENTIFIER)* ;
roles := ADD ROLE IDENTIFIER (, IDENTIFIER)* ;
defaultRole := DEFAULT ROLE IDENTIFIER ;
permission := ALLOW IDENTIFIER permissionItem (, permissionItem)* ;
permissionItem := (CREATE | READ | UPDATE | DELETE) [OWN] IDENTIFIER
environment := ENVIRONMENT IDENTIFIER (, IDENTIFIER)* ;
secret := SECRET IDENTIFIER (, IDENTIFIER)* ;
observability := ADD OBSERVABILITY IDENTIFIER (, IDENTIFIER)* ;
event := EVENT IDENTIFIER FROM IDENTIFIER ;
job := JOB IDENTIFIER ON IDENTIFIER ;
generateOpenApi := GENERATE OPENAPI ;
generateSdk := GENERATE SDK TYPESCRIPT ;
generateTests := GENERATE TESTS ;
build := BUILD ;
deploy := DEPLOY [IDENTIFIER] ;Application declarations
A program must contain exactly enough information to establish an application name. If no application type is supplied, compilation produces a warning rather than an error.
CREATE APPLICATION "Ledger" TYPE API;Cross-reference rules
CREATE CRUD, CREATE API, both sides of RELATE and OWN must reference declared entities and fields. ALLOW must reference a declared role. ... OWN Entity permissions require a matching OWN Entity BY field declaration. Violations are compiler errors.
Identity, JWT and ownership semantics
For runnable WEB/API + NEXTJS generation, ADD AUTHENTICATION JWT generates HS256 bearer-token verification. CREATE USER ENTITY, EMAIL_PASSWORD and DEFAULT ROLE define persisted application identity. RAIQL 1.0 adds OWN Entity BY field and scoped permissions such as READ OWN Order. PostgreSQL handlers enforce OWN rules by comparing the declared owner field with the JWT sub claim; CREATE OWN writes the authenticated subject server-side rather than trusting client input.
Environments and secrets
ENVIRONMENT declares named execution profiles. SECRET declares required environment-variable names only; values are intentionally excluded from RAIQL source and generated IR. The CLI stores local profile values under .raiql/env and can validate/run a selected profile with --env.
Compatibility contract
RAIQL 1.0 separates project schema, language contract and plugin API versions. These are recorded in raiql.config.json and generated raiql.compatibility.json. The RAIQL 1.0 compiler accepts supported older project metadata in compatible mode and the CLI can migrate metadata with raiql migrate without silently rewriting source when no grammar change is required.
Production cloud adapter
DEPLOY AWS ECS; requests the AWS ECS/Fargate adapter. It generates Docker/ECS task and service artifacts, AWS Secrets Manager mappings and an execution-role policy using placeholders rather than credentials. raiql deploy --env production --target aws-ecs prepares a non-secret deployment plan; remote cloud mutation remains explicit outside the compiler.
Compilation result
A successful compilation emits a JSON-serializable RAIQL intermediate representation containing application metadata, stack selections, entities, relationships, APIs, CRUD intent, authentication mechanisms, user-identity metadata, default role, roles, permissions, ownership declarations and delivery actions.
For WEB applications targeting NEXTJS, RAIQL 1.0 emits runnable Next.js applications with entity workspaces and HTTP CRUD routes. TYPE API reuses the same server adapters without CRUD workspace pages. TYPE MOBILE with FRONTEND EXPO and BACKEND REMOTE emits a runnable Expo SDK 57 API client. DATABASE MEMORY provides zero-setup evaluation, while DATABASE POSTGRESQL additionally emits a Prisma schema, PostgreSQL driver integration, Docker Compose database service and migration workflow. With EMAIL_PASSWORD, PostgreSQL output also includes a generated user model, salted scrypt password hashing, registration/login APIs and UI, JWT issuance and session-aware protected CRUD requests. Ownership-aware output additionally filters reads and verifies updates/deletes against the authenticated subject.
Executable targets
TYPE WEB supports Next.js full-stack generation, TYPE API supports Next.js API-service generation, and TYPE MOBILE supports Expo SDK 57 client generation. Mobile output consumes a remote API configured with EXPO_PUBLIC_RAIQL_API_URL; it does not embed a PostgreSQL server into the native application.
Generated tests
GENERATE TESTS; requests executable verification. RAIQL 1.0 emits target-aware Vitest tests, and raiql test executes them.
Dependency hardening
Dependency locking and audit behavior are CLI/generator delivery semantics rather than new RAIQL grammar. Generated runnable projects use exact dependency declarations and security metadata; raiql lock creates a reproducible package lock and raiql audit checks dependency policy and npm advisories.
API contract generation
GENERATE OPENAPI; emits an OpenAPI 3.1 contract. GENERATE SDK TYPESCRIPT; emits a typed client from the same compiled entities and API declarations.
Tenant semantics
CREATE TENANT ENTITY declares the tenant identity model. TENANT Entity BY field makes that field server-managed in generated PostgreSQL APIs. Requests carry tenant context in x-raiql-tenant-id; generated reads, creates, updates and deletes enforce the scope.
Events and jobs
EVENT Name FROM Entity connects creation of an entity to an outbox event. JOB Name ON Event declares a generated worker handler. RAIQL 1.0 executes this model through the generated PostgreSQL outbox and worker adapter.
Deployment adapters
DEPLOY DOCKER, DEPLOY DOCKER_COMPOSE and DEPLOY KUBERNETES are concrete generator targets in RAIQL 1.0. DEPLOY AWS ECS adds the production ECS/Fargate artifact adapter. Multiple DEPLOY statements may coexist.
Observability
ADD OBSERVABILITY HEALTH, LOGS, METRICS, TRACES; selects generated operational surfaces. HEALTH and METRICS create API endpoints; generated resource handlers call the observability runtime for counters, structured logs and correlation IDs.
Extension model
Plugins are project-level compiler/generator extensions configured in raiql.config.json; they do not add grammar in RAIQL 1.0. Plugin API 1 receives a JSON-compatible copy of the compiled IR and generated-file map. Plugins may emit diagnostics and additive text files. Core-file replacement is rejected.
Registry distribution
The official plugin registry is a CLI distribution layer, not language grammar. Registry records declare plugin API compatibility, download URLs and SHA-256 digests. Installed registry plugins are copied into the project and then execute through the same plugin API 1 contract as local plugins.
Stable contract
RAIQL 1.0 freezes the grammar implemented by 0.23, IR field semantics, plugin API 1 and core output contract 1. The 0.23 → 1.0 migration is metadata-only for valid 0.23 programs.
Versioning
This specification describes language version 1.0. RAIQL 1.0 is the frozen stable grammar. 1.0.x maintenance releases may fix bugs and generators but must not add top-level syntax or reinterpret valid 1.0 source. Incompatible grammar changes require a future major version.