Skip to content

Commit e9ab3ea

Browse files
committed
2 parents 577aedd + 53ae86d commit e9ab3ea

File tree

8 files changed

+144
-115
lines changed

8 files changed

+144
-115
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ flowchart TD
2424

2525
## 🚀 Quick Start
2626

27-
1. **Clone SuperStack and start the stack:**
27+
1. Click [Use this
28+
template](https://github.com/explodinglabs/superstack/generate) and create a
29+
new repository on Github.
30+
31+
2. Clone your new repository and start SuperStack:
2832

2933
```sh
30-
git clone https://github.com/explodinglabs/superstack myapp
34+
git clone https://github.com/yourname/myapp.git
3135
cd myapp
3236
cp example.env .env
3337
docker compose up -d
3438
```
3539

36-
2. **Explore your API**
37-
38-
Open [http://localhost:8000/openapi/](http://localhost:8000/openapi/) in your
39-
browser to view and test endpoints using Swagger UI.
40+
Open [http://localhost:8000/openapi/](http://localhost:8000/openapi/) to view
41+
your Swagger UI.
4042

4143
## 📚 Full Documentation
4244

docs/authentication.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Edit `postgres/Dockerfile` to build and install the extension:
2020

2121
```sh
2222
RUN apt-get update && apt-get install -y \
23-
build-essential \
24-
postgresql-server-dev-17
23+
build-essential \
24+
postgresql-server-dev-17
2525

2626
# pgjwt - used by auth schema
2727
COPY ./pgjwt /pgjwt
@@ -31,10 +31,11 @@ RUN make && make install
3131
WORKDIR /var/lib/postgresql
3232
```
3333

34-
Then rebuild:
34+
Then rebuild the Postgres image and recreate the container:
3535

3636
```sh
3737
docker compose build postgres
38+
docker compose up -d postgres
3839
```
3940

4041
## ➡️ 2. Add Migrations
@@ -44,7 +45,9 @@ docker compose build postgres
4445
Add this to a migration file like `01-extensions.sql`:
4546

4647
```sql
47-
-- pgcrypto adds public.crypt used in auth.encrypt_pass
48+
/* pgcrypto adds public.crypt used in auth.encrypt_pass pgjwt also needs this
49+
so it must be loaded first. pgcrypto is built into Postgres, so no need to
50+
install it. */
4851
create extension pgcrypto;
4952

5053
-- pgjwt adds public.sign used in auth.generate_access_token
@@ -212,7 +215,7 @@ commit;
212215

213216
### 👮 Grant Permissions
214217

215-
Add another migration such as `99-roles_and_grants.sql`:
218+
Add another migration such as `99-grants.sql`:
216219

217220
```sql
218221
begin;
@@ -241,14 +244,57 @@ applied.
241244
Add the auth schema to Postgres in `compose.yaml`:
242245

243246
```yaml
244-
PGRST_DB_SCHEMAS: api,auth
247+
postgrest:
248+
environment:
249+
PGRST_DB_SCHEMAS: api,auth
245250
```
246251
247-
✅ Usage
252+
And recreate the PostgREST container:
248253
249-
Explain that all auth endpoints must have a certain header.
254+
```sh
255+
docker compose up -d postgrest
256+
```
257+
258+
## ✅ Usage
259+
260+
To use the `auth` schema, requests [must include a
261+
header](https://docs.postgrest.org/en/stable/references/api/schemas.html#multiple-schemas).
262+
263+
GET and HEAD requests should include the header:
264+
265+
```
266+
Accept-Profile: auth
267+
```
268+
269+
Other methods (POST, PATCH, PUT and DELETE) should include:
270+
271+
```
272+
Content-Profile: auth
273+
```
250274

251-
Show example of using each endpoint.
275+
### Examples
276+
277+
Login:
278+
279+
```sh
280+
curl \
281+
-H "Content-Profile: auth" \
282+
-H "Content-Type: application/json" \
283+
--data '{"user_": "demo", "pass": "demo"}' \
284+
http://localhost/rpc/login
285+
```
286+
287+
Get the refresh token inserted when logged in:
288+
289+
```sh
290+
bin/postgres psql -c 'select token from auth.refresh_token order by created_at desc limit 1'
291+
```
292+
293+
Refresh the access token and extract the new token from the Set-Cookie header:
294+
295+
```sh
296+
export ACCESS_TOKEN=$(curl --silent -i -X POST -H 'Cookie: refresh_token='$REFRESH_TOKEN'; HttpOnly' http://localhost/rpc/refresh_token |sed -nE 's/^Set-Cookie: access_token=([^;]*).*/\1/p')
297+
```
252298

253299
- POST-ing a user.
254300
- `/rpc/login`

docs/gettingstarted.md

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,39 @@
33
SuperStack uses Docker, so make sure [Docker is
44
installed](https://docs.docker.com/get-docker/) before you begin.
55

6-
## 1. Clone SuperStack
6+
## 1. Get SuperStack
77

8-
```sh
9-
git clone https://github.com/explodinglabs/superstack myapp
10-
cd myapp
11-
```
8+
### Option 1: Use the Template (Recommended)
129

13-
<details>
14-
<summary>Click here to see how to change this clone to point "origin" to your own hosted repository (Recommended)</summary>
10+
The easiest way to get started:
1511

16-
Rename "origin" to "upstream":
12+
1. Click [Use this
13+
template](https://github.com/explodinglabs/superstack/generate) on GitHub.
14+
2. Create a new repository (e.g. `myapp`) from the template.
15+
3. Clone it to your machine:
1716

1817
```sh
19-
git remote rename origin upstream
18+
git clone https://github.com/yourname/myapp.git
19+
cd myapp
2020
```
2121

22-
This way you can still upgrade to a more recent SuperStack with:
23-
24-
```sh
25-
git pull upstream main
26-
```
22+
### Option 2: Clone and Track Upstream (Advanced)
2723

28-
Add your own code repository:
24+
If you want to keep SuperStack’s Git history and pull upstream changes later:
2925

3026
```sh
27+
git clone https://github.com/explodinglabs/superstack.git myapp
28+
cd myapp
29+
git remote rename origin upstream
3130
git remote add origin https://github.com/yourname/myapp
3231
```
3332

34-
Now you can pull/push to your own repo as normal:
33+
You can now pull upstream changes with:
3534

3635
```sh
37-
git pull
38-
git push origin head
36+
git pull upstream main
3937
```
4038

41-
<h3>Why not just fork SuperStack?</h3>
42-
43-
Because you can't make a fork private.
44-
45-
<h3>Why not make SuperStack a template repo?</h3>
46-
47-
Because then you can't pull from upstream SuperStack.
48-
49-
</details>
50-
5139
## 2. Configure Environment Variables
5240

5341
Copy the example file:
@@ -56,8 +44,8 @@ Copy the example file:
5644
cp example.env .env
5745
```
5846

59-
> ⚠️ The .env file is for local development only. For remote deployments,
60-
> set environment variables using CI/CD or inline in the `docker compose up` command (be sure to avoid saving secrets in shell history).
47+
> ⚠️ **The .env file is for local development only.** Don't store real secrets
48+
> in production — use CI/CD environment variables or a secrets manager.
6149
6250
## 3. Start the Stack
6351

@@ -67,19 +55,20 @@ docker compose up -d
6755

6856
That's it – your backend is live.
6957

70-
You can now open [localhost:8000/openapi/](http://localhost:8000/openapi/)
71-
to explore your API.
58+
You can now open
59+
[http://localhost:8000/openapi/](http://localhost:8000/openapi/) to explore
60+
your API.
7261

7362
---
7463

7564
## 🧩 What Just Happened?
7665

7766
SuperStack automatically:
7867

79-
- Starts a fresh **Postgres** database
80-
- Applies initial **migrations**
81-
- Launches **PostgREST** and **Swagger UI**
82-
- Serves everything through **Caddy**
68+
1. Starts a fresh Postgres database
69+
2. Applies initial migrations
70+
3. Launches PostgREST and Swagger UI
71+
4. Serves everything through Caddy
8372

8473
```mermaid
8574
flowchart TD
@@ -90,14 +79,33 @@ flowchart TD
9079

9180
> 💡 Only Caddy exposes a port – all services are routed through it.
9281
93-
## Nuke everything
82+
## Project Structure
9483

95-
To wipe your stack and start clean:
84+
```
85+
📁 bin/ → Helper scripts (e.g. wrappers for CLI tools)
86+
📁 caddy/ → Custom Caddy configuration and certificates
87+
📁 docs/ → Markdown files for SuperStack documentation
88+
📁 postgres/ → SQL migrations and configuration of the postgres container
89+
📄 compose.yaml → Main Docker Compose config
90+
📄 compose.override.yaml → Optional local overrides (development only)
91+
📄 example.env → Example environment variables — copy to `.env`
92+
📄 LICENSE → License file (MIT)
93+
📄 logo.png → SuperStack logo for README/docs
94+
📄 mkdocs.yml → MkDocs configuration for documentation site
95+
📄 README.md → Overview and quick start for the repository
96+
```
97+
98+
## 🔄 Resetting
99+
100+
If you want to start fresh:
96101

97102
```sh
98103
docker compose down --volumes
104+
docker compose up -d
99105
```
100106

107+
This will wipe your database and re-run all migrations from scratch.
108+
101109
## ➕ What's Next?
102110

103111
👉 [Create your database schema with migrations](migrations.md)

docs/index.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# SuperStack
44

5-
_SuperStack_ is a lightweight, modular backend powered by PostgreSQL —
6-
perfect for indie developers, SaaS builders, and teams who want full
7-
rontrol without the bloat.
5+
_SuperStack_ is a lightweight, modular backend powered by PostgreSQL — perfect
6+
for indie developers, SaaS builders, and teams who want full control without
7+
the bloat.
88

99
Spin up a fully working backend in seconds, with zero setup. Just clone and
1010
run.
@@ -25,11 +25,6 @@ Caddy), making it easy to develop locally or deploy remotely.
2525

2626
---
2727

28-
## 📚 Documentation
28+
## 📚 Get Started
2929

30-
- [Getting Started](gettingstarted.md)
31-
- [Migrations](migrations.md)
32-
- [Postgres Extensions](extensions.md)
33-
- [Authentication](authentication.md)
34-
- [Psql](psql.md)
35-
- [Deploying to Remote Environments](deploying.md)
30+
👉 [Continue to Getting Started](gettingstarted.md)

docs/migrations.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# 📜 Migrations
22

3-
SuperStack includes a simple built-in system for managing database schema
4-
migrations.
3+
SuperStack includes a simple system for managing database schema changes.
54

65
## ✍️ Writing Migrations
76

8-
Place your migration scripts in:
7+
Place SQL scripts in:
98

109
```
1110
postgres/migrations/
@@ -14,9 +13,9 @@ postgres/migrations/
1413
Each file should be:
1514

1615
- A `.sql` file
17-
- Numbered in order (e.g. `00-init.sql`, `01-extensions.sql`, `02-auth.sql`)
16+
- Numbered in order (e.g. `00-init.sql`, `01-extensions.sql`, `02-create_auth_schema.sql`)
1817
- Written in plain SQL
19-
- But can include environment variables.
18+
- But can include environment variables
2019

2120
## ▶️ Applying Migrations
2221

@@ -41,22 +40,10 @@ Already-applied scripts are skipped on subsequent runs.
4140

4241
> 💡 `bin/postgres` is short for `docker compose exec postgres`
4342
44-
## 🔄 Resetting
45-
46-
If you want to start fresh:
47-
48-
```sh
49-
docker compose down --volumes
50-
docker compose up -d
51-
```
52-
53-
This will wipe your database and re-run all migrations from scratch.
54-
5543
## 🔁 Transactions
5644

57-
Use `BEGIN;` and `COMMIT;` to wrap migration files when all included
58-
statements are transactional. This ensures that all changes are applied
59-
atomically.
45+
Use `BEGIN;` and `COMMIT;` to wrap migration files when all included statements
46+
are transactional. This ensures that all changes are applied atomically.
6047

6148
For example:
6249

@@ -78,11 +65,10 @@ create table movie (
7865
commit;
7966
```
8067

81-
> 💡 If your migration script only contains one statement, there's no need
82-
> to use a transaction, the statement will be auto-committed.
68+
> 💡 Statements outside of begin/commit are auto-committed.
8369
84-
Avoid wrapping non-transactional operations in a transaction — these will
85-
cause errors if used inside `BEGIN ... COMMIT`.
70+
Avoid wrapping non-transactional operations in a transaction — these will cause
71+
errors if used inside `BEGIN ... COMMIT`.
8672

8773
Examples of non-transactional statements include:
8874

0 commit comments

Comments
 (0)