Architecture

This page describes the architecture of PostgREST.

Bird’s Eye View

../_images/arch.png

Code Map

This section talks briefly about various important modules.

Main

The starting point of the program is Main.hs.

CLI

Main then calls CLI.hs, which is in charge of CLI.

App

App.hs is then in charge of composing the different modules.

Auth

Auth.hs is in charge of Authentication.

Api Request

ApiRequest.hs is in charge of parsing the URL query string (following PostgREST syntax), the request headers, and the request body.

A request might be rejected at this level if it’s invalid. For example when providing an unknown media type to PostgREST or using an unknown HTTP method.

Plan

Using the Schema Cache, Plan.hs fills in out-of-band SQL details (like an ON CONFLICT (pk) clause) required to complete the user request.

A request might be rejected at this level if it’s invalid. For example when doing resource embedding on a nonexistent resource.

Query

Query.hs generates the SQL queries (parametrized and prepared) required to satisfy the user request.

Only at this stage a connection from the pool might be used.

Schema Cache

SchemaCache.hs is in charge of Schema Cache.

Config

Config.hs is in charge of Configuration.

Admin

Admin.hs is in charge of the Admin Server.

HTTP

The HTTP server is provided by Warp.

Listener

Listener.hs is in charge of the Listener.