svelte-postgrest-template is a boilerplate starter that pairs a Svelte front end with a PostgREST API backend, wired for JWT social authentication and environment-driven AWS deployment.
What is svelte-postgrest-template?
This starter template (by repo owner guyromm) combines the Svelte / SvelteKit component framework with the PostgREST REST API layer over a Postgres database. Instead of writing a custom backend, you define database tables and permissions, and PostgREST publishes them as an API. It targets Node.js environments (tested with node v13.11.0) and ships with scripts for local development and AWS serverless deployment.
What makes svelte-postgrest-template stand out?
- SvelteKit front end — Uses Svelte as the reactive UI framework with SvelteKit for server-side rendering, analogous to how Next.js works for React; the template is set up as a Sapper-style application.
- PostgREST API backend — Turns an existing Postgres schema into an automatically generated REST API with no backend code, and includes the pgjwt PostgreSQL extension for JWT-based auth.
- Social authentication — Integrates beyonk-adventures/svelte-social-auth to add login via Google and Facebook alongside JWT tokens.
- EveryLayout CSS system — Layout components are borrowed from SilvanCodes/svelte-layout-components, based on the Every Layout approach to responsive CSS.
- AWS serverless deployment — Includes Lambda functions that package PostgREST into a Node.js 14.x function, create an RDS database, create a function URL with CORS allowed origins, and wire environment variables. Scripts are provided to create IAM roles and attach the AWSLambdaBasicExecutionRole.
- Environment configuration — Uses envs/local.tpl and envs/aws templates with a setenv.sh script that loads variables; a freeport() helper finds open ports for the app, PostgREST, and the dev server.
- Process management — A tmux.sh script launches PostgREST, the Svelte dev server, and an editor in a tmux session, plus a db_init.sh script to initialize the database.
Who should use svelte-postgrest-template?
- Front-end developers — who want to build a full-stack app without hand-writing server endpoints; they define Postgres tables and get an immediate REST API.
- Svelte developers — who want a production-oriented SvelteKit starter pre-configured with social login and API integration.
- Serverless adopters — who need to deploy PostgREST on AWS Lambda using RDS for Postgres and want ready-made shell scripts for IAM, Lambda, and function URL setup.
What can you do with svelte-postgrest-template?
- Rapid prototyping: clone the repo with npx degit, set environment variables from envs/local.tpl, run ./db_init.sh to initialize the database, and launch everything with ./tmux.sh to get a working SPA with an API in minutes.
- Social login testing: Google and Facebook login flows are wired through the template, letting you plug in OAuth credentials and test JWT-protected endpoints without building auth yourself.
- AWS deployment: follow the 'deploying on aws' section to create a separate envs/aws file, provision an RDS instance, and package PostgREST as a Lambda function with a public function URL.
- Learning PostgREST: see a complete working example of PostgREST JWT auth with pgjwt, including download and setup scripts.
How does svelte-postgrest-template work?
The template is a shell of scripts around a Svelte app. You clone it with npx degit, run ./npm-init.sh to install dependencies, create an env file from the local template, then ./db_init.sh builds the database schema. For AWS, separate scripts create an RDS instance, download PostgREST for Lambda, pack it into function.zip, create the Lambda function and its URL, and update the env file with the returned endpoint. Finally ./tmux.sh starts PostgREST and the dev server inside tmux.
FAQ
What Node.js version is supported?
The template is tested with Node v13.11.0 and uses nvm (Node Version Manager) for easy switching. Package setup runs through an ./npm-init.sh script after running nvm use.
Is social authentication included?
Yes. The template uses the beyonk-adventures/svelte-social-auth package to implement social login providers. The README lists Google and Facebook as available providers, and authentication is handled via JWT using the pgjwt PostgreSQL extension.
What are the prerequisites?
You need PostgREST (installed per the official instructions), the pgjwt PostgreSQL extension for JWT support, and nvm to manage Node versions. The AWS deployment path additionally requires the AWS CLI with permissions to create IAM roles, Lambda functions, and RDS instances.
How do I deploy to AWS?
The README walks through creating an aws env file from the local one, adding an RDS password and VPC group, running lambda/postgrest-download.sh, creating the RDS instance, and then creating the Lambda function with a function URL configured for CORS with AllowOrigins=*. Scripts output the endpoint to envs/aws.




