Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"setup:windows": "powershell -ExecutionPolicy Bypass -File ./setup/setup-windows.ps1",
"setup:linux": "bash ./setup/setup-linux.sh",
"setup:mac": "bash ./setup/setup-mac.sh"
},
"devDependencies": {
"prettier": "^3.2.5",
Expand Down
57 changes: 57 additions & 0 deletions setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# OpenSox Environment Setup Scripts

This directory contains interactive setup scripts designed to simplify local development setup for **OpenSox** across Windows, Linux, and macOS.

## Quick Start

Run the setup command corresponding to your operating system from the repository root directory (`opensox/`):

### 🪟 Windows (PowerShell)
```powershell
pnpm run setup:windows
```
*Or directly via PowerShell:*
```powershell
powershell -ExecutionPolicy Bypass -File .\setup\setup-windows.ps1
```

---

### 🐧 Linux (Bash)
```bash
pnpm run setup:linux
```
*Or directly via terminal:*
```bash
bash ./setup/setup-linux.sh
```

---

### 🍎 macOS (Zsh / Bash)
```bash
pnpm run setup:mac
```
*Or directly via terminal:*
```bash
bash ./setup/setup-mac.sh
```

---

## What the Setup Script Does

1. **Environment Variables Check (`.env` & `.env.local`)**:
- Verifies that `apps/api/.env` and `apps/web/.env.local` are present.
- Checks that essential variables (e.g., `DATABASE_URL`, `JWT_SECRET`, `PORT`, `NEXT_PUBLIC_API_URL`) are populated.
- If missing, guides you on what values are required to run locally.
- **Smart Re-run (Idempotency):** If `.env` files are already configured, it skips prompts on subsequent runs.
Comment on lines +44 to +48

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Align the rerun claim with the actual validation.

setup/setup-linux.sh:28-39 accepts any non-empty value for a required key. A value such as DATABASE_URL=placeholder can therefore pass the check and skip the prompts described here.

Either validate value formats before declaring the files configured, or change line 48 to state that the scripts check for non-empty values only.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@setup/README.md` around lines 44 - 48, Update the “Smart Re-run
(Idempotency)” statement to accurately describe the validation performed by the
setup scripts: they only verify that required environment variables are
non-empty, not that values such as DATABASE_URL are valid. Keep the existing
skip-prompts behavior documented without claiming format validation.


2. **Dependencies (`pnpm install`)**:
- Ensures workspace dependencies are installed across `apps/api` and `apps/web`.

3. **Prisma Client Generation (`prisma generate`)**:
- Generates the Prisma Client typescript definitions needed for `apps/api`.

4. **Database Migrations (`prisma migrate dev`)**:
- Optionally applies database migrations to your PostgreSQL database.
159 changes: 159 additions & 0 deletions setup/setup-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env bash

# ==============================================================================
# OpenSox Interactive Setup Script for Linux (Bash)
# ==============================================================================

set -e

# Terminal colors
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
GRAY='\033[0;90m'
NC='\033[0m' # No Color

echo -e "${CYAN}========================================================${NC}"
echo -e "${CYAN} 🚀 OpenSox Local Environment Setup (Linux) ${NC}"
echo -e "${CYAN}========================================================${NC}"
echo ""

ROOT_DIR="$(pwd)"
API_ENV_PATH="${ROOT_DIR}/apps/api/.env"
API_ENV_EXAMPLE="${ROOT_DIR}/apps/api/.env.example"
WEB_ENV_PATH="${ROOT_DIR}/apps/web/.env.local"

# Helper function to check non-empty env key
check_env_key() {
local file="$1"
local key="$2"
if [ ! -f "$file" ]; then
return 1
fi
if grep -qE "^${key}\s*=\s*.+" "$file"; then
return 0
else
return 1
fi
}

# ------------------------------------------------------------------------------
# 1. API Environment Variables Check (.env)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🔍 [1/4] Checking apps/api/.env...${NC}"

API_NEEDS_ATTENTION=false

if [ ! -f "$API_ENV_PATH" ]; then
echo -e "${RED}⚠️ apps/api/.env file is missing!${NC}"
API_NEEDS_ATTENTION=true
else
if check_env_key "$API_ENV_PATH" "DATABASE_URL" && check_env_key "$API_ENV_PATH" "JWT_SECRET"; then
echo -e "${GREEN}✅ apps/api/.env is fully configured with essential keys.${NC}"
else
echo -e "${RED}⚠️ apps/api/.env exists but is missing essential variables!${NC}"
API_NEEDS_ATTENTION=true
fi
fi

if [ "$API_NEEDS_ATTENTION" = true ]; then
echo ""
echo -e "${CYAN}📌 Important environment variables for apps/api/.env:${NC}"
echo -e "${GRAY} - DATABASE_URL (e.g., postgresql://postgres:postgres@localhost:5432/opensox?schema=public)${NC}"
echo -e "${GRAY} - JWT_SECRET (e.g., a-random-secret-key)${NC}"
echo -e "${GRAY} - PORT (default: 8080)${NC}"
echo ""

if [ ! -f "$API_ENV_PATH" ]; then
read -p "Would you like to copy apps/api/.env.example to apps/api/.env now? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
cp "$API_ENV_EXAMPLE" "$API_ENV_PATH"
echo -e "${GREEN}✅ Created apps/api/.env from .env.example. Please review and update DATABASE_URL if needed.${NC}"
else
echo -e "${YELLOW}Please create apps/api/.env manually with essential keys before running the app.${NC}"
fi
fi
Comment on lines +60 to +77

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Require valid environment values before initialization.

The scripts only show warnings when required values are absent. A user can decline file creation, or keep incomplete files, and setup still runs dependency and Prisma commands. This does not meet the required prompt-and-confirm setup flow.

  • setup/setup-linux.sh#L60-L77: Prompt for missing API values, revalidate them, and exit before initialization when they remain invalid.
  • setup/setup-linux.sh#L87-L109: Validate NEXT_PUBLIC_API_URL and NEXTAUTH_SECRET in existing files before reporting success or continuing.
  • setup/setup-mac.sh#L60-L77: Prompt for missing API values, revalidate them, and exit before initialization when they remain invalid.
  • setup/setup-mac.sh#L87-L109: Validate NEXT_PUBLIC_API_URL and NEXTAUTH_SECRET in existing files before reporting success or continuing.
  • setup/setup-windows.ps1#L52-L69: Prompt for missing API values, revalidate them, and exit before initialization when they remain invalid.
  • setup/setup-windows.ps1#L80-L102: Validate NEXT_PUBLIC_API_URL and NEXTAUTH_SECRET in existing files before reporting success or continuing.
📍 Affects 3 files
  • setup/setup-linux.sh#L60-L77 (this comment)
  • setup/setup-linux.sh#L87-L109
  • setup/setup-mac.sh#L60-L77
  • setup/setup-mac.sh#L87-L109
  • setup/setup-windows.ps1#L52-L69
  • setup/setup-windows.ps1#L80-L102
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@setup/setup-linux.sh` around lines 60 - 77, Require valid environment values
before initialization: in setup/setup-linux.sh lines 60-77, setup/setup-mac.sh
lines 60-77, and setup/setup-windows.ps1 lines 52-69, prompt for missing API
values, revalidate after any file creation or user response, and exit if
required values remain invalid. In setup/setup-linux.sh lines 87-109,
setup/setup-mac.sh lines 87-109, and setup/setup-windows.ps1 lines 80-102,
validate NEXT_PUBLIC_API_URL and NEXTAUTH_SECRET in existing environment files
before reporting success or continuing with dependency and Prisma
initialization; preserve the existing API_ENV_PATH/API_NEEDS_ATTENTION flow.

fi

echo ""

# ------------------------------------------------------------------------------
# 2. Web Environment Variables Check (.env.local)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🔍 [2/4] Checking apps/web/.env.local...${NC}"

if [ ! -f "$WEB_ENV_PATH" ]; then
echo -e "${RED}⚠️ apps/web/.env.local is missing!${NC}"
echo -e "${CYAN}📌 Essential environment variables for apps/web/.env.local:${NC}"
echo -e "${GRAY} - NEXT_PUBLIC_API_URL (default: http://localhost:8080)${NC}"
echo -e "${GRAY} - NEXTAUTH_SECRET (e.g., a-random-secret)${NC}"
echo ""

read -p "Would you like to create apps/web/.env.local with default local values now? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
cat <<EOF > "$WEB_ENV_PATH"
# Required for Local Setup
NEXT_PUBLIC_API_URL="http://localhost:8080"
NEXTAUTH_SECRET="opensox-local-dev-secret-key"
NEXTAUTH_URL="http://localhost:3000"
EOF
echo -e "${GREEN}✅ Created apps/web/.env.local!${NC}"
else
echo -e "${YELLOW}Please create apps/web/.env.local manually before running the app.${NC}"
fi
else
echo -e "${GREEN}✅ apps/web/.env.local is configured.${NC}"
fi

echo ""

# ------------------------------------------------------------------------------
# 3. Dependency Installation (pnpm)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}📦 [3/4] Checking workspace dependencies...${NC}"

if [ ! -d "${ROOT_DIR}/node_modules" ]; then
echo -e "${CYAN}Installing dependencies with pnpm...${NC}"
pnpm install
else
echo -e "${GREEN}✅ Root node_modules found. Checking for updates...${NC}"
pnpm install --prefer-offline
fi

echo ""

# ------------------------------------------------------------------------------
# 4. Prisma Client Generation & Database Migrations
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🗄️ [4/4] Setting up Prisma Database Client...${NC}"

echo -e "${CYAN}Generating Prisma Client...${NC}"
pnpm --filter api exec prisma generate

echo ""
read -p "Would you like to run database migrations now (requires running PostgreSQL DB)? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${CYAN}Running Prisma migrations...${NC}"
pnpm --filter api exec prisma migrate dev
else
echo -e "${GRAY}Skipped database migrations. You can run 'pnpm --filter api exec prisma migrate dev' later.${NC}"
fi

# ------------------------------------------------------------------------------
# Setup Complete
# ------------------------------------------------------------------------------
echo ""
echo -e "${GREEN}========================================================${NC}"
echo -e "${GREEN} OpenSox Setup Complete!${NC}"
echo -e "${GREEN}========================================================${NC}"
echo -e "To start the development servers, run:"
echo -e "${CYAN} pnpm dev${NC}"
echo ""
echo -e "Local Application URLs (once running):"
echo -e "${CYAN} Frontend Web: http://localhost:3000${NC}"
echo -e "${CYAN} Backend API: http://localhost:8080${NC}"
echo ""
159 changes: 159 additions & 0 deletions setup/setup-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env bash

# ==============================================================================
# OpenSox Interactive Setup Script for macOS (Zsh/Bash)
# ==============================================================================

set -e

# Terminal colors
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
GRAY='\033[0;90m'
NC='\033[0m' # No Color

echo -e "${CYAN}========================================================${NC}"
echo -e "${CYAN} 🚀 OpenSox Local Environment Setup (macOS) ${NC}"
echo -e "${CYAN}========================================================${NC}"
echo ""

ROOT_DIR="$(pwd)"
API_ENV_PATH="${ROOT_DIR}/apps/api/.env"
API_ENV_EXAMPLE="${ROOT_DIR}/apps/api/.env.example"
WEB_ENV_PATH="${ROOT_DIR}/apps/web/.env.local"

# Helper function to check non-empty env key
check_env_key() {
local file="$1"
local key="$2"
if [ ! -f "$file" ]; then
return 1
fi
if grep -qE "^${key}\s*=\s*.+" "$file"; then
return 0
else
return 1
fi
}

# ------------------------------------------------------------------------------
# 1. API Environment Variables Check (.env)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🔍 [1/4] Checking apps/api/.env...${NC}"

API_NEEDS_ATTENTION=false

if [ ! -f "$API_ENV_PATH" ]; then
echo -e "${RED}⚠️ apps/api/.env file is missing!${NC}"
API_NEEDS_ATTENTION=true
else
if check_env_key "$API_ENV_PATH" "DATABASE_URL" && check_env_key "$API_ENV_PATH" "JWT_SECRET"; then
echo -e "${GREEN}✅ apps/api/.env is fully configured with essential keys.${NC}"
else
echo -e "${RED}⚠️ apps/api/.env exists but is missing essential variables!${NC}"
API_NEEDS_ATTENTION=true
fi
fi

if [ "$API_NEEDS_ATTENTION" = true ]; then
echo ""
echo -e "${CYAN}📌 Important environment variables for apps/api/.env:${NC}"
echo -e "${GRAY} - DATABASE_URL (e.g., postgresql://postgres:postgres@localhost:5432/opensox?schema=public)${NC}"
echo -e "${GRAY} - JWT_SECRET (e.g., a-random-secret-key)${NC}"
echo -e "${GRAY} - PORT (default: 8080)${NC}"
echo ""

if [ ! -f "$API_ENV_PATH" ]; then
read -p "Would you like to copy apps/api/.env.example to apps/api/.env now? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
cp "$API_ENV_EXAMPLE" "$API_ENV_PATH"
echo -e "${GREEN}✅ Created apps/api/.env from .env.example. Please review and update DATABASE_URL if needed.${NC}"
else
echo -e "${YELLOW}Please create apps/api/.env manually with essential keys before running the app.${NC}"
fi
fi
fi

echo ""

# ------------------------------------------------------------------------------
# 2. Web Environment Variables Check (.env.local)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🔍 [2/4] Checking apps/web/.env.local...${NC}"

if [ ! -f "$WEB_ENV_PATH" ]; then
echo -e "${RED}⚠️ apps/web/.env.local is missing!${NC}"
echo -e "${CYAN}📌 Essential environment variables for apps/web/.env.local:${NC}"
echo -e "${GRAY} - NEXT_PUBLIC_API_URL (default: http://localhost:8080)${NC}"
echo -e "${GRAY} - NEXTAUTH_SECRET (e.g., a-random-secret)${NC}"
echo ""

read -p "Would you like to create apps/web/.env.local with default local values now? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
cat <<EOF > "$WEB_ENV_PATH"
# Required for Local Setup
NEXT_PUBLIC_API_URL="http://localhost:8080"
NEXTAUTH_SECRET="opensox-local-dev-secret-key"
NEXTAUTH_URL="http://localhost:3000"
EOF
echo -e "${GREEN}✅ Created apps/web/.env.local!${NC}"
else
echo -e "${YELLOW}Please create apps/web/.env.local manually before running the app.${NC}"
fi
else
echo -e "${GREEN}✅ apps/web/.env.local is configured.${NC}"
fi

echo ""

# ------------------------------------------------------------------------------
# 3. Dependency Installation (pnpm)
# ------------------------------------------------------------------------------
echo -e "${YELLOW}📦 [3/4] Checking workspace dependencies...${NC}"

if [ ! -d "${ROOT_DIR}/node_modules" ]; then
echo -e "${CYAN}Installing dependencies with pnpm...${NC}"
pnpm install
else
echo -e "${GREEN}✅ Root node_modules found. Checking for updates...${NC}"
pnpm install --prefer-offline
fi

echo ""

# ------------------------------------------------------------------------------
# 4. Prisma Client Generation & Database Migrations
# ------------------------------------------------------------------------------
echo -e "${YELLOW}🗄️ [4/4] Setting up Prisma Database Client...${NC}"

echo -e "${CYAN}Generating Prisma Client...${NC}"
pnpm --filter api exec prisma generate

echo ""
read -p "Would you like to run database migrations now (requires running PostgreSQL DB)? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${CYAN}Running Prisma migrations...${NC}"
pnpm --filter api exec prisma migrate dev
else
echo -e "${GRAY}Skipped database migrations. You can run 'pnpm --filter api exec prisma migrate dev' later.${NC}"
fi

# ------------------------------------------------------------------------------
# Setup Complete
# ------------------------------------------------------------------------------
echo ""
echo -e "${GREEN}========================================================${NC}"
echo -e "${GREEN} OpenSox Setup Complete!${NC}"
echo -e "${GREEN}========================================================${NC}"
echo -e "To start the development servers, run:"
echo -e "${CYAN} pnpm dev${NC}"
echo ""
echo -e "Local Application URLs (once running):"
echo -e "${CYAN} Frontend Web: http://localhost:3000${NC}"
echo -e "${CYAN} Backend API: http://localhost:8080${NC}"
echo ""
Loading