From 1b9e8a640e34749f5607d566be3811eba4fd0aa3 Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Mon, 9 Feb 2026 11:22:01 -0500 Subject: [PATCH 1/6] Add verification scripts and unify envs across all three backends --- mflix/README-JAVA-SPRING.md | 25 +- mflix/README-JAVASCRIPT-EXPRESS.md | 12 +- mflix/README-PYTHON-FASTAPI.md | 28 +- mflix/check-requirements-java.sh | 438 ++++++++++++++++++ mflix/check-requirements-js.sh | 408 ++++++++++++++++ mflix/check-requirements-python.sh | 400 ++++++++++++++++ mflix/server/java-spring/.env.example | 20 +- .../src/main/resources/application.properties | 4 +- mflix/server/js-express/.env.example | 19 +- mflix/server/js-express/src/app.ts | 7 +- mflix/server/python-fastapi/.env.example | 14 +- .../src/database/mongo_client.py | 7 +- 12 files changed, 1326 insertions(+), 56 deletions(-) create mode 100755 mflix/check-requirements-java.sh create mode 100755 mflix/check-requirements-js.sh create mode 100755 mflix/check-requirements-python.sh diff --git a/mflix/README-JAVA-SPRING.md b/mflix/README-JAVA-SPRING.md index 245afc5..8905cab 100644 --- a/mflix/README-JAVA-SPRING.md +++ b/mflix/README-JAVA-SPRING.md @@ -28,6 +28,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements-java.sh +``` + +This script checks for required tools (Java, Maven, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -48,28 +58,19 @@ Edit the `.env` file and set your MongoDB connection string: ```env # MongoDB Connection -# Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) VOYAGE_API_KEY=your_voyage_api_key # Server Configuration -# Port on which the Spring Boot application will run PORT=3001 # CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 - -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true +CORS_ORIGINS=http://localhost:3000 ``` -**Note:** Replace `username`, `password`, and `cluster` with your +**Note:** Replace ``, ``, and `` with your actual MongoDB Atlas credentials. Replace `your_voyage_api_key` with your key. diff --git a/mflix/README-JAVASCRIPT-EXPRESS.md b/mflix/README-JAVASCRIPT-EXPRESS.md index f3c531c..e2982f0 100644 --- a/mflix/README-JAVASCRIPT-EXPRESS.md +++ b/mflix/README-JAVASCRIPT-EXPRESS.md @@ -27,6 +27,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements-js.sh +``` + +This script checks for required tools (Node.js, npm), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -61,7 +71,7 @@ NODE_ENV=development # CORS Configuration # Allowed origin for cross-origin requests (frontend URL) # For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 +CORS_ORIGINS=http://localhost:3000 # Optional: Enable MongoDB Search tests # Uncomment the following line to enable Search tests diff --git a/mflix/README-PYTHON-FASTAPI.md b/mflix/README-PYTHON-FASTAPI.md index 3d79f3b..4b3e49f 100644 --- a/mflix/README-PYTHON-FASTAPI.md +++ b/mflix/README-PYTHON-FASTAPI.md @@ -31,6 +31,16 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) +## Verify Requirements + +Before getting started, you can run the verification script to check if you have all the necessary requirements: + +```bash +./check-requirements-python.sh +``` + +This script checks for required tools (Python, pip, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. + ## Getting Started ### 1. Configure the Backend @@ -50,21 +60,21 @@ cp .env.example .env Edit the `.env` file and set your MongoDB connection string: ```env -# MongoDB Configuration -MONGO_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -MONGO_DB=sample_mflix +# MongoDB Connection +MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) VOYAGE_API_KEY=your_voyage_api_key +# Server Configuration +PORT=3001 + # CORS Configuration -# Comma-separated list of allowed origins for CORS -CORS_ORIGINS=http://localhost:3000,http://localhost:3001 +CORS_ORIGINS=http://localhost:3000 ``` -**Note:** Replace `username`, `password`, and `cluster` with your actual MongoDB Atlas -credentials. +**Note:** Replace ``, ``, and `` with your actual MongoDB Atlas +credentials. Replace `your_voyage_api_key` with your key. Make a virtual environment: diff --git a/mflix/check-requirements-java.sh b/mflix/check-requirements-java.sh new file mode 100755 index 0000000..e857edf --- /dev/null +++ b/mflix/check-requirements-java.sh @@ -0,0 +1,438 @@ +#!/bin/bash + +# ============================================================================= +# Java/Spring Boot Sample App - Requirements Verification Script +# ============================================================================= +# This script verifies that all requirements are met to run the Java/Spring Boot +# backend sample application. It checks for required tools, dependencies, and +# environment configuration. +# +# Usage: +# ./check-requirements-java.sh # Check all requirements +# ./check-requirements-java.sh --setup # Check and auto-setup missing items +# ============================================================================= + +set -e + +# Get script directory (works even if script is sourced) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Configuration - adjusted for artifact repo structure +SERVER_DIR="server" +CLIENT_DIR="client" +JAVA_MIN_VERSION="21" +NODE_MIN_VERSION="18" + +# Setup mode flag +SETUP_MODE=false +if [[ "$1" == "--setup" ]]; then + SETUP_MODE=true +fi + +# Counters +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# Helper Functions +# ============================================================================= + +print_header() { + echo "" + echo -e "${BLUE}======================================${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}======================================${NC}" +} + +print_subheader() { + echo "" + echo -e "${BLUE}--- $1 ---${NC}" +} + +check_pass() { + echo -e "${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e "${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e "${YELLOW}!${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e " ${BLUE}→${NC} $1" +} + +version_gte() { + # Returns 0 (true) if $1 >= $2 + [ "$1" -ge "$2" ] 2>/dev/null +} + +command_exists() { + command -v "$1" &>/dev/null +} + +# ============================================================================= +# Common Requirements +# ============================================================================= + +check_common_requirements() { + print_subheader "Common Requirements" + + # Check Git + if command_exists git; then + GIT_VERSION=$(git --version | grep -oE '[0-9]+\.[0-9]+' | head -1) + check_pass "Git installed (v$GIT_VERSION)" + else + check_fail "Git not installed" + check_info "Install Git from https://git-scm.com/" + fi + + # Check curl + if command_exists curl; then + check_pass "curl installed" + else + check_warn "curl not installed (optional, but useful for testing)" + fi +} + +# ============================================================================= +# Java/Spring Boot Requirements +# ============================================================================= + +check_java_requirements() { + print_subheader "Java/Spring Boot Backend" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + + # Check Java + if command_exists java; then + # Get Java version - handle different version formats + JAVA_VERSION_OUTPUT=$(java -version 2>&1 | head -n1) + JAVA_VERSION=$(echo "$JAVA_VERSION_OUTPUT" | sed -E 's/.*version "([0-9]+).*/\1/') + + if [ -n "$JAVA_VERSION" ] && version_gte "$JAVA_VERSION" "$JAVA_MIN_VERSION"; then + check_pass "Java installed: version $JAVA_VERSION (>= $JAVA_MIN_VERSION required)" + else + check_fail "Java version $JAVA_VERSION is too old (>= $JAVA_MIN_VERSION required)" + check_info "Install Java $JAVA_MIN_VERSION+ from:" + check_info " - Eclipse Temurin: https://adoptium.net/" + check_info " - Oracle JDK: https://www.oracle.com/java/technologies/downloads/" + check_info " - Or use SDKMAN: https://sdkman.io/" + fi + else + check_fail "Java not installed" + check_info "Install Java $JAVA_MIN_VERSION+ from:" + check_info " - Eclipse Temurin: https://adoptium.net/" + check_info " - Oracle JDK: https://www.oracle.com/java/technologies/downloads/" + check_info " - Or use SDKMAN: https://sdkman.io/" + return + fi + + # Check JAVA_HOME + if [ -n "$JAVA_HOME" ]; then + if [ -d "$JAVA_HOME" ]; then + check_pass "JAVA_HOME is set: $JAVA_HOME" + else + check_warn "JAVA_HOME is set but directory doesn't exist: $JAVA_HOME" + fi + else + check_warn "JAVA_HOME is not set (may cause issues with some tools)" + check_info "Set JAVA_HOME to your Java installation directory" + fi + + + # Check Maven wrapper + if [ -f "$server_dir/mvnw" ]; then + check_pass "Maven wrapper (mvnw) found" + + # Check if mvnw is executable + if [ -x "$server_dir/mvnw" ]; then + check_pass "Maven wrapper is executable" + else + check_warn "Maven wrapper is not executable" + if [ "$SETUP_MODE" = true ]; then + chmod +x "$server_dir/mvnw" + check_pass "Made Maven wrapper executable" + else + check_info "Run: chmod +x $server_dir/mvnw" + fi + fi + + # Try to get Maven version + MAVEN_VERSION=$(cd "$server_dir" && ./mvnw --version 2>/dev/null | grep "Apache Maven" | awk '{print $3}') + if [ -n "$MAVEN_VERSION" ]; then + check_pass "Maven version: $MAVEN_VERSION" + fi + else + check_fail "Maven wrapper (mvnw) not found in $server_dir" + check_info "The Maven wrapper should be included in the repository" + fi + + # Check if Maven dependencies are downloaded + if [ -d "$server_dir/target" ]; then + check_pass "Maven target directory exists (dependencies likely downloaded)" + else + check_warn "Maven target directory not found" + if [ "$SETUP_MODE" = true ]; then + check_info "Downloading Maven dependencies..." + if (cd "$server_dir" && ./mvnw dependency:resolve -q); then + check_pass "Maven dependencies downloaded successfully" + else + check_fail "Failed to download Maven dependencies" + fi + else + check_info "Run: cd $server_dir && ./mvnw dependency:resolve" + fi + fi + + # Check if project compiles + if [ -d "$server_dir/target/classes" ]; then + check_pass "Project appears to be compiled" + else + check_warn "Project not compiled yet" + if [ "$SETUP_MODE" = true ]; then + check_info "Compiling project..." + if (cd "$server_dir" && ./mvnw compile -q); then + check_pass "Project compiled successfully" + else + check_fail "Failed to compile project" + fi + else + check_info "Run: cd $server_dir && ./mvnw compile" + fi + fi +} + +# ============================================================================= +# Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_subheader "Environment Configuration" + + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local example_file="$server_dir/.env.example" + + if [ -f "$env_file" ]; then + check_pass ".env file exists" + + # Check MongoDB URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + if grep -qE "^MONGODB_URI=.*<.*>" "$env_file" 2>/dev/null; then + check_warn "MONGODB_URI appears to be a placeholder - update with your connection string" + elif grep -qE "^MONGODB_URI=.+" "$env_file" 2>/dev/null; then + check_pass "MONGODB_URI is configured" + else + check_warn "MONGODB_URI is empty" + fi + else + check_fail "MONGODB_URI not found in .env" + fi + + # Check Voyage AI key (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + if grep -qE "^VOYAGE_API_KEY=your" "$env_file" 2>/dev/null || \ + grep -qE "^VOYAGE_API_KEY=$" "$env_file" 2>/dev/null; then + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + else + check_pass "VOYAGE_API_KEY is configured" + fi + else + check_info "VOYAGE_API_KEY not found (optional - needed for vector search)" + fi + + # Check CORS_ORIGINS + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not found (will use default: http://localhost:3000)" + fi + + # Check PORT + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not found (will use default)" + fi + else + check_warn ".env file not found" + if [ -f "$example_file" ]; then + check_info ".env.example exists - use it as a template" + if [ "$SETUP_MODE" = true ]; then + cp "$example_file" "$env_file" + check_pass "Created .env from .env.example" + check_warn "Please edit $env_file with your actual values" + else + check_info "Run: cp $example_file $env_file" + check_info "Then edit .env with your actual values" + fi + else + check_fail "No .env.example found to use as template" + fi + fi +} + + +# ============================================================================= +# Frontend Requirements +# ============================================================================= + +check_frontend_requirements() { + print_header "Frontend Requirements (Next.js)" + + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + + # Check Node.js (required for frontend) + print_subheader "Node.js" + if command_exists node; then + NODE_VERSION=$(node --version 2>/dev/null | sed 's/v//') + NODE_MAJOR=$(echo "$NODE_VERSION" | cut -d. -f1) + + if [ "$NODE_MAJOR" -ge "$NODE_MIN_VERSION" ] 2>/dev/null; then + check_pass "Node.js installed: v$NODE_VERSION (required: >= $NODE_MIN_VERSION)" + else + check_fail "Node.js version $NODE_VERSION is too old (required: >= $NODE_MIN_VERSION)" + check_info "Install Node.js $NODE_MIN_VERSION+ from: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+ from: https://nodejs.org/" + return + fi + + # Check npm + print_subheader "npm" + if command_exists npm; then + NPM_VERSION=$(npm --version 2>/dev/null) + check_pass "npm installed: v$NPM_VERSION" + else + check_fail "npm not installed" + check_info "npm should be installed with Node.js" + return + fi + + # Check client dependencies + print_subheader "Frontend Dependencies" + if [ -d "$client_dir/node_modules" ]; then + check_pass "Frontend dependencies installed" + + # Check for Next.js + if [ -d "$client_dir/node_modules/next" ]; then + check_pass "Next.js is installed" + else + check_warn "Next.js not found in dependencies" + fi + + # Check for React + if [ -d "$client_dir/node_modules/react" ]; then + check_pass "React is installed" + else + check_warn "React not found in dependencies" + fi + else + check_warn "Frontend dependencies not installed" + if [ "$SETUP_MODE" = true ]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install); then + check_pass "Frontend dependencies installed successfully" + else + check_fail "Failed to install frontend dependencies" + fi + else + check_info "Run: cd $client_dir && npm install" + fi + fi +} + +# ============================================================================= +# Summary +# ============================================================================= + +print_summary() { + echo "" + echo "=============================================================================" + echo " SUMMARY" + echo "=============================================================================" + echo "" + + if [ "$CHECKS_FAILED" -eq 0 ]; then + echo -e "${GREEN}✓ All checks passed!${NC}" + else + echo -e "${RED}✗ Some checks failed${NC}" + fi + + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [ "$CHECKS_FAILED" -gt 0 ]; then + echo "Review the failed checks above and follow the instructions to resolve them." + echo "Run with --setup flag to automatically fix some issues: ./check-requirements-java.sh --setup" + echo "" + fi +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +main() { + echo "=============================================================================" + echo " Java/Spring Boot Backend - Requirements Verification" + echo "=============================================================================" + echo "" + + check_common_requirements + check_java_requirements + check_env_configuration + check_frontend_requirements + print_summary + + # Exit with error code if any checks failed + if [ "$CHECKS_FAILED" -gt 0 ]; then + exit 1 + fi +} + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + echo "Usage: ./check-requirements-java.sh [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Automatically set up missing requirements where possible" + echo " --help Show this help message" + echo "" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +main \ No newline at end of file diff --git a/mflix/check-requirements-js.sh b/mflix/check-requirements-js.sh new file mode 100755 index 0000000..4fea4c6 --- /dev/null +++ b/mflix/check-requirements-js.sh @@ -0,0 +1,408 @@ +#!/bin/bash +# +# Requirements Verification Script for mflix Sample Application +# JavaScript/Express Backend (Node.js + Express + MongoDB) +# +# This script checks if you have all the necessary requirements to run the +# mflix sample application with the JavaScript/Express backend. +# +# Usage: +# ./check-requirements-js.sh # Check all requirements +# ./check-requirements-js.sh --setup # Check and auto-setup missing items +# ./check-requirements-js.sh --help # Show help message +# + +set -e + +# ============================================================================= +# Configuration +# ============================================================================= + +# Server directory (in artifact repo, server/js-express becomes just server) +SERVER_DIR="server" + +# ============================================================================= +# Colors for output +# ============================================================================= + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# ============================================================================= +# Counters +# ============================================================================= + +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# ============================================================================= +# Helper Functions +# ============================================================================= + +check_pass() { + echo -e "${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e "${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e "${YELLOW}!${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e "${BLUE}ℹ${NC} $1" +} + +print_section() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +# ============================================================================= +# Check Common Requirements +# ============================================================================= + +check_common_requirements() { + print_section "Common Requirements" + + # Check Git + if command -v git &> /dev/null; then + local git_version=$(git --version | cut -d' ' -f3) + check_pass "Git installed (version $git_version)" + else + check_fail "Git not installed" + check_info "Install Git: https://git-scm.com/downloads" + fi + + # Check curl (useful for API testing) + if command -v curl &> /dev/null; then + check_pass "curl installed" + else + check_warn "curl not installed (optional, useful for API testing)" + fi +} + +# ============================================================================= +# Check Node.js/Express Requirements +# ============================================================================= + +check_node_requirements() { + print_section "Node.js/Express Backend Requirements" + + # Check Node.js + if command -v node &> /dev/null; then + local node_version=$(node --version | sed 's/v//') + local node_major=$(echo "$node_version" | cut -d. -f1) + if [ "$node_major" -ge 18 ]; then + check_pass "Node.js installed (version $node_version)" + else + check_fail "Node.js version $node_version is below minimum required (18+)" + check_info "Install Node.js 18+: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js 18+: https://nodejs.org/" + return + fi + + # Check npm + if command -v npm &> /dev/null; then + local npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" + else + check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check server directory + if [ ! -d "$SERVER_DIR" ]; then + check_fail "Server directory not found: $SERVER_DIR" + return + fi + + # Check package.json + if [ -f "$SERVER_DIR/package.json" ]; then + check_pass "package.json found" + else + check_fail "package.json not found in $SERVER_DIR" + return + fi + + # Check node_modules + if [ -d "$SERVER_DIR/node_modules" ]; then + check_pass "node_modules directory exists" + + # Check key dependencies + if [ -d "$SERVER_DIR/node_modules/express" ]; then + check_pass "Express.js dependency installed" + else + check_fail "Express.js dependency not installed" + fi + + if [ -d "$SERVER_DIR/node_modules/mongodb" ]; then + check_pass "MongoDB driver dependency installed" + else + check_fail "MongoDB driver dependency not installed" + fi + + # Check TypeScript build + if [ -d "$SERVER_DIR/dist" ]; then + check_pass "TypeScript build output exists (dist directory)" + else + check_warn "TypeScript build output not found (dist directory)" + check_info "Run 'npm run build' in $SERVER_DIR to build" + fi + else + check_fail "node_modules directory not found" + if [ "$SETUP_MODE" = true ]; then + check_info "Attempting to install dependencies..." + if (cd "$SERVER_DIR" && npm install); then + check_pass "Dependencies installed successfully" + else + check_fail "Failed to install dependencies" + check_info "Run 'npm install' manually in $SERVER_DIR" + fi + else + check_info "Run 'npm install' in $SERVER_DIR or use --setup flag" + fi + fi +} + +# ============================================================================= +# Check Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_section "Environment Configuration" + + local env_file="$SERVER_DIR/.env" + local env_example="$SERVER_DIR/.env.example" + + # Check .env file + if [ -f "$env_file" ]; then + check_pass ".env file exists" + + # Check MONGODB_URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [ -n "$mongo_uri" ] && [ "$mongo_uri" != "mongodb+srv://:@.mongodb.net/" ]; then + check_pass "MONGODB_URI is configured" + else + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $env_file with your MongoDB connection string" + fi + else + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI= to $env_file" + fi + + # Check VOYAGE_API_KEY (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [ -n "$voyage_key" ] && [ "$voyage_key" != "" ]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_warn "VOYAGE_API_KEY has placeholder value (optional for vector search)" + fi + else + check_info "VOYAGE_API_KEY not set (optional, needed for vector search features)" + fi + + # Check CORS_ORIGINS (optional) + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" + fi + + # Check PORT (optional) + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + local port=$(grep "^PORT=" "$env_file" | cut -d'=' -f2-) + check_pass "PORT is configured ($port)" + else + check_info "PORT not set (will use default: 3001)" + fi + + # Check LOG_LEVEL (optional) + if grep -q "^LOG_LEVEL=" "$env_file" 2>/dev/null; then + check_pass "LOG_LEVEL is configured" + else + check_info "LOG_LEVEL not set (will use default)" + fi + else + check_fail ".env file not found" + if [ -f "$env_example" ]; then + if [ "$SETUP_MODE" = true ]; then + check_info "Attempting to create .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $env_file" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy .env.example to .env: cp $env_example $env_file" + check_info "Or use --setup flag to create automatically" + fi + else + check_info "Create a .env file with required configuration" + check_info "Required: MONGODB_URI" + check_info "Optional: VOYAGE_API_KEY, CORS_ORIGINS, PORT, LOG_LEVEL" + fi + fi +} + +# ============================================================================= +# Check Frontend Requirements +# ============================================================================= + +check_frontend_requirements() { + print_section "Frontend Requirements (Next.js)" + + local client_dir="client" + + # Check client directory + if [ ! -d "$client_dir" ]; then + check_warn "Client directory not found: $client_dir" + check_info "Frontend may be in a separate repository" + return + fi + + # Check package.json + if [ -f "$client_dir/package.json" ]; then + check_pass "Frontend package.json found" + else + check_fail "Frontend package.json not found" + return + fi + + # Check node_modules + if [ -d "$client_dir/node_modules" ]; then + check_pass "Frontend node_modules exists" + + # Check Next.js + if [ -d "$client_dir/node_modules/next" ]; then + check_pass "Next.js dependency installed" + else + check_fail "Next.js dependency not installed" + fi + + # Check React + if [ -d "$client_dir/node_modules/react" ]; then + check_pass "React dependency installed" + else + check_fail "React dependency not installed" + fi + else + check_fail "Frontend node_modules not found" + if [ "$SETUP_MODE" = true ]; then + check_info "Attempting to install frontend dependencies..." + if (cd "$client_dir" && npm install); then + check_pass "Frontend dependencies installed successfully" + else + check_fail "Failed to install frontend dependencies" + check_info "Run 'npm install' manually in $client_dir" + fi + else + check_info "Run 'npm install' in $client_dir or use --setup flag" + fi + fi +} + +# ============================================================================= +# Print Summary +# ============================================================================= + +print_summary() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} Summary${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [ $CHECKS_FAILED -eq 0 ]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [ $CHECKS_WARNED -gt 0 ]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi + else + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [ "$SETUP_MODE" != true ]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi + fi + echo "" +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +SETUP_MODE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks if you have all the necessary requirements" + echo "to run the mflix sample application with the JavaScript/Express backend." + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ JavaScript/Express Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [ "$SETUP_MODE" = true ]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_common_requirements +check_node_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [ $CHECKS_FAILED -gt 0 ]; then + exit 1 +fi +exit 0 diff --git a/mflix/check-requirements-python.sh b/mflix/check-requirements-python.sh new file mode 100755 index 0000000..05007e7 --- /dev/null +++ b/mflix/check-requirements-python.sh @@ -0,0 +1,400 @@ +#!/bin/bash + +# ============================================================================= +# Requirements Verification Script for mflix Sample Application +# Python/FastAPI Backend +# ============================================================================= +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the Python/FastAPI backend. +# +# Usage: ./check-requirements-python.sh [options] +# --setup Attempt to set up missing requirements +# --help Show this help message +# ============================================================================= + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Counters +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + +# Options +SETUP_MODE=false + +# Configuration +PYTHON_MIN_VERSION="3.11" +SERVER_DIR="server" +CLIENT_DIR="client" + +# ============================================================================= +# Helper Functions +# ============================================================================= + +print_header() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +print_subheader() { + echo "" + echo -e "${YELLOW}▸ $1${NC}" +} + +check_pass() { + echo -e " ${GREEN}✓${NC} $1" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) +} + +check_fail() { + echo -e " ${RED}✗${NC} $1" + CHECKS_FAILED=$((CHECKS_FAILED + 1)) +} + +check_warn() { + echo -e " ${YELLOW}⚠${NC} $1" + CHECKS_WARNED=$((CHECKS_WARNED + 1)) +} + +check_info() { + echo -e " ${BLUE}ℹ${NC} $1" +} + +version_gte() { + [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ] +} + +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# ============================================================================= +# Parse Arguments +# ============================================================================= + +show_help() { + echo "Usage: ./check-requirements-python.sh [options]" + echo "" + echo "Options:" + echo " --setup Attempt to set up missing requirements" + echo " --help Show this help message" + echo "" + echo "Examples:" + echo " ./check-requirements-python.sh # Check all requirements" + echo " ./check-requirements-python.sh --setup # Check and set up missing items" +} + +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help) + show_help + exit 0 + ;; + *) + echo "Unknown option: $1" + show_help + exit 1 + ;; + esac +done + +# ============================================================================= +# Get Script Directory +# ============================================================================= + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +print_header "mflix Sample Application - Python/FastAPI Requirements Check" +echo "" +echo "Setup mode: $SETUP_MODE" +echo "Working directory: $SCRIPT_DIR" + +# ============================================================================= +# Common Requirements +# ============================================================================= + +check_common_requirements() { + print_subheader "Common Requirements" + + # Check Git + if command_exists git; then + local git_version + git_version=$(git --version | awk '{print $3}') + check_pass "Git installed (version $git_version)" + else + check_fail "Git not installed" + check_info "Install Git: https://git-scm.com/downloads" + fi + + # Check curl + if command_exists curl; then + check_pass "curl installed" + else + check_fail "curl not installed" + check_info "Install curl using your package manager" + fi +} + +# ============================================================================= +# Python Backend Requirements +# ============================================================================= + +check_python_requirements() { + print_subheader "Python/FastAPI Backend Requirements" + + # Check Python version + if command_exists python3; then + PYTHON_VERSION=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1) + if version_gte "$PYTHON_VERSION" "$PYTHON_MIN_VERSION"; then + check_pass "Python $PYTHON_VERSION installed (>= $PYTHON_MIN_VERSION required)" + else + check_fail "Python $PYTHON_VERSION installed but >= $PYTHON_MIN_VERSION required" + check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" + fi + else + check_fail "Python 3 not installed" + check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" + fi + + # Check pip + if command_exists pip3 || python3 -m pip --version &>/dev/null; then + check_pass "pip installed" + else + check_fail "pip not installed" + check_info "Install pip: python3 -m ensurepip --upgrade" + fi + + # Check virtual environment + local venv_dir="$SCRIPT_DIR/$SERVER_DIR/.venv" + if [[ -d "$venv_dir" ]]; then + check_pass "Python virtual environment exists at $SERVER_DIR/.venv" + + # Check if venv is activated or can be used + if [[ -f "$venv_dir/bin/activate" ]]; then + check_pass "Virtual environment activation script exists" + else + check_warn "Virtual environment activation script missing" + fi + else + check_warn "Python virtual environment not found at $SERVER_DIR/.venv" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating virtual environment..." + if python3 -m venv "$venv_dir"; then + check_pass "Virtual environment created" + else + check_fail "Failed to create virtual environment" + fi + else + check_info "Create with: cd $SERVER_DIR && python3 -m venv .venv" + fi + fi + + # Check Python dependencies + local requirements_file="$SCRIPT_DIR/$SERVER_DIR/requirements.txt" + if [[ -f "$requirements_file" ]]; then + check_pass "requirements.txt found" + + # Check if key dependencies are installed + if [[ -d "$venv_dir" ]]; then + local pip_cmd="$venv_dir/bin/pip" + if [[ -f "$pip_cmd" ]]; then + # Check FastAPI + if "$pip_cmd" show fastapi &>/dev/null; then + check_pass "FastAPI installed in virtual environment" + else + check_warn "FastAPI not installed in virtual environment" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing dependencies..." + if "$pip_cmd" install -r "$requirements_file" &>/dev/null; then + check_pass "Dependencies installed" + else + check_fail "Failed to install dependencies" + fi + else + check_info "Install with: source $SERVER_DIR/.venv/bin/activate && pip install -r $SERVER_DIR/requirements.txt" + fi + fi + + # Check PyMongo + if "$pip_cmd" show pymongo &>/dev/null; then + check_pass "PyMongo installed in virtual environment" + else + check_warn "PyMongo not installed in virtual environment" + fi + fi + fi + else + check_fail "requirements.txt not found at $SERVER_DIR/requirements.txt" + fi +} + +# ============================================================================= +# Environment Configuration +# ============================================================================= + +check_env_configuration() { + print_subheader "Environment Configuration" + + local env_file="$SCRIPT_DIR/$SERVER_DIR/.env" + local env_example="$SCRIPT_DIR/$SERVER_DIR/.env.example" + + # Check .env file exists + if [[ -f "$env_file" ]]; then + check_pass ".env file exists at $SERVER_DIR/.env" + else + check_warn ".env file not found at $SERVER_DIR/.env" + if [[ "$SETUP_MODE" == true ]] && [[ -f "$env_example" ]]; then + check_info "Copying .env.example to .env..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_info "Please update the values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy the example: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + fi + return + fi + + # Check required environment variables + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" && "$mongo_uri" != "mongodb+srv://:@.mongodb.net/" ]]; then + check_pass "MONGODB_URI is configured" + else + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" + fi + else + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" + fi + + # Check optional environment variables + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" && "$voyage_key" != "" ]]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + fi + else + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" + fi + + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" + else + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" + fi + + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not set (will use default: 8000)" + fi +} + + + +# ============================================================================= +# Frontend Requirements (Next.js) +# ============================================================================= + +check_frontend_requirements() { + print_subheader "Frontend Requirements (Next.js)" + + # Check Node.js version + if command_exists node; then + NODE_VERSION=$(node --version 2>&1 | grep -oE '[0-9]+' | head -1) + if version_gte "$NODE_VERSION" "$NODE_MIN_VERSION"; then + check_pass "Node.js v$NODE_VERSION installed (>= v$NODE_MIN_VERSION required)" + else + check_fail "Node.js v$NODE_VERSION installed but >= v$NODE_MIN_VERSION required" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" + fi + + # Check npm + if command_exists npm; then + check_pass "npm installed" + else + check_fail "npm not installed" + fi + + # Check client dependencies + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + if [[ -d "$client_dir" ]]; then + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Client dependencies installed" + else + check_warn "Client dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing client dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then + check_pass "Client dependencies installed" + else + check_fail "Failed to install client dependencies" + fi + else + check_info "Install with: cd $CLIENT_DIR && npm install" + fi + fi + fi +} + +# ============================================================================= +# Summary +# ============================================================================= + +print_summary() { + echo "" + print_header "Summary" + echo -e "${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e "${RED}Failed:${NC} $CHECKS_FAILED" + echo -e "${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + + if [[ $CHECKS_FAILED -gt 0 ]]; then + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + exit 1 + elif [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}All critical checks passed, but there are warnings to review.${NC}" + exit 0 + else + echo -e "${GREEN}All checks passed! You're ready to run the application.${NC}" + exit 0 + fi +} + +# ============================================================================= +# Main Execution +# ============================================================================= + +main() { + print_header "Python/FastAPI Sample App - Requirements Check" + + check_common_requirements + check_python_requirements + check_env_configuration + check_frontend_requirements + + print_summary +} + +main diff --git a/mflix/server/java-spring/.env.example b/mflix/server/java-spring/.env.example index 049e6e9..465f95d 100644 --- a/mflix/server/java-spring/.env.example +++ b/mflix/server/java-spring/.env.example @@ -2,21 +2,19 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Optional: Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) # Get your API key from https://www.voyageai.com/ -# Uncomment the following line to enable vector search -# VOYAGE_API_KEY=your-api-key +VOYAGE_API_KEY=your_voyage_api_key # Server Configuration -# Port on which the Spring Boot application will run PORT=3001 # CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true \ No newline at end of file +# Logging Configuration +# Log level: TRACE, DEBUG, INFO, WARN, ERROR (default: INFO) +LOG_LEVEL=INFO +# Optional: Path to log file (if not set, logs only to console) +# LOG_FILE=app.log \ No newline at end of file diff --git a/mflix/server/java-spring/src/main/resources/application.properties b/mflix/server/java-spring/src/main/resources/application.properties index ffe611f..47bd6d0 100644 --- a/mflix/server/java-spring/src/main/resources/application.properties +++ b/mflix/server/java-spring/src/main/resources/application.properties @@ -8,8 +8,8 @@ spring.data.mongodb.database=sample_mflix server.port=${PORT:3001} # CORS Configuration -# Allowed origins for cross-origin requests (typically the frontend URL) -cors.allowed.origins=${CORS_ORIGIN:http://localhost:3000} +# Comma-separated list of allowed origins for cross-origin requests +cors.allowed.origins=${CORS_ORIGINS:http://localhost:3000} # Voyage AI Configuration # API key for Voyage AI embedding model (required for vector search) diff --git a/mflix/server/js-express/.env.example b/mflix/server/js-express/.env.example index c870ee0..71ef3ab 100644 --- a/mflix/server/js-express/.env.example +++ b/mflix/server/js-express/.env.example @@ -2,24 +2,19 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) +# Get your API key from https://www.voyageai.com/ VOYAGE_API_KEY=your_voyage_api_key # Server Configuration PORT=3001 NODE_ENV=development +# CORS Configuration +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 + # Logging Configuration # Available levels: error, warn, info, http, debug # Default: debug (development), info (production), error (test) -LOG_LEVEL=debug - -# CORS Configuration -# Allowed origin for cross-origin requests (frontend URL) -# For multiple origins, separate with commas -CORS_ORIGIN=http://localhost:3000 - -# Optional: Enable MongoDB Search tests -# Uncomment the following line to enable Search tests -# ENABLE_SEARCH_TESTS=true \ No newline at end of file +LOG_LEVEL=debug \ No newline at end of file diff --git a/mflix/server/js-express/src/app.ts b/mflix/server/js-express/src/app.ts index 6e3d389..d6f2e99 100644 --- a/mflix/server/js-express/src/app.ts +++ b/mflix/server/js-express/src/app.ts @@ -32,10 +32,15 @@ const PORT = process.env.PORT || 3001; * CORS Configuration * Allows the frontend to communicate with this Express backend * In production, this should be configured to only allow specific origins + * Supports multiple origins via comma-separated CORS_ORIGINS environment variable */ +const corsOrigins = (process.env.CORS_ORIGINS || "http://localhost:3000") + .split(",") + .map((origin) => origin.trim()); + app.use( cors({ - origin: process.env.CORS_ORIGIN || "http://localhost:3000", + origin: corsOrigins.length === 1 ? corsOrigins[0] : corsOrigins, credentials: true, }) ); diff --git a/mflix/server/python-fastapi/.env.example b/mflix/server/python-fastapi/.env.example index 6dc1d0d..74db84c 100644 --- a/mflix/server/python-fastapi/.env.example +++ b/mflix/server/python-fastapi/.env.example @@ -1,15 +1,17 @@ # MongoDB Connection # Replace with your MongoDB Atlas connection string or local MongoDB URI -MONGO_URI="mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority" -MONGO_DB="sample_mflix" +MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration -# API key for Voyage AI embedding model (required for Vector Search) +# Voyage AI Configuration (optional - required for Vector Search) +# Get your API key from https://www.voyageai.com/ VOYAGE_API_KEY=your_voyage_api_key +# Server Configuration +PORT=3001 + # CORS Configuration -# Comma-separated list of allowed origins for CORS -CORS_ORIGINS="http://localhost:3000,http://localhost:3001" +# Comma-separated list of allowed origins for cross-origin requests +CORS_ORIGINS=http://localhost:3000 # Logging Configuration # Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO) diff --git a/mflix/server/python-fastapi/src/database/mongo_client.py b/mflix/server/python-fastapi/src/database/mongo_client.py index 37ab816..b5bdf35 100644 --- a/mflix/server/python-fastapi/src/database/mongo_client.py +++ b/mflix/server/python-fastapi/src/database/mongo_client.py @@ -5,11 +5,14 @@ load_dotenv() -client = AsyncMongoClient(os.getenv("MONGO_URI"), +# Database name is hardcoded to sample_mflix for consistency across all backends +DATABASE_NAME = "sample_mflix" + +client = AsyncMongoClient(os.getenv("MONGODB_URI"), # Set application name appname="sample-app-python-mflix") -db = client[os.getenv("MONGO_DB")] +db = client[DATABASE_NAME] voyage_api_key = os.getenv("VOYAGE_API_KEY") if voyage_api_key: From a0517c297d9700952c5b219fb589848e9d0df734 Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Wed, 11 Feb 2026 16:16:30 -0500 Subject: [PATCH 2/6] Remove comment --- mflix/server/python-fastapi/src/database/mongo_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mflix/server/python-fastapi/src/database/mongo_client.py b/mflix/server/python-fastapi/src/database/mongo_client.py index b5bdf35..ac8e2d3 100644 --- a/mflix/server/python-fastapi/src/database/mongo_client.py +++ b/mflix/server/python-fastapi/src/database/mongo_client.py @@ -5,7 +5,6 @@ load_dotenv() -# Database name is hardcoded to sample_mflix for consistency across all backends DATABASE_NAME = "sample_mflix" client = AsyncMongoClient(os.getenv("MONGODB_URI"), From bafc4b7ff4eba3436f750d5d12eb72f36147ade3 Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Wed, 11 Feb 2026 16:25:57 -0500 Subject: [PATCH 3/6] Update copier workflow to include new check-requirements.sh scripts --- .copier/config.yaml | 3 +++ mflix/README-JAVA-SPRING.md | 2 +- mflix/README-JAVASCRIPT-EXPRESS.md | 2 +- mflix/README-PYTHON-FASTAPI.md | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.copier/config.yaml b/.copier/config.yaml index d9f108f..c39f5bb 100644 --- a/.copier/config.yaml +++ b/.copier/config.yaml @@ -43,6 +43,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/java-spring", to: "server" } - copy: { from: "mflix/README-JAVA-SPRING.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-java.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-java", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" @@ -68,6 +69,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/js-express", to: "server" } - copy: { from: "mflix/README-JAVASCRIPT-EXPRESS.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-js.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-js", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" @@ -93,6 +95,7 @@ workflows: - move: { from: "mflix/client", to: "client" } - move: { from: "mflix/server/python-fastapi", to: "server" } - copy: { from: "mflix/README-PYTHON-FASTAPI.md", to: "README.md" } + - copy: { from: "mflix/check-requirements-python.sh", to: "check-requirements.sh" } - copy: { from: "mflix/.gitignore-python", to: ".gitignore" } commit_strategy: pr_title: "Update MFlix application from docs-sample-apps" diff --git a/mflix/README-JAVA-SPRING.md b/mflix/README-JAVA-SPRING.md index 8905cab..a888664 100644 --- a/mflix/README-JAVA-SPRING.md +++ b/mflix/README-JAVA-SPRING.md @@ -33,7 +33,7 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo Before getting started, you can run the verification script to check if you have all the necessary requirements: ```bash -./check-requirements-java.sh +./check-requirements.sh ``` This script checks for required tools (Java, Maven, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. diff --git a/mflix/README-JAVASCRIPT-EXPRESS.md b/mflix/README-JAVASCRIPT-EXPRESS.md index e2982f0..a7b8e75 100644 --- a/mflix/README-JAVASCRIPT-EXPRESS.md +++ b/mflix/README-JAVASCRIPT-EXPRESS.md @@ -32,7 +32,7 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo Before getting started, you can run the verification script to check if you have all the necessary requirements: ```bash -./check-requirements-js.sh +./check-requirements.sh ``` This script checks for required tools (Node.js, npm), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. diff --git a/mflix/README-PYTHON-FASTAPI.md b/mflix/README-PYTHON-FASTAPI.md index 4b3e49f..fdcf10d 100644 --- a/mflix/README-PYTHON-FASTAPI.md +++ b/mflix/README-PYTHON-FASTAPI.md @@ -36,7 +36,7 @@ The `sample_mflix` dataset contains movies released up to **2016**. Searching fo Before getting started, you can run the verification script to check if you have all the necessary requirements: ```bash -./check-requirements-python.sh +./check-requirements.sh ``` This script checks for required tools (Python, pip, Node.js), validates your environment configuration, and verifies dependencies. Run with `--help` for more options. From 45d8a6ffecaa6aff0d6ff8b94a24f5cee97730cd Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Thu, 12 Feb 2026 13:22:48 -0500 Subject: [PATCH 4/6] genericize script names --- mflix/check-requirements-java.sh | 8 ++++---- mflix/check-requirements-js.sh | 6 +++--- mflix/check-requirements-python.sh | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mflix/check-requirements-java.sh b/mflix/check-requirements-java.sh index e857edf..07a2b5e 100755 --- a/mflix/check-requirements-java.sh +++ b/mflix/check-requirements-java.sh @@ -8,8 +8,8 @@ # environment configuration. # # Usage: -# ./check-requirements-java.sh # Check all requirements -# ./check-requirements-java.sh --setup # Check and auto-setup missing items +# ./check-requirements.sh # Check all requirements +# ./check-requirements.sh --setup # Check and auto-setup missing items # ============================================================================= set -e @@ -384,7 +384,7 @@ print_summary() { if [ "$CHECKS_FAILED" -gt 0 ]; then echo "Review the failed checks above and follow the instructions to resolve them." - echo "Run with --setup flag to automatically fix some issues: ./check-requirements-java.sh --setup" + echo "Run with --setup flag to automatically fix some issues: ./check-requirements.sh --setup" echo "" fi } @@ -419,7 +419,7 @@ while [[ $# -gt 0 ]]; do shift ;; --help|-h) - echo "Usage: ./check-requirements-java.sh [OPTIONS]" + echo "Usage: ./check-requirements.sh [OPTIONS]" echo "" echo "Options:" echo " --setup Automatically set up missing requirements where possible" diff --git a/mflix/check-requirements-js.sh b/mflix/check-requirements-js.sh index 4fea4c6..e6ee17c 100755 --- a/mflix/check-requirements-js.sh +++ b/mflix/check-requirements-js.sh @@ -7,9 +7,9 @@ # mflix sample application with the JavaScript/Express backend. # # Usage: -# ./check-requirements-js.sh # Check all requirements -# ./check-requirements-js.sh --setup # Check and auto-setup missing items -# ./check-requirements-js.sh --help # Show help message +# ./check-requirements.sh # Check all requirements +# ./check-requirements.sh --setup # Check and auto-setup missing items +# ./check-requirements.sh --help # Show help message # set -e diff --git a/mflix/check-requirements-python.sh b/mflix/check-requirements-python.sh index 05007e7..e761350 100755 --- a/mflix/check-requirements-python.sh +++ b/mflix/check-requirements-python.sh @@ -7,7 +7,7 @@ # This script checks that all necessary requirements are installed to run # the mflix sample application with the Python/FastAPI backend. # -# Usage: ./check-requirements-python.sh [options] +# Usage: ./check-requirements.sh [options] # --setup Attempt to set up missing requirements # --help Show this help message # ============================================================================= @@ -80,15 +80,15 @@ command_exists() { # ============================================================================= show_help() { - echo "Usage: ./check-requirements-python.sh [options]" + echo "Usage: ./check-requirements.sh [options]" echo "" echo "Options:" echo " --setup Attempt to set up missing requirements" echo " --help Show this help message" echo "" echo "Examples:" - echo " ./check-requirements-python.sh # Check all requirements" - echo " ./check-requirements-python.sh --setup # Check and set up missing items" + echo " ./check-requirements.sh # Check all requirements" + echo " ./check-requirements.sh --setup # Check and set up missing items" } while [[ $# -gt 0 ]]; do From 9a32d7de444e663f3b8fab851f891adb48a71151 Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Thu, 12 Feb 2026 13:24:49 -0500 Subject: [PATCH 5/6] Comment out the voyage api keys in env.examples --- mflix/server/java-spring/.env.example | 4 ++-- mflix/server/js-express/.env.example | 4 ++-- mflix/server/python-fastapi/.env.example | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mflix/server/java-spring/.env.example b/mflix/server/java-spring/.env.example index 465f95d..96c3555 100644 --- a/mflix/server/java-spring/.env.example +++ b/mflix/server/java-spring/.env.example @@ -2,9 +2,9 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration (optional - required for Vector Search) +# OPTIONAL: Voyage AI Configuration (required for Vector Search) # Get your API key from https://www.voyageai.com/ -VOYAGE_API_KEY=your_voyage_api_key +# VOYAGE_API_KEY=your_voyage_api_key # Server Configuration PORT=3001 diff --git a/mflix/server/js-express/.env.example b/mflix/server/js-express/.env.example index 71ef3ab..8b264f6 100644 --- a/mflix/server/js-express/.env.example +++ b/mflix/server/js-express/.env.example @@ -2,9 +2,9 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration (optional - required for Vector Search) +# OPTIONAL: Voyage AI Configuration (required for Vector Search) # Get your API key from https://www.voyageai.com/ -VOYAGE_API_KEY=your_voyage_api_key +# VOYAGE_API_KEY=your_voyage_api_key # Server Configuration PORT=3001 diff --git a/mflix/server/python-fastapi/.env.example b/mflix/server/python-fastapi/.env.example index 74db84c..f0d77b2 100644 --- a/mflix/server/python-fastapi/.env.example +++ b/mflix/server/python-fastapi/.env.example @@ -2,9 +2,9 @@ # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority -# Voyage AI Configuration (optional - required for Vector Search) +# OPTIONAL: Voyage AI Configuration (required for Vector Search) # Get your API key from https://www.voyageai.com/ -VOYAGE_API_KEY=your_voyage_api_key +# VOYAGE_API_KEY=your_voyage_api_key # Server Configuration PORT=3001 From 19ee4c8b71a6afa55985c85f317dd960b3ffec6d Mon Sep 17 00:00:00 2001 From: Cory Bullinger Date: Thu, 12 Feb 2026 13:47:31 -0500 Subject: [PATCH 6/6] update scripts to be consistent across backends --- mflix/check-requirements-java.sh | 372 +++++++++++++------------- mflix/check-requirements-js.sh | 299 +++++++++++---------- mflix/check-requirements-python.sh | 403 ++++++++++++++++------------- 3 files changed, 562 insertions(+), 512 deletions(-) diff --git a/mflix/check-requirements-java.sh b/mflix/check-requirements-java.sh index 07a2b5e..97dedb7 100755 --- a/mflix/check-requirements-java.sh +++ b/mflix/check-requirements-java.sh @@ -1,150 +1,135 @@ #!/bin/bash - # ============================================================================= -# Java/Spring Boot Sample App - Requirements Verification Script +# Requirements Verification Script for mflix Sample Application +# Java/Spring Boot Backend # ============================================================================= -# This script verifies that all requirements are met to run the Java/Spring Boot -# backend sample application. It checks for required tools, dependencies, and -# environment configuration. +# +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the Java/Spring Boot backend. # # Usage: -# ./check-requirements.sh # Check all requirements -# ./check-requirements.sh --setup # Check and auto-setup missing items +# ./check-requirements-java.sh # Check all requirements +# ./check-requirements-java.sh --setup # Check and auto-setup missing items +# ./check-requirements-java.sh --help # Show help message +# # ============================================================================= +# Exit on error (but handle arithmetic expressions carefully) set -e -# Get script directory (works even if script is sourced) -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# ============================================================================= +# Configuration +# ============================================================================= -# Configuration - adjusted for artifact repo structure SERVER_DIR="server" CLIENT_DIR="client" JAVA_MIN_VERSION="21" NODE_MIN_VERSION="18" -# Setup mode flag -SETUP_MODE=false -if [[ "$1" == "--setup" ]]; then - SETUP_MODE=true -fi - -# Counters -CHECKS_PASSED=0 -CHECKS_FAILED=0 -CHECKS_WARNED=0 - +# ============================================================================= # Colors +# ============================================================================= + RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# ============================================================================= +# Counters +# ============================================================================= + +CHECKS_PASSED=0 +CHECKS_FAILED=0 +CHECKS_WARNED=0 + # ============================================================================= # Helper Functions # ============================================================================= print_header() { echo "" - echo -e "${BLUE}======================================${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${BLUE} $1${NC}" - echo -e "${BLUE}======================================${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" } -print_subheader() { +print_section() { echo "" - echo -e "${BLUE}--- $1 ---${NC}" + echo -e "${YELLOW}▸ $1${NC}" } check_pass() { - echo -e "${GREEN}✓${NC} $1" + echo -e " ${GREEN}✓${NC} $1" CHECKS_PASSED=$((CHECKS_PASSED + 1)) } check_fail() { - echo -e "${RED}✗${NC} $1" + echo -e " ${RED}✗${NC} $1" CHECKS_FAILED=$((CHECKS_FAILED + 1)) } check_warn() { - echo -e "${YELLOW}!${NC} $1" + echo -e " ${YELLOW}⚠${NC} $1" CHECKS_WARNED=$((CHECKS_WARNED + 1)) } check_info() { - echo -e " ${BLUE}→${NC} $1" -} - -version_gte() { - # Returns 0 (true) if $1 >= $2 - [ "$1" -ge "$2" ] 2>/dev/null + echo -e " ${BLUE}→${NC} $1" } command_exists() { command -v "$1" &>/dev/null } -# ============================================================================= -# Common Requirements -# ============================================================================= +version_gte() { + # Returns 0 (true) if $1 >= $2 (numeric comparison) + [[ "$1" -ge "$2" ]] 2>/dev/null +} -check_common_requirements() { - print_subheader "Common Requirements" +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the Java/Spring Boot backend." + exit 0 +} - # Check Git - if command_exists git; then - GIT_VERSION=$(git --version | grep -oE '[0-9]+\.[0-9]+' | head -1) - check_pass "Git installed (v$GIT_VERSION)" - else - check_fail "Git not installed" - check_info "Install Git from https://git-scm.com/" - fi - # Check curl - if command_exists curl; then - check_pass "curl installed" - else - check_warn "curl not installed (optional, but useful for testing)" - fi -} # ============================================================================= -# Java/Spring Boot Requirements +# Check Java/Spring Boot Backend Requirements # ============================================================================= -check_java_requirements() { - print_subheader "Java/Spring Boot Backend" +check_backend_requirements() { + print_section "Java/Spring Boot Backend Requirements" local server_dir="$SCRIPT_DIR/$SERVER_DIR" - # Check Java + # Check Java version if command_exists java; then - # Get Java version - handle different version formats - JAVA_VERSION_OUTPUT=$(java -version 2>&1 | head -n1) - JAVA_VERSION=$(echo "$JAVA_VERSION_OUTPUT" | sed -E 's/.*version "([0-9]+).*/\1/') - - if [ -n "$JAVA_VERSION" ] && version_gte "$JAVA_VERSION" "$JAVA_MIN_VERSION"; then - check_pass "Java installed: version $JAVA_VERSION (>= $JAVA_MIN_VERSION required)" + local java_version + java_version=$(java -version 2>&1 | head -n1 | sed -E 's/.*version "([0-9]+).*/\1/') + if [[ -n "$java_version" ]] && version_gte "$java_version" "$JAVA_MIN_VERSION"; then + check_pass "Java $java_version installed (>= $JAVA_MIN_VERSION required)" else - check_fail "Java version $JAVA_VERSION is too old (>= $JAVA_MIN_VERSION required)" - check_info "Install Java $JAVA_MIN_VERSION+ from:" - check_info " - Eclipse Temurin: https://adoptium.net/" - check_info " - Oracle JDK: https://www.oracle.com/java/technologies/downloads/" - check_info " - Or use SDKMAN: https://sdkman.io/" + check_fail "Java $java_version installed but >= $JAVA_MIN_VERSION required" + check_info "Install Java $JAVA_MIN_VERSION+ from https://adoptium.net/" fi else check_fail "Java not installed" - check_info "Install Java $JAVA_MIN_VERSION+ from:" - check_info " - Eclipse Temurin: https://adoptium.net/" - check_info " - Oracle JDK: https://www.oracle.com/java/technologies/downloads/" - check_info " - Or use SDKMAN: https://sdkman.io/" + check_info "Install Java $JAVA_MIN_VERSION+ from https://adoptium.net/" return fi # Check JAVA_HOME - if [ -n "$JAVA_HOME" ]; then - if [ -d "$JAVA_HOME" ]; then + if [[ -n "$JAVA_HOME" ]]; then + if [[ -d "$JAVA_HOME" ]]; then check_pass "JAVA_HOME is set: $JAVA_HOME" else check_warn "JAVA_HOME is set but directory doesn't exist: $JAVA_HOME" @@ -154,40 +139,40 @@ check_java_requirements() { check_info "Set JAVA_HOME to your Java installation directory" fi - # Check Maven wrapper - if [ -f "$server_dir/mvnw" ]; then + if [[ -f "$server_dir/mvnw" ]]; then check_pass "Maven wrapper (mvnw) found" # Check if mvnw is executable - if [ -x "$server_dir/mvnw" ]; then + if [[ -x "$server_dir/mvnw" ]]; then check_pass "Maven wrapper is executable" else check_warn "Maven wrapper is not executable" - if [ "$SETUP_MODE" = true ]; then + if [[ "$SETUP_MODE" == true ]]; then chmod +x "$server_dir/mvnw" check_pass "Made Maven wrapper executable" else - check_info "Run: chmod +x $server_dir/mvnw" + check_info "Run: chmod +x $SERVER_DIR/mvnw" fi fi # Try to get Maven version - MAVEN_VERSION=$(cd "$server_dir" && ./mvnw --version 2>/dev/null | grep "Apache Maven" | awk '{print $3}') - if [ -n "$MAVEN_VERSION" ]; then - check_pass "Maven version: $MAVEN_VERSION" + local maven_version + maven_version=$(cd "$server_dir" && ./mvnw --version 2>/dev/null | grep "Apache Maven" | awk '{print $3}') + if [[ -n "$maven_version" ]]; then + check_pass "Maven version: $maven_version" fi else - check_fail "Maven wrapper (mvnw) not found in $server_dir" + check_fail "Maven wrapper (mvnw) not found in $SERVER_DIR" check_info "The Maven wrapper should be included in the repository" fi # Check if Maven dependencies are downloaded - if [ -d "$server_dir/target" ]; then + if [[ -d "$server_dir/target" ]]; then check_pass "Maven target directory exists (dependencies likely downloaded)" else check_warn "Maven target directory not found" - if [ "$SETUP_MODE" = true ]; then + if [[ "$SETUP_MODE" == true ]]; then check_info "Downloading Maven dependencies..." if (cd "$server_dir" && ./mvnw dependency:resolve -q); then check_pass "Maven dependencies downloaded successfully" @@ -195,16 +180,16 @@ check_java_requirements() { check_fail "Failed to download Maven dependencies" fi else - check_info "Run: cd $server_dir && ./mvnw dependency:resolve" + check_info "Run: cd $SERVER_DIR && ./mvnw dependency:resolve" fi fi # Check if project compiles - if [ -d "$server_dir/target/classes" ]; then + if [[ -d "$server_dir/target/classes" ]]; then check_pass "Project appears to be compiled" else check_warn "Project not compiled yet" - if [ "$SETUP_MODE" = true ]; then + if [[ "$SETUP_MODE" == true ]]; then check_info "Compiling project..." if (cd "$server_dir" && ./mvnw compile -q); then check_pass "Project compiled successfully" @@ -212,74 +197,80 @@ check_java_requirements() { check_fail "Failed to compile project" fi else - check_info "Run: cd $server_dir && ./mvnw compile" + check_info "Run: cd $SERVER_DIR && ./mvnw compile" fi fi } # ============================================================================= -# Environment Configuration +# Check Environment Configuration # ============================================================================= check_env_configuration() { - print_subheader "Environment Configuration" + print_section "Environment Configuration" local server_dir="$SCRIPT_DIR/$SERVER_DIR" local env_file="$server_dir/.env" - local example_file="$server_dir/.env.example" + local env_example="$server_dir/.env.example" - if [ -f "$env_file" ]; then + # Check .env file + if [[ -f "$env_file" ]]; then check_pass ".env file exists" - # Check MongoDB URI + # Check MONGODB_URI if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then - if grep -qE "^MONGODB_URI=.*<.*>" "$env_file" 2>/dev/null; then - check_warn "MONGODB_URI appears to be a placeholder - update with your connection string" - elif grep -qE "^MONGODB_URI=.+" "$env_file" 2>/dev/null; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then check_pass "MONGODB_URI is configured" else - check_warn "MONGODB_URI is empty" + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" fi else check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" fi - # Check Voyage AI key (optional) + # Check VOYAGE_API_KEY (optional) if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then - if grep -qE "^VOYAGE_API_KEY=your" "$env_file" 2>/dev/null || \ - grep -qE "^VOYAGE_API_KEY=$" "$env_file" 2>/dev/null; then - check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" - else + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" fi else - check_info "VOYAGE_API_KEY not found (optional - needed for vector search)" + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" fi - # Check CORS_ORIGINS + # Check CORS_ORIGINS (optional) if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then check_pass "CORS_ORIGINS is configured" else - check_info "CORS_ORIGINS not found (will use default: http://localhost:3000)" + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" fi - # Check PORT + # Check PORT (optional) if grep -q "^PORT=" "$env_file" 2>/dev/null; then check_pass "PORT is configured" else - check_info "PORT not found (will use default)" + check_info "PORT not set (will use default: 3001)" fi else check_warn ".env file not found" - if [ -f "$example_file" ]; then - check_info ".env.example exists - use it as a template" - if [ "$SETUP_MODE" = true ]; then - cp "$example_file" "$env_file" - check_pass "Created .env from .env.example" - check_warn "Please edit $env_file with your actual values" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi else - check_info "Run: cp $example_file $env_file" - check_info "Then edit .env with your actual values" + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" fi else check_fail "No .env.example found to use as template" @@ -287,131 +278,121 @@ check_env_configuration() { fi } - # ============================================================================= -# Frontend Requirements +# Check Frontend Requirements # ============================================================================= check_frontend_requirements() { - print_header "Frontend Requirements (Next.js)" + print_section "Frontend Requirements (Next.js)" local client_dir="$SCRIPT_DIR/$CLIENT_DIR" - # Check Node.js (required for frontend) - print_subheader "Node.js" + # Check Node.js if command_exists node; then - NODE_VERSION=$(node --version 2>/dev/null | sed 's/v//') - NODE_MAJOR=$(echo "$NODE_VERSION" | cut -d. -f1) - - if [ "$NODE_MAJOR" -ge "$NODE_MIN_VERSION" ] 2>/dev/null; then - check_pass "Node.js installed: v$NODE_VERSION (required: >= $NODE_MIN_VERSION)" + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" else - check_fail "Node.js version $NODE_VERSION is too old (required: >= $NODE_MIN_VERSION)" - check_info "Install Node.js $NODE_MIN_VERSION+ from: https://nodejs.org/" + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" fi else check_fail "Node.js not installed" - check_info "Install Node.js $NODE_MIN_VERSION+ from: https://nodejs.org/" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" return fi # Check npm - print_subheader "npm" if command_exists npm; then - NPM_VERSION=$(npm --version 2>/dev/null) - check_pass "npm installed: v$NPM_VERSION" + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" else check_fail "npm not installed" - check_info "npm should be installed with Node.js" + check_info "npm should come with Node.js installation" + return + fi + + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" return fi # Check client dependencies - print_subheader "Frontend Dependencies" - if [ -d "$client_dir/node_modules" ]; then + if [[ -d "$client_dir/node_modules" ]]; then check_pass "Frontend dependencies installed" - # Check for Next.js - if [ -d "$client_dir/node_modules/next" ]; then - check_pass "Next.js is installed" + # Check Next.js + if [[ -d "$client_dir/node_modules/next" ]]; then + check_pass "Next.js dependency installed" else check_warn "Next.js not found in dependencies" fi - # Check for React - if [ -d "$client_dir/node_modules/react" ]; then - check_pass "React is installed" + # Check React + if [[ -d "$client_dir/node_modules/react" ]]; then + check_pass "React dependency installed" else check_warn "React not found in dependencies" fi else check_warn "Frontend dependencies not installed" - if [ "$SETUP_MODE" = true ]; then + if [[ "$SETUP_MODE" == true ]]; then check_info "Installing frontend dependencies..." - if (cd "$client_dir" && npm install); then + if (cd "$client_dir" && npm install &>/dev/null); then check_pass "Frontend dependencies installed successfully" else check_fail "Failed to install frontend dependencies" fi else - check_info "Run: cd $client_dir && npm install" + check_info "Run: cd $CLIENT_DIR && npm install" fi fi } # ============================================================================= -# Summary +# Print Summary # ============================================================================= print_summary() { - echo "" - echo "=============================================================================" - echo " SUMMARY" - echo "=============================================================================" - echo "" - - if [ "$CHECKS_FAILED" -eq 0 ]; then - echo -e "${GREEN}✓ All checks passed!${NC}" - else - echo -e "${RED}✗ Some checks failed${NC}" - fi - + print_header "Summary" echo "" echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" echo "" - if [ "$CHECKS_FAILED" -gt 0 ]; then - echo "Review the failed checks above and follow the instructions to resolve them." - echo "Run with --setup flag to automatically fix some issues: ./check-requirements.sh --setup" - echo "" + if [[ $CHECKS_FAILED -eq 0 ]]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi + else + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [[ "$SETUP_MODE" != true ]]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi fi + echo "" } # ============================================================================= # Main Execution # ============================================================================= -main() { - echo "=============================================================================" - echo " Java/Spring Boot Backend - Requirements Verification" - echo "=============================================================================" - echo "" - - check_common_requirements - check_java_requirements - check_env_configuration - check_frontend_requirements - print_summary +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" - # Exit with error code if any checks failed - if [ "$CHECKS_FAILED" -gt 0 ]; then - exit 1 - fi -} +# Default options +SETUP_MODE=false -# Parse command line arguments +# Parse arguments while [[ $# -gt 0 ]]; do case $1 in --setup) @@ -419,13 +400,7 @@ while [[ $# -gt 0 ]]; do shift ;; --help|-h) - echo "Usage: ./check-requirements.sh [OPTIONS]" - echo "" - echo "Options:" - echo " --setup Automatically set up missing requirements where possible" - echo " --help Show this help message" - echo "" - exit 0 + show_help ;; *) echo "Unknown option: $1" @@ -435,4 +410,27 @@ while [[ $# -gt 0 ]]; do esac done -main \ No newline at end of file +# Print banner +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ Java/Spring Boot Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [[ "$SETUP_MODE" == true ]]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_backend_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [[ $CHECKS_FAILED -gt 0 ]]; then + exit 1 +fi +exit 0 \ No newline at end of file diff --git a/mflix/check-requirements-js.sh b/mflix/check-requirements-js.sh index e6ee17c..a588fe0 100755 --- a/mflix/check-requirements-js.sh +++ b/mflix/check-requirements-js.sh @@ -1,28 +1,32 @@ #!/bin/bash -# +# ============================================================================= # Requirements Verification Script for mflix Sample Application -# JavaScript/Express Backend (Node.js + Express + MongoDB) +# JavaScript/Express Backend +# ============================================================================= # -# This script checks if you have all the necessary requirements to run the -# mflix sample application with the JavaScript/Express backend. +# This script checks that all necessary requirements are installed to run +# the mflix sample application with the JavaScript/Express backend. # # Usage: -# ./check-requirements.sh # Check all requirements -# ./check-requirements.sh --setup # Check and auto-setup missing items -# ./check-requirements.sh --help # Show help message +# ./check-requirements-js.sh # Check all requirements +# ./check-requirements-js.sh --setup # Check and auto-setup missing items +# ./check-requirements-js.sh --help # Show help message # +# ============================================================================= +# Exit on error (but handle arithmetic expressions carefully) set -e # ============================================================================= # Configuration # ============================================================================= -# Server directory (in artifact repo, server/js-express becomes just server) SERVER_DIR="server" +CLIENT_DIR="client" +NODE_MIN_VERSION="18" # ============================================================================= -# Colors for output +# Colors # ============================================================================= RED='\033[0;31m' @@ -43,82 +47,91 @@ CHECKS_WARNED=0 # Helper Functions # ============================================================================= +print_header() { + echo "" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE} $1${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +} + +print_section() { + echo "" + echo -e "${YELLOW}▸ $1${NC}" +} + check_pass() { - echo -e "${GREEN}✓${NC} $1" + echo -e " ${GREEN}✓${NC} $1" CHECKS_PASSED=$((CHECKS_PASSED + 1)) } check_fail() { - echo -e "${RED}✗${NC} $1" + echo -e " ${RED}✗${NC} $1" CHECKS_FAILED=$((CHECKS_FAILED + 1)) } check_warn() { - echo -e "${YELLOW}!${NC} $1" + echo -e " ${YELLOW}⚠${NC} $1" CHECKS_WARNED=$((CHECKS_WARNED + 1)) } check_info() { - echo -e "${BLUE}ℹ${NC} $1" + echo -e " ${BLUE}→${NC} $1" } -print_section() { - echo "" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" - echo -e "${BLUE} $1${NC}" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +command_exists() { + command -v "$1" &>/dev/null } -# ============================================================================= -# Check Common Requirements -# ============================================================================= +version_gte() { + # Returns 0 (true) if $1 >= $2 (numeric comparison) + [[ "$1" -ge "$2" ]] 2>/dev/null +} -check_common_requirements() { - print_section "Common Requirements" +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --setup Attempt to automatically set up missing requirements" + echo " --help Show this help message" + echo "" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the JavaScript/Express backend." + exit 0 +} - # Check Git - if command -v git &> /dev/null; then - local git_version=$(git --version | cut -d' ' -f3) - check_pass "Git installed (version $git_version)" - else - check_fail "Git not installed" - check_info "Install Git: https://git-scm.com/downloads" - fi - # Check curl (useful for API testing) - if command -v curl &> /dev/null; then - check_pass "curl installed" - else - check_warn "curl not installed (optional, useful for API testing)" - fi -} # ============================================================================= -# Check Node.js/Express Requirements +# Check JavaScript/Express Backend Requirements # ============================================================================= -check_node_requirements() { - print_section "Node.js/Express Backend Requirements" +check_backend_requirements() { + print_section "JavaScript/Express Backend Requirements" - # Check Node.js - if command -v node &> /dev/null; then - local node_version=$(node --version | sed 's/v//') - local node_major=$(echo "$node_version" | cut -d. -f1) - if [ "$node_major" -ge 18 ]; then - check_pass "Node.js installed (version $node_version)" + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + + # Check Node.js version + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js $node_version installed (>= $NODE_MIN_VERSION required)" else - check_fail "Node.js version $node_version is below minimum required (18+)" - check_info "Install Node.js 18+: https://nodejs.org/" + check_fail "Node.js $node_version installed but >= $NODE_MIN_VERSION required" + check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" fi else check_fail "Node.js not installed" - check_info "Install Node.js 18+: https://nodejs.org/" + check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" return fi # Check npm - if command -v npm &> /dev/null; then - local npm_version=$(npm --version) + if command_exists npm; then + local npm_version + npm_version=$(npm --version) check_pass "npm installed (version $npm_version)" else check_fail "npm not installed" @@ -127,13 +140,13 @@ check_node_requirements() { fi # Check server directory - if [ ! -d "$SERVER_DIR" ]; then + if [[ ! -d "$server_dir" ]]; then check_fail "Server directory not found: $SERVER_DIR" return fi # Check package.json - if [ -f "$SERVER_DIR/package.json" ]; then + if [[ -f "$server_dir/package.json" ]]; then check_pass "package.json found" else check_fail "package.json not found in $SERVER_DIR" @@ -141,41 +154,41 @@ check_node_requirements() { fi # Check node_modules - if [ -d "$SERVER_DIR/node_modules" ]; then + if [[ -d "$server_dir/node_modules" ]]; then check_pass "node_modules directory exists" - # Check key dependencies - if [ -d "$SERVER_DIR/node_modules/express" ]; then + # Check Express.js + if [[ -d "$server_dir/node_modules/express" ]]; then check_pass "Express.js dependency installed" else check_fail "Express.js dependency not installed" fi - if [ -d "$SERVER_DIR/node_modules/mongodb" ]; then + # Check MongoDB driver + if [[ -d "$server_dir/node_modules/mongodb" ]]; then check_pass "MongoDB driver dependency installed" else check_fail "MongoDB driver dependency not installed" fi # Check TypeScript build - if [ -d "$SERVER_DIR/dist" ]; then + if [[ -d "$server_dir/dist" ]]; then check_pass "TypeScript build output exists (dist directory)" else check_warn "TypeScript build output not found (dist directory)" - check_info "Run 'npm run build' in $SERVER_DIR to build" + check_info "Run: cd $SERVER_DIR && npm run build" fi else - check_fail "node_modules directory not found" - if [ "$SETUP_MODE" = true ]; then - check_info "Attempting to install dependencies..." - if (cd "$SERVER_DIR" && npm install); then + check_warn "node_modules directory not found" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing dependencies..." + if (cd "$server_dir" && npm install &>/dev/null); then check_pass "Dependencies installed successfully" else check_fail "Failed to install dependencies" - check_info "Run 'npm install' manually in $SERVER_DIR" fi else - check_info "Run 'npm install' in $SERVER_DIR or use --setup flag" + check_info "Run: cd $SERVER_DIR && npm install" fi fi } @@ -187,37 +200,40 @@ check_node_requirements() { check_env_configuration() { print_section "Environment Configuration" - local env_file="$SERVER_DIR/.env" - local env_example="$SERVER_DIR/.env.example" + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local env_example="$server_dir/.env.example" # Check .env file - if [ -f "$env_file" ]; then + if [[ -f "$env_file" ]]; then check_pass ".env file exists" # Check MONGODB_URI if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then - local mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) - if [ -n "$mongo_uri" ] && [ "$mongo_uri" != "mongodb+srv://:@.mongodb.net/" ]; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then check_pass "MONGODB_URI is configured" else check_fail "MONGODB_URI is not configured (still has placeholder value)" - check_info "Update MONGODB_URI in $env_file with your MongoDB connection string" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" fi else check_fail "MONGODB_URI not found in .env" - check_info "Add MONGODB_URI= to $env_file" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" fi # Check VOYAGE_API_KEY (optional) if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then - local voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) - if [ -n "$voyage_key" ] && [ "$voyage_key" != "" ]; then + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then check_pass "VOYAGE_API_KEY is configured" else - check_warn "VOYAGE_API_KEY has placeholder value (optional for vector search)" + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" fi else - check_info "VOYAGE_API_KEY not set (optional, needed for vector search features)" + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" fi # Check CORS_ORIGINS (optional) @@ -229,37 +245,26 @@ check_env_configuration() { # Check PORT (optional) if grep -q "^PORT=" "$env_file" 2>/dev/null; then - local port=$(grep "^PORT=" "$env_file" | cut -d'=' -f2-) - check_pass "PORT is configured ($port)" + check_pass "PORT is configured" else check_info "PORT not set (will use default: 3001)" fi - - # Check LOG_LEVEL (optional) - if grep -q "^LOG_LEVEL=" "$env_file" 2>/dev/null; then - check_pass "LOG_LEVEL is configured" - else - check_info "LOG_LEVEL not set (will use default)" - fi else - check_fail ".env file not found" - if [ -f "$env_example" ]; then - if [ "$SETUP_MODE" = true ]; then - check_info "Attempting to create .env from .env.example..." + check_warn ".env file not found" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." if cp "$env_example" "$env_file"; then check_pass ".env file created from .env.example" - check_warn "Please update the placeholder values in $env_file" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" else check_fail "Failed to create .env file" fi else - check_info "Copy .env.example to .env: cp $env_example $env_file" - check_info "Or use --setup flag to create automatically" + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" fi else - check_info "Create a .env file with required configuration" - check_info "Required: MONGODB_URI" - check_info "Optional: VOYAGE_API_KEY, CORS_ORIGINS, PORT, LOG_LEVEL" + check_fail "No .env.example found to use as template" fi fi } @@ -271,52 +276,72 @@ check_env_configuration() { check_frontend_requirements() { print_section "Frontend Requirements (Next.js)" - local client_dir="client" + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" - # Check client directory - if [ ! -d "$client_dir" ]; then - check_warn "Client directory not found: $client_dir" - check_info "Frontend may be in a separate repository" + # Check Node.js + if command_exists node; then + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" + else + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + fi + else + check_fail "Node.js not installed" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" return fi - # Check package.json - if [ -f "$client_dir/package.json" ]; then - check_pass "Frontend package.json found" + # Check npm + if command_exists npm; then + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" else - check_fail "Frontend package.json not found" + check_fail "npm not installed" + check_info "npm should come with Node.js installation" return fi - # Check node_modules - if [ -d "$client_dir/node_modules" ]; then - check_pass "Frontend node_modules exists" + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" + return + fi + + # Check client dependencies + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Frontend dependencies installed" # Check Next.js - if [ -d "$client_dir/node_modules/next" ]; then + if [[ -d "$client_dir/node_modules/next" ]]; then check_pass "Next.js dependency installed" else - check_fail "Next.js dependency not installed" + check_warn "Next.js not found in dependencies" fi # Check React - if [ -d "$client_dir/node_modules/react" ]; then + if [[ -d "$client_dir/node_modules/react" ]]; then check_pass "React dependency installed" else - check_fail "React dependency not installed" + check_warn "React not found in dependencies" fi else - check_fail "Frontend node_modules not found" - if [ "$SETUP_MODE" = true ]; then - check_info "Attempting to install frontend dependencies..." - if (cd "$client_dir" && npm install); then + check_warn "Frontend dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then check_pass "Frontend dependencies installed successfully" else check_fail "Failed to install frontend dependencies" - check_info "Run 'npm install' manually in $client_dir" fi else - check_info "Run 'npm install' in $client_dir or use --setup flag" + check_info "Run: cd $CLIENT_DIR && npm install" fi fi } @@ -326,24 +351,21 @@ check_frontend_requirements() { # ============================================================================= print_summary() { + print_header "Summary" echo "" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" - echo -e "${BLUE} Summary${NC}" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" - echo "" - echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" - echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" echo "" - if [ $CHECKS_FAILED -eq 0 ]; then + if [[ $CHECKS_FAILED -eq 0 ]]; then echo -e "${GREEN}All required checks passed!${NC}" - if [ $CHECKS_WARNED -gt 0 ]; then + if [[ $CHECKS_WARNED -gt 0 ]]; then echo -e "${YELLOW}There are some warnings to review.${NC}" fi else echo -e "${RED}Some checks failed. Please address the issues above.${NC}" - if [ "$SETUP_MODE" != true ]; then + if [[ "$SETUP_MODE" != true ]]; then echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" fi fi @@ -354,6 +376,11 @@ print_summary() { # Main Execution # ============================================================================= +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +# Default options SETUP_MODE=false # Parse arguments @@ -364,15 +391,7 @@ while [[ $# -gt 0 ]]; do shift ;; --help|-h) - echo "Usage: $0 [OPTIONS]" - echo "" - echo "Options:" - echo " --setup Attempt to automatically set up missing requirements" - echo " --help Show this help message" - echo "" - echo "This script checks if you have all the necessary requirements" - echo "to run the mflix sample application with the JavaScript/Express backend." - exit 0 + show_help ;; *) echo "Unknown option: $1" @@ -382,19 +401,19 @@ while [[ $# -gt 0 ]]; do esac done +# Print banner echo "" echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" echo -e "${BLUE}║ JavaScript/Express Backend ║${NC}" echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" -if [ "$SETUP_MODE" = true ]; then +if [[ "$SETUP_MODE" == true ]]; then echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" fi # Run all checks -check_common_requirements -check_node_requirements +check_backend_requirements check_env_configuration check_frontend_requirements @@ -402,7 +421,7 @@ check_frontend_requirements print_summary # Exit with appropriate code -if [ $CHECKS_FAILED -gt 0 ]; then +if [[ $CHECKS_FAILED -gt 0 ]]; then exit 1 fi exit 0 diff --git a/mflix/check-requirements-python.sh b/mflix/check-requirements-python.sh index e761350..ea1249c 100755 --- a/mflix/check-requirements-python.sh +++ b/mflix/check-requirements-python.sh @@ -1,49 +1,61 @@ #!/bin/bash - # ============================================================================= # Requirements Verification Script for mflix Sample Application # Python/FastAPI Backend # ============================================================================= +# # This script checks that all necessary requirements are installed to run # the mflix sample application with the Python/FastAPI backend. # -# Usage: ./check-requirements.sh [options] -# --setup Attempt to set up missing requirements -# --help Show this help message +# Usage: +# ./check-requirements-python.sh # Check all requirements +# ./check-requirements-python.sh --setup # Check and auto-setup missing items +# ./check-requirements-python.sh --help # Show help message +# +# ============================================================================= + +# Exit on error (but handle arithmetic expressions carefully) +set -e + +# ============================================================================= +# Configuration +# ============================================================================= + +SERVER_DIR="server" +CLIENT_DIR="client" +PYTHON_MIN_VERSION="3.11" +NODE_MIN_VERSION="18" + +# ============================================================================= +# Colors # ============================================================================= -# Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# ============================================================================= # Counters +# ============================================================================= + CHECKS_PASSED=0 CHECKS_FAILED=0 CHECKS_WARNED=0 -# Options -SETUP_MODE=false - -# Configuration -PYTHON_MIN_VERSION="3.11" -SERVER_DIR="server" -CLIENT_DIR="client" - # ============================================================================= # Helper Functions # ============================================================================= print_header() { echo "" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${BLUE} $1${NC}" - echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" } -print_subheader() { +print_section() { echo "" echo -e "${YELLOW}▸ $1${NC}" } @@ -64,108 +76,55 @@ check_warn() { } check_info() { - echo -e " ${BLUE}ℹ${NC} $1" -} - -version_gte() { - [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ] + echo -e " ${BLUE}→${NC} $1" } command_exists() { - command -v "$1" >/dev/null 2>&1 + command -v "$1" &>/dev/null } -# ============================================================================= -# Parse Arguments -# ============================================================================= +version_gte() { + # Returns 0 (true) if $1 >= $2 using version sorting + [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ] +} show_help() { - echo "Usage: ./check-requirements.sh [options]" + echo "Usage: $0 [OPTIONS]" echo "" echo "Options:" - echo " --setup Attempt to set up missing requirements" + echo " --setup Attempt to automatically set up missing requirements" echo " --help Show this help message" echo "" - echo "Examples:" - echo " ./check-requirements.sh # Check all requirements" - echo " ./check-requirements.sh --setup # Check and set up missing items" + echo "This script checks that all necessary requirements are installed" + echo "to run the mflix sample application with the Python/FastAPI backend." + exit 0 } -while [[ $# -gt 0 ]]; do - case $1 in - --setup) - SETUP_MODE=true - shift - ;; - --help) - show_help - exit 0 - ;; - *) - echo "Unknown option: $1" - show_help - exit 1 - ;; - esac -done - -# ============================================================================= -# Get Script Directory -# ============================================================================= -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" - -print_header "mflix Sample Application - Python/FastAPI Requirements Check" -echo "" -echo "Setup mode: $SETUP_MODE" -echo "Working directory: $SCRIPT_DIR" # ============================================================================= -# Common Requirements +# Check Python/FastAPI Backend Requirements # ============================================================================= -check_common_requirements() { - print_subheader "Common Requirements" +check_backend_requirements() { + print_section "Python/FastAPI Backend Requirements" - # Check Git - if command_exists git; then - local git_version - git_version=$(git --version | awk '{print $3}') - check_pass "Git installed (version $git_version)" - else - check_fail "Git not installed" - check_info "Install Git: https://git-scm.com/downloads" - fi - - # Check curl - if command_exists curl; then - check_pass "curl installed" - else - check_fail "curl not installed" - check_info "Install curl using your package manager" - fi -} - -# ============================================================================= -# Python Backend Requirements -# ============================================================================= - -check_python_requirements() { - print_subheader "Python/FastAPI Backend Requirements" + local server_dir="$SCRIPT_DIR/$SERVER_DIR" # Check Python version if command_exists python3; then - PYTHON_VERSION=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1) - if version_gte "$PYTHON_VERSION" "$PYTHON_MIN_VERSION"; then - check_pass "Python $PYTHON_VERSION installed (>= $PYTHON_MIN_VERSION required)" + local python_version + python_version=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1) + if version_gte "$python_version" "$PYTHON_MIN_VERSION"; then + check_pass "Python $python_version installed (>= $PYTHON_MIN_VERSION required)" else - check_fail "Python $PYTHON_VERSION installed but >= $PYTHON_MIN_VERSION required" + check_fail "Python $python_version installed but >= $PYTHON_MIN_VERSION required" check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" fi else check_fail "Python 3 not installed" check_info "Install Python $PYTHON_MIN_VERSION+ from https://www.python.org/downloads/" + return fi # Check pip @@ -177,11 +136,11 @@ check_python_requirements() { fi # Check virtual environment - local venv_dir="$SCRIPT_DIR/$SERVER_DIR/.venv" + local venv_dir="$server_dir/.venv" if [[ -d "$venv_dir" ]]; then check_pass "Python virtual environment exists at $SERVER_DIR/.venv" - # Check if venv is activated or can be used + # Check if venv activation script exists if [[ -f "$venv_dir/bin/activate" ]]; then check_pass "Virtual environment activation script exists" else @@ -202,7 +161,7 @@ check_python_requirements() { fi # Check Python dependencies - local requirements_file="$SCRIPT_DIR/$SERVER_DIR/requirements.txt" + local requirements_file="$server_dir/requirements.txt" if [[ -f "$requirements_file" ]]; then check_pass "requirements.txt found" @@ -241,160 +200,234 @@ check_python_requirements() { } # ============================================================================= -# Environment Configuration +# Check Environment Configuration # ============================================================================= check_env_configuration() { - print_subheader "Environment Configuration" + print_section "Environment Configuration" - local env_file="$SCRIPT_DIR/$SERVER_DIR/.env" - local env_example="$SCRIPT_DIR/$SERVER_DIR/.env.example" + local server_dir="$SCRIPT_DIR/$SERVER_DIR" + local env_file="$server_dir/.env" + local env_example="$server_dir/.env.example" - # Check .env file exists + # Check .env file if [[ -f "$env_file" ]]; then - check_pass ".env file exists at $SERVER_DIR/.env" - else - check_warn ".env file not found at $SERVER_DIR/.env" - if [[ "$SETUP_MODE" == true ]] && [[ -f "$env_example" ]]; then - check_info "Copying .env.example to .env..." - if cp "$env_example" "$env_file"; then - check_pass ".env file created from .env.example" - check_info "Please update the values in $SERVER_DIR/.env" + check_pass ".env file exists" + + # Check MONGODB_URI + if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then + local mongo_uri + mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$mongo_uri" ]] && [[ "$mongo_uri" != *"<"*">"* ]]; then + check_pass "MONGODB_URI is configured" else - check_fail "Failed to create .env file" + check_fail "MONGODB_URI is not configured (still has placeholder value)" + check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" fi else - check_info "Copy the example: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + check_fail "MONGODB_URI not found in .env" + check_info "Add MONGODB_URI to $SERVER_DIR/.env" fi - return - fi - # Check required environment variables - if grep -q "^MONGODB_URI=" "$env_file" 2>/dev/null; then - local mongo_uri=$(grep "^MONGODB_URI=" "$env_file" | cut -d'=' -f2-) - if [[ -n "$mongo_uri" && "$mongo_uri" != "mongodb+srv://:@.mongodb.net/" ]]; then - check_pass "MONGODB_URI is configured" + # Check VOYAGE_API_KEY (optional) + if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then + local voyage_key + voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) + if [[ -n "$voyage_key" ]] && [[ "$voyage_key" != "your_voyage_api_key" ]]; then + check_pass "VOYAGE_API_KEY is configured" + else + check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + fi else - check_fail "MONGODB_URI is not configured (still has placeholder value)" - check_info "Update MONGODB_URI in $SERVER_DIR/.env with your MongoDB connection string" + check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" fi - else - check_fail "MONGODB_URI not found in .env" - check_info "Add MONGODB_URI to $SERVER_DIR/.env" - fi - # Check optional environment variables - if grep -q "^VOYAGE_API_KEY=" "$env_file" 2>/dev/null; then - local voyage_key=$(grep "^VOYAGE_API_KEY=" "$env_file" | cut -d'=' -f2-) - if [[ -n "$voyage_key" && "$voyage_key" != "" ]]; then - check_pass "VOYAGE_API_KEY is configured" + # Check CORS_ORIGINS (optional) + if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then + check_pass "CORS_ORIGINS is configured" else - check_info "VOYAGE_API_KEY not configured (optional - needed for vector search)" + check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" fi - else - check_info "VOYAGE_API_KEY not set (optional - needed for vector search)" - fi - if grep -q "^CORS_ORIGINS=" "$env_file" 2>/dev/null; then - check_pass "CORS_ORIGINS is configured" - else - check_info "CORS_ORIGINS not set (will use default: http://localhost:3000)" - fi - - if grep -q "^PORT=" "$env_file" 2>/dev/null; then - check_pass "PORT is configured" + # Check PORT (optional) + if grep -q "^PORT=" "$env_file" 2>/dev/null; then + check_pass "PORT is configured" + else + check_info "PORT not set (will use default: 3001)" + fi else - check_info "PORT not set (will use default: 8000)" + check_warn ".env file not found" + if [[ -f "$env_example" ]]; then + if [[ "$SETUP_MODE" == true ]]; then + check_info "Creating .env from .env.example..." + if cp "$env_example" "$env_file"; then + check_pass ".env file created from .env.example" + check_warn "Please update the placeholder values in $SERVER_DIR/.env" + else + check_fail "Failed to create .env file" + fi + else + check_info "Copy .env.example to .env: cp $SERVER_DIR/.env.example $SERVER_DIR/.env" + fi + else + check_fail "No .env.example found to use as template" + fi fi } - - # ============================================================================= -# Frontend Requirements (Next.js) +# Check Frontend Requirements # ============================================================================= check_frontend_requirements() { - print_subheader "Frontend Requirements (Next.js)" + print_section "Frontend Requirements (Next.js)" - # Check Node.js version + local client_dir="$SCRIPT_DIR/$CLIENT_DIR" + + # Check Node.js if command_exists node; then - NODE_VERSION=$(node --version 2>&1 | grep -oE '[0-9]+' | head -1) - if version_gte "$NODE_VERSION" "$NODE_MIN_VERSION"; then - check_pass "Node.js v$NODE_VERSION installed (>= v$NODE_MIN_VERSION required)" + local node_version + node_version=$(node --version | sed 's/v//') + local node_major + node_major=$(echo "$node_version" | cut -d. -f1) + if [[ "$node_major" -ge "$NODE_MIN_VERSION" ]]; then + check_pass "Node.js installed (version $node_version, >= $NODE_MIN_VERSION required)" else - check_fail "Node.js v$NODE_VERSION installed but >= v$NODE_MIN_VERSION required" + check_fail "Node.js version $node_version is below minimum required ($NODE_MIN_VERSION+)" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" fi else check_fail "Node.js not installed" - check_info "Install Node.js $NODE_MIN_VERSION+ from https://nodejs.org/" + check_info "Install Node.js $NODE_MIN_VERSION+: https://nodejs.org/" + return fi # Check npm if command_exists npm; then - check_pass "npm installed" + local npm_version + npm_version=$(npm --version) + check_pass "npm installed (version $npm_version)" else check_fail "npm not installed" + check_info "npm should come with Node.js installation" + return + fi + + # Check client directory + if [[ ! -d "$client_dir" ]]; then + check_warn "Client directory not found: $CLIENT_DIR" + check_info "Frontend may be in a separate repository" + return fi # Check client dependencies - local client_dir="$SCRIPT_DIR/$CLIENT_DIR" - if [[ -d "$client_dir" ]]; then - if [[ -d "$client_dir/node_modules" ]]; then - check_pass "Client dependencies installed" + if [[ -d "$client_dir/node_modules" ]]; then + check_pass "Frontend dependencies installed" + + # Check Next.js + if [[ -d "$client_dir/node_modules/next" ]]; then + check_pass "Next.js dependency installed" else - check_warn "Client dependencies not installed" - if [[ "$SETUP_MODE" == true ]]; then - check_info "Installing client dependencies..." - if (cd "$client_dir" && npm install &>/dev/null); then - check_pass "Client dependencies installed" - else - check_fail "Failed to install client dependencies" - fi + check_warn "Next.js not found in dependencies" + fi + + # Check React + if [[ -d "$client_dir/node_modules/react" ]]; then + check_pass "React dependency installed" + else + check_warn "React not found in dependencies" + fi + else + check_warn "Frontend dependencies not installed" + if [[ "$SETUP_MODE" == true ]]; then + check_info "Installing frontend dependencies..." + if (cd "$client_dir" && npm install &>/dev/null); then + check_pass "Frontend dependencies installed successfully" else - check_info "Install with: cd $CLIENT_DIR && npm install" + check_fail "Failed to install frontend dependencies" fi + else + check_info "Run: cd $CLIENT_DIR && npm install" fi fi } # ============================================================================= -# Summary +# Print Summary # ============================================================================= print_summary() { - echo "" print_header "Summary" - echo -e "${GREEN}Passed:${NC} $CHECKS_PASSED" - echo -e "${RED}Failed:${NC} $CHECKS_FAILED" - echo -e "${YELLOW}Warnings:${NC} $CHECKS_WARNED" + echo "" + echo -e " ${GREEN}Passed:${NC} $CHECKS_PASSED" + echo -e " ${RED}Failed:${NC} $CHECKS_FAILED" + echo -e " ${YELLOW}Warnings:${NC} $CHECKS_WARNED" echo "" - if [[ $CHECKS_FAILED -gt 0 ]]; then - echo -e "${RED}Some checks failed. Please address the issues above.${NC}" - exit 1 - elif [[ $CHECKS_WARNED -gt 0 ]]; then - echo -e "${YELLOW}All critical checks passed, but there are warnings to review.${NC}" - exit 0 + if [[ $CHECKS_FAILED -eq 0 ]]; then + echo -e "${GREEN}All required checks passed!${NC}" + if [[ $CHECKS_WARNED -gt 0 ]]; then + echo -e "${YELLOW}There are some warnings to review.${NC}" + fi else - echo -e "${GREEN}All checks passed! You're ready to run the application.${NC}" - exit 0 + echo -e "${RED}Some checks failed. Please address the issues above.${NC}" + if [[ "$SETUP_MODE" != true ]]; then + echo -e "${BLUE}Tip: Run with --setup flag to auto-fix some issues${NC}" + fi fi + echo "" } # ============================================================================= # Main Execution # ============================================================================= -main() { - print_header "Python/FastAPI Sample App - Requirements Check" +# Get script directory and change to it +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" - check_common_requirements - check_python_requirements - check_env_configuration - check_frontend_requirements +# Default options +SETUP_MODE=false - print_summary -} +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --setup) + SETUP_MODE=true + shift + ;; + --help|-h) + show_help + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done -main +# Print banner +echo "" +echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" +echo -e "${BLUE}║ mflix Sample Application - Requirements Check ║${NC}" +echo -e "${BLUE}║ Python/FastAPI Backend ║${NC}" +echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}" + +if [[ "$SETUP_MODE" == true ]]; then + echo -e "${YELLOW}Running in setup mode - will attempt to fix issues${NC}" +fi + +# Run all checks +check_backend_requirements +check_env_configuration +check_frontend_requirements + +# Print summary +print_summary + +# Exit with appropriate code +if [[ $CHECKS_FAILED -gt 0 ]]; then + exit 1 +fi +exit 0