Skip to content

Commit 42a7b11

Browse files
committed
Campus Booking System
1 parent fffc508 commit 42a7b11

5 files changed

Lines changed: 119 additions & 5 deletions

File tree

CLOUD_DEPLOYMENT.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Cloud Deployment Guide: Campus Resource Engine
2+
3+
This guide walks you through deploying the `campus-resource-engine` project to the cloud. We'll use a modern, cost-effective stack:
4+
- **GitHub** for version control
5+
- **Supabase** for the PostgreSQL Database
6+
- **Railway** for the Node.js Backend and Redis
7+
- **Vercel** for the Next.js Frontend
8+
9+
---
10+
11+
## Step 1: Push Code to GitHub
12+
Both Railway and Vercel will deploy automatically when you push code to your GitHub repository.
13+
14+
1. Go to [GitHub](https://github.com/) and create a new repository (e.g., `campus-resource-engine`).
15+
2. Open your terminal in the root of your local project and run:
16+
```bash
17+
git init
18+
git add .
19+
git commit -m "Initial commit for deployment"
20+
git branch -M main
21+
git remote add origin https://github.com/YOUR_USERNAME/campus-resource-engine.git
22+
git push -u origin main
23+
```
24+
25+
---
26+
27+
## Step 2: Setup Supabase (Database)
28+
You are already using Supabase, so you just need to ensure your production database is set up.
29+
30+
1. Go to [Supabase](https://supabase.com/) and create a new Project.
31+
2. Note down the **Database Password**, **Project URL**, and **anon key** (found in Project Settings -> API).
32+
3. Get your **Database Connection string** (found in Project Settings -> Database -> URI). It should look like `postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres`.
33+
34+
*Note: You will need to run your initial database migrations/seed scripts against this new Supabase production database.*
35+
36+
---
37+
38+
## Step 3: Setup Railway (Backend & Redis)
39+
Railway is perfect for our Express backend and Redis cache.
40+
41+
### 3a. Provision Redis
42+
1. Make an account on [Railway.app](https://railway.app/).
43+
2. Click **New Project** -> **Provision Redis**.
44+
3. Railway will provision a Redis instance. Note its internal connection URL (available in its Variables tab once created).
45+
46+
### 3b. Deploy the Backend Server
47+
1. In the same Railway project, click **New** -> **GitHub Repo** and select your `campus-resource-engine` repository.
48+
2. Railway might try to guess the deployment. We need to tell it to only build the backend.
49+
3. Once the service appears, click on it -> Go to **Settings**:
50+
- Give it a name like `campus-backend`.
51+
- **Root Directory**: `server` (or leave as `/` but ensure the Dockerfile path is `server/Dockerfile`). Since you have a `railway.toml` at the root pointing to `server/Dockerfile`, Railway might auto-detect this correctly.
52+
- **Build Command**: Leave blank (it uses the Dockerfile).
53+
4. Go to the **Variables** tab for the backend service. Add all variables from your `server/.env.example`:
54+
- `NODE_ENV=production`
55+
- `DATABASE_URL`: Your Supabase connection string.
56+
- `DIRECT_URL`: Same as above but port `5432` for direct access if needed.
57+
- `REDIS_URL`: Use the private Railway URL provided by the Redis service you just created (e.g., `redis://redis.railway.internal:6379`).
58+
- `JWT_SECRET` & `JWT_REFRESH_SECRET`: Generate long random strings for these.
59+
- `CORS_ORIGIN`: Set this to your frontend URL (you can update this *after* Step 4).
60+
- *(Add any other required vars like SMTP for emails).*
61+
5. Go to the **Settings** tab -> **Networking** and click **Generate Domain**. This will be your `API_URL` (e.g., `https://campus-backend-production.up.railway.app`).
62+
63+
---
64+
65+
## Step 4: Setup Vercel (Frontend Next.js)
66+
Vercel is the creator of Next.js and the absolute best place to host it.
67+
68+
1. Make an account on [Vercel.com](https://vercel.com/) and link your GitHub.
69+
2. Click **Add New...** -> **Project**.
70+
3. Import your `campus-resource-engine` repository.
71+
4. In the **Configure Project** screen:
72+
- **Framework Preset**: Next.js
73+
- **Root Directory**: Click "Edit" and change it to `client`.
74+
5. Open the **Environment Variables** section and add the variables from `client/.env.example`:
75+
- `NEXT_PUBLIC_API_URL`: The domain Railway generated for you + `/api/v1` (e.g., `https://campus-backend-production.up.railway.app/api/v1`).
76+
- `NEXT_PUBLIC_SOCKET_URL`: The domain Railway generated for you (e.g., `https://campus-backend-production.up.railway.app`).
77+
- `NEXT_PUBLIC_SUPABASE_URL`: Your Supabase Project URL.
78+
- `NEXT_PUBLIC_SUPABASE_ANON_KEY`: Your Supabase anon key.
79+
6. Click **Deploy**.
80+
81+
---
82+
83+
## Final Review
84+
1. Ensure Vercel successfully builds and gives you a frontend URL (e.g., `https://campus-engine.vercel.app`).
85+
2. **Crucial:** Go back to your Railway Backend service -> **Variables** tab, and update the `CORS_ORIGIN` to match your new Vercel frontend URL exactly (e.g., `https://campus-engine.vercel.app`).
86+
3. Your app is now live in the cloud!
87+
88+
## Maintenance & Updates
89+
Whenever you push changes to your `main` branch on GitHub:
90+
- Vercel will automatically detect changes in the `client/` folder and rebuild the frontend.
91+
- Railway will automatically detect changes and rebuild the backend.

client/.env.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# =============================================================================
2+
# Campus Resource Engine - Client Environment Configuration
3+
# =============================================================================
4+
# Copy this file to .env.local for local development
5+
# For production/deployment, set these in your hosting provider's dashboard
6+
# =============================================================================
7+
8+
# API and Socket URLs (must match your backend deployed URLs)
9+
NEXT_PUBLIC_API_URL=http://localhost:3001/api/v1
10+
NEXT_PUBLIC_SOCKET_URL=http://localhost:3001
11+
12+
# Supabase Configuration
13+
# You must provide these for authentication and real-time features to work
14+
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
15+
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

client/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ COPY . .
2828
# Set build-time environment variables
2929
ARG NEXT_PUBLIC_API_URL
3030
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
31+
32+
ARG NEXT_PUBLIC_SOCKET_URL
33+
ENV NEXT_PUBLIC_SOCKET_URL=$NEXT_PUBLIC_SOCKET_URL
34+
35+
ARG NEXT_PUBLIC_SUPABASE_URL
36+
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL
37+
38+
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
39+
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
40+
3141
ENV NEXT_TELEMETRY_DISABLED=1
3242

3343
# Build the application

client/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"lint": "pnpm -r lint",
1212
"docker:up": "docker-compose up -d",
1313
"docker:down": "docker-compose down",
14-
"db:generate": "pnpm --filter @campus/server prisma:generate",
15-
"db:push": "pnpm --filter @campus/server exec prisma db push",
16-
"db:seed": "pnpm --filter @campus/server exec prisma db seed",
14+
"db:seed": "pnpm --filter @campus/server run seed",
1715
"test:epic3": "npm run test:epic3 --prefix server"
1816
},
1917
"engines": {
@@ -25,4 +23,4 @@
2523
"@supabase/supabase-js": "^2.95.3",
2624
"lucide-react": "^0.563.0"
2725
}
28-
}
26+
}

0 commit comments

Comments
 (0)