Guard / How Guard works
How Guard works
In most applications, permission checks live scattered across route handlers, SQL queries, forms, and background jobs. When you add an endpoint or a role, you have to find every check and update it by hand. One missed WHERE clause leaks another customer's rows, and one forgotten field check lets a user change their own role.
foldkit-guard lets you declare access rules once on your data model. Row rules compile straight into SQL WHERE clauses for multi-tenant reads, run on the server when saving writes, and generate permission hints for your UI and forms. To see a full app running with sign-in and guarded notes, look at examples/auth or examples/chirp.
You describe each table as an Entity (a schema of typed fields from foldkit-entity, built on Effect Schema) and the signed-in user as a principal (a typed record built from your session). foldkit-guard splits permissions into server-only checks on the user and data-driven rules over rows.