Skip to content
Documentation

Documentation

Melange is an OpenFGA-to-PostgreSQL compiler. It takes your authorization model (written in OpenFGA DSL) and compiles it into specialized PostgreSQL functions that run permission checks directly inside your database.

What is an Authorization Compiler?

The pattern is similar to Protocol Buffers or GraphQL Code Generator: define a schema, run a compiler, get code tailored to your definitions.

Melange applies this pattern to authorization:

    flowchart LR
    schema["schema.fga<br/>(OpenFGA DSL)"] --> melange["melange<br/>compile"]
    melange --> funcs["PostgreSQL Functions<br/>(check_permission, etc)"]
  

Instead of a generic runtime that interprets your model at query time, Melange generates a SQL function for each relation in your schema. The authorization logic runs as PostgreSQL code: transaction-aware, query-planned, and with zero network hops.

How It Works

  1. Define your model - Write an OpenFGA schema (.fga file) describing types, relations, and permission rules
  2. Compile to SQL - Run melange migrate to generate and install specialized PostgreSQL functions
  3. Query permissions - Call the generated functions from any language or directly in SQL

Read more about Melange’s architecture and how it works here.

Why Compile to PostgreSQL?

Traditional FGAMelange
Separate authorization serviceAuthorization lives in your database
Network round-trip for every checkSingle SQL query
Eventual consistency with your dataTransaction-aware, always consistent
Generic graph traversal at runtimeSpecialized functions per relation
Sync tuples to external storeQuery your existing tables directly

Key Features

  • Per-Relation Code Generation - Each relation gets its own check function, not a generic interpreter
  • Works with Your Tables - Permissions derived from a view over your existing data (no tuple sync)
  • Transaction Aware - Permission checks see uncommitted changes within the same transaction
  • Language Agnostic - Generated SQL functions callable from Go, Python, Node.js, or any PostgreSQL client
  • OpenFGA Compatible - Use familiar OpenFGA DSL syntax for authorization models

Getting Started

Concepts

Architecture and design.

Guides

Using Melange’s client libraries, middleware patterns, and operational workflows. For direct SQL access, see the SQL API reference.

Reference

Technical reference documentation.

Contributing