Skip to content

Repository files navigation

Raffles Hall crest

RHApp

Hall life, in one place.

Bookings, CCAs, events, and the people who run them — for Raffles Hall, NUS.

Quickstart · The map · Under the hood · Contributing · What's new

Next.js 14 TypeScript tRPC Prisma Tailwind


It started as a room-booking tool. It is now the place a resident goes to find a practice room, apply to a CCA, book the interview, turn up to the event, and check what they signed up for — and the place a CCA head, the JCRC, or the hall office goes to run all of that without a spreadsheet.


The map

Every route below is a surface someone actually uses. They are grouped by who they belong to, because that is also how authorization is drawn: /cca is the committee's dashboard, /ccas is the resident's view of the same CCAs, and the two never share a procedure.

Route What lives there
Everyone / Home, and the door to everything else
/bookings Book a facility; see what you're holding
/events What's on in hall, and signing up for it
/ccas Browse CCAs, apply, book your interview
/ccas/applications Every application you have open, and its slot
/ccas/my The CCAs you're actually in
/profile · /onboarding Who you are, and the gate that insists on it
CCA heads /cca/[id] Roster, description, applications, interviews, events
JCRC /admin Users, roles, facilities, and the event review queue
Hall office /scrc Oversight without the keys to everything
Five roles, and what separates them

resident is the baseline everyone holds. The other four are granted, and are deliberately not a ladder — scrc is not "admin lite", it is a different job with a different surface.

Role Is Can
resident everyone signed in book, browse, apply, attend
cca_head scoped to a CCA run that CCA, and only that CCA
jcrc the hall committee review events, manage users and facilities
scrc the hall office appoint the JCRC; oversight, not operations
admin the keys everything, sparingly

jcrc and scrc are mutually exclusive in code — the office appoints the committee, so it cannot quietly also be the committee.


Under the hood

A T3 app, which mostly means one TypeScript type travels from the database to the button without anyone re-typing it by hand.

flowchart LR
    B["Browser<br/>server + client components"]
    T["tRPC router<br/>the authorization boundary"]
    P["Prisma"]
    M[("MongoDB")]
    A["NextAuth<br/>credentials + Google"]

    B <-->|"typed calls, no REST"| T
    T --> P --> M
    A -.->|"session, canonical userID"| T

    style B fill:#ecfdf5,stroke:#059669,color:#064e3b
    style T fill:#eff6ff,stroke:#2563eb,color:#1e3a8a
    style M fill:#f5f3ff,stroke:#7c3aed,color:#4c1d95
    style A fill:#fff7ed,stroke:#ea580c,color:#7c2d12
Loading

Three things worth knowing before you write a line of it:

The procedure is the boundary. Layouts check "signed in" and nothing more. Every real permission check lives in the tRPC procedure, so a route you forgot to guard cannot hand out data a procedure would have refused.

MongoDB is not Postgres wearing a hat. { field: null } in a Prisma where clause does not match documents where the field is absent — and on this schema, absent is the common case. Filter nullables in JS. The codebase says so, repeatedly, at every place it bit someone.

Identity is canonical. Users arrive with an NUS alias and an E-number address. canonicalUserID() is the one funnel; a userID that skips it becomes a second person with an empty history.


Quickstart

You'll need Node 18.20.4 (nvm use 18.20.4), npm or bun, and a MongoDB you can reach — local, or an Atlas cluster.

git clone https://github.com/rhdevs/RH-app-2.0.git
cd RH-app-2.0
npm install

cp .env.example .env                 # then open it — see below
npx prisma generate                  # generate the Prisma client
npm run dev                          # → http://localhost:3000

Caution

Do not run prisma db push, prisma migrate dev, or prisma migrate deploy against a database anyone else is using. This line used to say db push, and that was wrong: on MongoDB, Prisma only pushes indexes — adding or removing a scalar field needs nothing — while a push silently drops any index that is not in schema.prisma. This database relies on several that aren't, including the case-insensitive email_unique_ci, which a push has already destroyed once. prisma generate is what you actually want. New collections and indexes are created explicitly with $runCommandRaw; see scripts/remediation/README.md.

Pointing at an empty database instead? Then read this, because prisma generate deliberately does not do what db push did. On MongoDB, Prisma only ever pushes indexes — collections and scalar fields need nothing — so an empty database will come up with no unique indexes at all. That is not cosmetic: Counter.key, BookingLock.key and EventLock.key are what make the id allocator and the booking/signup locks safe, Event.eventID and EventSignup[eventID, userID] are what make a duplicate signup a P2002 instead of a second row, and User.email_unique_ci is the duplicate-account guard. Create them explicitly with createIndexes via $runCommandRaw — scripts/remediation/create-auth-allowlist.mjs is the working precedent, and scripts/remediation/README.md Step 0 explains the approach. There is no one-command bootstrap script yet; it lands with the events Phase 2 index work. In practice every deployment so far shares one long-lived database where these indexes already exist, which is why this gap went unnoticed.

Before npm run dev will get you anywhere, fill in two values in .env:

DATABASE_URL your MongoDB connection string
NEXTAUTH_SECRET openssl rand -base64 32 — never ship the placeholder

Everything else in .env.example is optional and documented in place: Google OAuth turns itself on only when both halves are set, and RESEND_API_KEY is only needed if you're testing password-reset emails.

npx prisma studio     # browse the data
npm run lint          # eslint
npx tsc --noEmit      # typecheck — CI will, so you should

Warning

prisma db push silently drops indexes that aren't in schema.prisma, and it has already cost this database email_unique_ci once. It is not part of any normal workflow here — see the caution above. The db:push / db:generate / db:migrate npm scripts were removed for the same reason: db:generate ran prisma migrate dev, so the script whose name said "generate" ran a migration.


Feature flags

Big surfaces ship dark and are switched on from the database, not a redeploy. If a whole section of the app appears to be missing, check here first.

Flag Turns on
cca.management.enabled the CCA head dashboard
cca.applications.enabled applications and interview booking
events.enabled the events pipeline, end to end
scrc.enabled the hall-office surface

Working on it

git checkout -b yourname/what-it-does

Branch off main, keep the branch about one thing, and open a PR back to main. Write the commit message for whoever has to understand the change in six months — why, not what; the diff already says what.

Read docs/ContributionGuidelines.md before your first PR. New to git? This guide is the short version.

Where the documentation is

Document Read it when
docs/SettingUp.md the quickstart above wasn't enough
docs/DeveloperGuide.md you want the architecture in full
docs/ContributionGuidelines.md before opening a PR
docs/The-New-RHApp.md you want the tour, in plain language
docs/plans/ you're touching CCAs or roles and want the reasoning

Built by

Patrick Steve Harrison
Creator and maintainer · @patrick-steve

Made for Raffles Hall, National University of Singapore by RHDevs

Releases

Packages

Used by

Contributors

Languages