#!/usr/bin/env bash # Quick Start Script for Reference Board Viewer # This script sets up and runs the authentication system for testing set -e GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' echo "=========================================" echo "Reference Board Viewer - Quick Start" echo "=========================================" echo "" # Check if we're in the right directory if [ ! -f "flake.nix" ]; then echo -e "${RED}Error: Please run this script from the project root${NC}" exit 1 fi # Step 1: Create backend .env if it doesn't exist echo -e "${YELLOW}Step 1: Setting up backend environment...${NC}" if [ ! -f "backend/.env" ]; then echo "Creating backend/.env..." cat > backend/.env << 'EOF' # Database DATABASE_URL=postgresql://localhost/webref # JWT Authentication SECRET_KEY=test-secret-key-change-in-production-$(openssl rand -hex 16) ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 # MinIO Storage (for later phases) MINIO_ENDPOINT=localhost:9000 MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_BUCKET=webref MINIO_SECURE=false # CORS CORS_ORIGINS=http://localhost:5173,http://localhost:3000 # Application DEBUG=true APP_NAME=Reference Board Viewer APP_VERSION=1.0.0 API_V1_PREFIX=/api/v1 # Logging LOG_LEVEL=INFO EOF echo -e "${GREEN}✓ Created backend/.env${NC}" else echo -e "${GREEN}✓ backend/.env already exists${NC}" fi echo "" # Step 2: Create frontend .env if it doesn't exist echo -e "${YELLOW}Step 2: Setting up frontend environment...${NC}" if [ ! -f "frontend/.env" ]; then echo "Creating frontend/.env..." cat > frontend/.env << 'EOF' VITE_API_URL=http://localhost:8000/api/v1 EOF echo -e "${GREEN}✓ Created frontend/.env${NC}" else echo -e "${GREEN}✓ frontend/.env already exists${NC}" fi echo "" # Step 3: Check PostgreSQL echo -e "${YELLOW}Step 3: Checking PostgreSQL...${NC}" if ! command -v psql &> /dev/null; then echo -e "${RED}✗ PostgreSQL not found. Please install PostgreSQL.${NC}" exit 1 fi # Check if database exists if psql -lqt | cut -d \| -f 1 | grep -qw webref; then echo -e "${GREEN}✓ Database 'webref' exists${NC}" else echo "Creating database 'webref'..." createdb webref || { echo -e "${RED}✗ Failed to create database. Make sure PostgreSQL is running.${NC}" echo "Try: sudo systemctl start postgresql" exit 1 } echo -e "${GREEN}✓ Created database 'webref'${NC}" fi echo "" # Step 4: Run migrations echo -e "${YELLOW}Step 4: Running database migrations...${NC}" echo "This requires the Nix development environment..." if command -v nix &> /dev/null; then nix develop -c bash -c "cd backend && alembic upgrade head" || { echo -e "${RED}✗ Migration failed${NC}" echo "You may need to run manually:" echo " nix develop" echo " cd backend" echo " alembic upgrade head" exit 1 } echo -e "${GREEN}✓ Migrations complete${NC}" else echo -e "${YELLOW}⚠ Nix not found. Please run migrations manually:${NC}" echo " nix develop" echo " cd backend" echo " alembic upgrade head" fi echo "" echo "=========================================" echo -e "${GREEN}Setup Complete!${NC}" echo "=========================================" echo "" echo "Next steps:" echo "" echo "1. Start the backend server (in one terminal):" echo " $ nix develop" echo " $ cd backend" echo " $ uvicorn app.main:app --reload" echo "" echo "2. Start the frontend server (in another terminal):" echo " $ cd frontend" echo " $ npm install # if not done already" echo " $ npm run dev" echo "" echo "3. Test the API:" echo " $ ./test-auth.sh" echo "" echo "4. Open browser:" echo " Backend API docs: http://localhost:8000/docs" echo " Frontend app: http://localhost:5173" echo "" echo "5. Try registration:" echo " - Navigate to http://localhost:5173/register" echo " - Create an account" echo " - Login and explore!" echo ""