Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": {
"default": "devs-dev-2027",
"dev": "devs-dev-2027"
}
}
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Formatting-only commits, skipped by `git blame` on GitHub.
# Locally: git config blame.ignoreRevsFile .git-blame-ignore-revs

# chore: reformat repo with prettier
feb6a181acb4f6f70adb3e13327fb88974419795
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Regenerated by the pre-commit hook. On a merge conflict, run `pnpm graph` and stage the result.
kb/assets/dependency-graph.svg -diff linguist-generated=true
36 changes: 36 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Builds and tests the Java API (apps/api). The tests start a Supabase Postgres with
# Testcontainers, apply db/migrations, and check every endpoint's access rules.

name: API

on:
pull_request:
paths: ["apps/api/**", "db/**", ".github/workflows/api.yml"]
push:
branches: [main]
paths: ["apps/api/**", "db/**", ".github/workflows/api.yml"]

permissions:
contents: read

jobs:
test:
name: Build and test
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/api
steps:
- uses: actions/checkout@v5

- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "25"
cache: maven

- name: Test
run: ./mvnw -B verify

- name: Build the Docker image
run: docker build -t devs-api .
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ yarn.lock
.env

#Template for landing page slideshow
public/home/slideshow/template.psd
public/home/slideshow/template.psd
# Firebase CLI cache
.firebase/

# Local DB dump / anonymised seed (contains prod schema incl. secrets)
dump/
supabase/seed.sql

# Supabase CLI local state
supabase/.branches
supabase/.temp

# Personal Claude Code settings
.claude/
7 changes: 7 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Commits are authored by people: reject AI co-author trailers (Claude, ChatGPT, Codex).
if grep -v '^#' "$1" | grep -Eiq '^co-authored-by:.*(claude|anthropic|chatgpt|codex|openai)'; then
echo "Remove the AI Co-Authored-By line from the commit message." >&2
exit 1
fi

pnpm exec commitlint --edit "$1"
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pnpm exec lint-staged
pnpm graph
git add kb/assets/dependency-graph.svg
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
This repository contains the source code for the **DEVS (Developers Society) website**, built with **React, TypeScript, Tailwind CSS, and Vite**.

The project follows a component-first approach with shared design and development guidelines to ensure consistency across the site.

## Documentation

Find all documentation, including a setup guide in the [Knowledge Base](kb/home.md).

## Dependency Graph

Every module in the website (`apps/web/src`) and what it imports. The pre-commit hook regenerates this on each commit, so it stays up to date as the code changes. Run `pnpm graph` to regenerate it manually.

[![Dependency graph of apps/web/src](kb/assets/dependency-graph.svg)](kb/assets/dependency-graph.svg)
4 changes: 4 additions & 0 deletions apps/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
*.iml
.idea
.vscode
3 changes: 3 additions & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
*.iml
.idea/
3 changes: 3 additions & 0 deletions apps/api/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip
17 changes: 17 additions & 0 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Build: compile and package the API. Tests run in CI, where Docker-in-Docker is available.
FROM maven:3.9-eclipse-temurin-25 AS build
WORKDIR /src
COPY pom.xml .
RUN mvn -B -q dependency:go-offline
COPY src src
RUN mvn -B -q -DskipTests package && cp target/devs-api-*.jar /api.jar

# Run: JRE only, as an unprivileged user with nothing writable except the local storage folder.
FROM eclipse-temurin:25-jre-noble
RUN useradd --system --uid 10001 --no-create-home api \
&& mkdir -p /app /data/storage \
&& chown api /data/storage
COPY --from=build /api.jar /app/api.jar
USER 10001
EXPOSE 8080
ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75", "-jar", "/app/api.jar"]
97 changes: 97 additions & 0 deletions apps/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# DEVS API

The only service that reads and writes the DEVS database and file storage. The website calls
this API; it no longer talks to Supabase tables, storage or edge functions directly. Supabase
is still used for logging in (Auth), Postgres and Storage.

Java 25, Spring Boot 4, plain SQL through `JdbcClient`. Database changes live in
[`db/migrations`](../../db/migrations) and are applied by Flyway in CI, never by the API.

## Run it locally

With Docker:

```sh
docker compose up --build # from the repo root
```

This starts a Supabase Postgres on `localhost:54330`, applies every migration, loads fake data
from [`db/seed/dev_seed.sql`](../../db/seed/dev_seed.sql), and runs the API on
`http://localhost:8080`. `docker compose down -v` wipes it.

There's no Supabase Auth in the local stack, so mint a token for one of the seeded users:

```sh
curl localhost:8080/api/events
curl -H "Authorization: Bearer $(apps/api/scripts/dev-token.sh admin)" localhost:8080/api/admin/members
```

`pnpm dev` proxies `/api` to `localhost:8080`, so the website's public pages work against the
local API. Admin pages need a real login: point the API at the shared dev Supabase project
instead (set `SUPABASE_URL` and `SUPABASE_JWT_SECRET` to the dev project's values).

Without Docker, use the Maven wrapper with Java 25 installed: `./mvnw spring-boot:run`, with the
environment variables below pointing at the dev database.

## Tests

```sh
./mvnw verify
```

The integration tests start a Supabase Postgres with Testcontainers, so they need Docker; without
it they're skipped. CI always runs them. `SecurityMatrixTest` walks every endpoint and checks that
anonymous callers get 401 and non-admins get 403, so a new endpoint is covered automatically.

## Configuration

| Variable | What it is |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `DB_URL`, `DB_USER`, `DB_PASSWORD` | Postgres connection. Connect as `api_app` (see below), never `postgres`. |
| `SUPABASE_URL` | The project's URL, e.g. `https://<ref>.supabase.co`. Tokens must be issued by `<url>/auth/v1`. |
| `SUPABASE_JWT_SECRET` | Legacy HS256 JWT secret. Leave empty if the project uses signing keys (JWKS). |
| `SUPABASE_SERVICE_ROLE_KEY` | Server-only key for Storage and inviting execs. Never put it in the website's env. |
| `SITE_URL` | The website's address, used for Stripe and invite redirects. |
| `CORS_ALLOWED_ORIGINS` | Comma-separated origins allowed to call the API. |
| `STORAGE_MODE` | `supabase` (default) or `local` (Docker dev). |
| `EMAIL_MODE`, `RESEND_API_KEY`, `CONTACT_EMAIL_TO` | `resend` sends mail; `log` only logs it. |
| `STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET` | Card payments. The webhook endpoint is `/api/webhooks/stripe`. |
| `MARKETING_APPS_SCRIPT_URL` | The Google Apps Script that writes marketing requests to the sheet. |
| `FORWARD_HEADERS_STRATEGY` | `native` behind a proxy that sets `X-Forwarded-For`, so rate limits see real IPs. |

### The `api_app` database role

Migration `V20261026_0310__api_role.sql` creates `api_app` with grants on exactly the tables the
API uses. It has no password until you set one, once per project, in the SQL editor:

```sql
alter role api_app with password '<generate a long random one>';
```

Then connect through the session pooler as `api_app.<project ref>`.

## How a request is handled

1. CORS, security headers, and a per-IP rate limit on public writes (sign up, RSVP, contact).
2. A bearer token, if sent, must be a Supabase user access token for this project: valid
signature, issuer, audience `authenticated`, role `authenticated`, not expired.
3. The caller's role is read from `public.profiles` on every request. Nothing in the token or
request body can make someone an admin.
4. `SecurityConfig` decides who may call each path. Anything not listed is denied.
5. Request bodies are validated (types, sizes, formats) before any code runs.
6. Writes run in a transaction that first tells Postgres who the caller is (`ActorContext`), so the
existing audit triggers keep recording the real person.
7. Errors come back as `{ status, code, detail }`. No stack traces, SQL or internal names.

## Endpoints

Public: `GET /api/events`, `GET /api/links`, `GET /api/degrees`, `GET /api/degrees/{id}/majors`,
`POST /api/members`, `POST /api/events/{id}/rsvps`, `POST /api/events/{id}/rsvps/bank-transfer`,
`POST /api/events/{id}/rsvps/checkout`, `POST /api/contact`, `POST /api/webhooks/stripe` (Stripe-signed).

Logged in: `GET /api/me`.

Execs (`/api/admin/**`): events, uploads, attendees and payment proofs, members, links, event
to-dos/notes/doc links, tasks and comments, marketing requests.

Superusers: `/api/admin/audit-log/**` (view and restore) and `/api/admin/users/invite`.
Loading
Loading