Swampy is an open source web app boilerplate with generic features (like authentication) that every app needs. With it, you can fast forward through project set up and get right into developing the core features of your app.
For a list of technologies and features included with Swampy, check out Swampy.rocks.
Swampy has an intuitive project structure where it’s easy to add and customize functionality while maintaining organization.
The top level directory contains standard configuration files. This is where you can configure:
Public resources are stored here. This is mainly for images, but any public file can be included here.
Scripts that are meant to run somewhere outside of the normal application code are kept here. Swampy includes some database scripts that set up a few important triggers on the database.
Files for managing Prisma’s object-relational-mapping for the PostgresSQL database. Here you can manage database schema and look through past migrations.
This is where the main body of your application’s code lives.
In the top level there are files for enabling the overarching style settings. Most importantly, getDesignTokens.ts
contains the custom theming for Swampy. This file can be modified to support any custom theming. Check out MUI’s documentation on custom theming.
This folder contains components that render each page for a given path. See the Next JS routing documentation for additional details.
The api
folder allows you to create API paths using Next JS routing. We've already added some routes as modules to contain grouped end points. The routes can be freely customized. There's a functions folder to illustrate a hello-world function which is used in the example cron job. Technically every API end point is a serverless function by default in Next JS when deployed with Vercel, so you may not want a dedicated functions folder.
Common contains general components and utils that don’t belong to a specific module.
The modules folder contains a large chunk of applications code that has been separated into modules. New modules can easily be added to this folder as your project grows. Most modules are pretty self explanatory but here’s a brief description of them:
Module folders typically follow a similar structure:
In this section we will cover the recommended step by step process that will get your new application completely set up, running, and ready to be customized in under 1 hour.
Note that this guide is written primarily for Windows 10 dev environment and hasn’t been tested in other environments, but similar steps should work on MacOS and Linux.
Some steps need to be taken once, and then you’ll be able to set up and develop any number of Swampy applications in your local environment.
/etc/hosts
on Linux, /private/etc/hosts
on Mac OS X, or C:\Windows\System32\Drivers\etc\hosts
on Windows. When debugging your projects you can access them via http://localhost.internal:3000
. You can use a different domain if you wish, but you’ll need to update the NEXT_PUBLIC_CURRENT_URL
and NEXT_PUBLIC_CURRENT_DOMAIN
variables inside .env.development
in your projects. See https://docs.hcaptcha.com/#local-development.127.0.0.1 localhost.internal
git clone https://github.com/oliver-tunebat/swampy.git cd swampy/ git remote set-url origin <YOUR REPOSITORY URL> git push -f git remote add swampy https://github.com/oliver-tunebat/swampy.git npm install
.example
from .env.example
and .env.local.example
. Delete extraneous comments in these files.Next we will get the application connected with Supabase so that it will have authentication and a database.
.env.local
and .env.development
.http://localhost.internal:3000
unless you picked a picked a different domain.Swampy uses hCaptcha to secure authentication forms so follow these steps to get hCaptcha set up and working with Supabase.
.env.development
and .env.production
.By default email authentication will be ready to go. Swampy already has implementations for several third party providers. More can be added quite easily inside the Supabase dashboard.
Note that Supabase allows up to 2 projects in their free tier (good for an initial dev and prod environment), and beyond that each project carries with it a monthly charge. You can pause any free projects that aren’t currently being worked on in order to support additional free projects.
Supabase provides a PostgresSQL database that is connected to your project by default. We will use Prisma to manage schema and connect to the DB in the code. If you run into any issues during these steps, or want to see more details, refer to these Supabase docs.
DIRECT_URL
variable in .env
. Make sure to add the correct password to the connection string.DATABASE_URL
variable in .env
. Make sure to add the correct password to the connection string. Append ?pgbouncer=true
to the end of this connection string.npx prisma migrate dev
to apply the schema to your database.scripts/database/triggers
.Now your application should be ready to run with nearly full operations.
You can start playing around with and customizing the application. You’ll still want to set up a production environment, analytics and transactional emails. Keep reading to learn how to set these up.
Setting up the production environment takes the same steps as setting up the dev environment. Just follow the above steps again to set it up your production environment.
Note that when deployed on Vercel, Plausible will use a proxy script by default to circumvent tracking blockers.
.env.local
file for SENDGRID_API_KEY
.{{SITE_URL}}
and {{UNSUBSCRIBE_URL}}
to embed the correct link destinations in your templates. Swampy has two transactional emails you may want to make templates for:
.env.local
..env.local
file.You can also optionally configure your own templates for authentication related emails that Supabase sends. This can be done in Authentication > Email Templates.
Swampy was designed with the intention of being deployed on Vercel to take advantage of Vercel’s high performance and excellent support for NextJS. We’ll go over some of the steps that need to be taken to get a good deployment on Vercel. But it is also recommended that you check out Vercel’s documentation for a more comprehensive look at your options.
You may also choose to protect your application with Cloudflare. If you do, make sure to go to SSL/TLS > Overview in Cloudflare and set encryption mode to Full. You may see a bug where your site won’t load with too many redirects if the wrong setting is applied here.
Going forward, Swampy will receive regular updates with new features and enhancements. You probably want to bring these changes into your application so follow these steps to update your code base.
main
branch from the Swampy repo into your dev branch.git fetch swampy git merge swampy/main
npm install
if there were any package changes.Whenever a new Swampy release becomes available, make sure to read the release notes for details on bringing that specific release into your code.