|
| 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. |
0 commit comments