@echo off setlocal enabledelayedexpansion echo ========================================== echo FinMK - Full Setup Script echo ========================================== echo. echo This script will: echo 1. Check Prerequisites echo 2. Create .env file with MongoDB configuration echo 3. Install all Python dependencies echo 4. Install frontend dependencies echo 5. Build frontend with Vite echo 6. Sync static files and Run Migrations echo 7. Verify MongoDB connection echo 8. Run Django system checks echo 9. Start both development servers echo. echo ========================================== echo. :: Check Prerequisites echo [Step 1/9] Checking Prerequisites... where python >nul 2>nul if %errorlevel% neq 0 ( echo [ERROR] Python is not installed or not in PATH. echo Please install Python 3.8+ and add it to PATH. pause exit /b 1 ) where npm >nul 2>nul if %errorlevel% neq 0 ( echo [ERROR] Node.js/npm is not installed or not in PATH. echo Please install Node.js and add it to PATH. pause exit /b 1 ) echo [OK] Python and Node.js detected. echo. :: Create .env file echo [Step 2/9] Creating .env file... cd /d "%~dp0backend" if exist .env ( echo [INFO] .env file already exists. Skipping creation. ) else ( echo Creating .env file with MongoDB Atlas configuration... ( echo # MongoDB Configuration echo MONGODB_URI=mongodb+srv://kumar:KumarDB7@mkcluster.hkk76.mongodb.net/finance echo. echo # Django Configuration echo SECRET_KEY=django-insecure-ereyyk0#@t#lc$@hpx^&9h@60-=-e+#=-3w^w+91w^&ol-^(6c^(fv echo DEBUG=True echo ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0 echo. echo # Database Name echo DB_NAME=finance echo. echo # Gemini AI Configuration echo # Get your free API key from: https://aistudio.google.com/app/apikey echo # Replace 'your_gemini_api_key_here' with your actual API key echo GEMINI_API_KEY=your_gemini_api_key_here ) > .env echo [OK] .env file created successfully. echo. echo [IMPORTANT] Please add your Gemini API key to backend\.env file echo to enable AI chatbot features. echo Get your free key from: https://aistudio.google.com/app/apikey ) echo. :: Install Python Dependencies echo [Step 3/9] Installing Python Dependencies... echo This may take several minutes... echo. python -m pip install --upgrade pip if %errorlevel% neq 0 ( echo [WARNING] Failed to upgrade pip. Continuing... ) echo Installing requirements.txt... pip install -r requirements.txt if %errorlevel% neq 0 ( echo [ERROR] Failed to install Python dependencies. pause exit /b 1 ) echo [OK] Python dependencies installed successfully. echo. :: Install Frontend Dependencies echo [Step 4/9] Installing Frontend Dependencies... cd /d "%~dp0frontend" echo Installing npm packages... call npm install if %errorlevel% neq 0 ( echo [ERROR] Failed to install npm packages. pause exit /b 1 ) echo [OK] Frontend dependencies installed. echo. :: Build Frontend echo [Step 5/9] Building Frontend with Vite... echo This may take a minute... call npm run build if %errorlevel% neq 0 ( echo [ERROR] Frontend build failed. pause exit /b 1 ) echo [OK] Frontend built successfully. echo. :: Sync Static Files and Migrations echo [Step 6/9] Syncing Static Files and Running Migrations... cd /d "%~dp0" if not exist backend\staticfiles mkdir backend\staticfiles echo Copying frontend build to staticfiles... xcopy /E /I /Y "frontend\dist\*" "backend\staticfiles\" if %errorlevel% neq 0 ( echo [WARNING] Failed to copy some files. ) cd backend echo Running database migrations (SQLite)... python manage.py migrate if %errorlevel% neq 0 ( echo [ERROR] Database migration failed. pause exit /b 1 ) echo Running Django collectstatic... python manage.py collectstatic --no-input if %errorlevel% neq 0 ( echo [WARNING] collectstatic completed with warnings. ) else ( echo [OK] Static files collected and migrations applied. ) echo. :: Verify MongoDB Connection echo [Step 7/9] Verifying MongoDB Connection... python -c "from pymongo import MongoClient; import os; from dotenv import load_dotenv; load_dotenv(); uri = os.getenv('MONGODB_URI'); client = MongoClient(uri, serverSelectionTimeoutMS=5000); client.server_info(); print('[OK] MongoDB connected successfully!')" if %errorlevel% neq 0 ( echo [WARNING] MongoDB connection failed. Please check your MONGODB_URI in .env file. echo The application may not work properly without MongoDB. ) else ( echo [OK] MongoDB connection verified. ) echo. :: Run Django System Check echo [Step 8/9] Running Django System Check... python manage.py check if %errorlevel% neq 0 ( echo [WARNING] Django system check found issues. ) else ( echo [OK] Django system check passed. ) echo. :: Final Summary echo ========================================== echo Setup Complete! echo ========================================== echo. echo All components have been initialized: echo [x] Python dependencies installed echo [x] AI models downloaded echo [x] Database migrations applied echo [x] Frontend built echo [x] Static files synced echo [x] MongoDB connection verified echo [x] Django system check passed echo. echo ========================================== echo Starting Development Servers echo ========================================== echo. :: Start Backend Server cd /d "%~dp0backend" echo Starting Backend (Django) on http://localhost:8000... start "FinMK Backend" powershell -NoExit -Command "cd '%~dp0backend'; python manage.py runserver 0.0.0.0:8000" :: Wait a moment before starting frontend timeout /t 2 /nobreak >nul :: Start Frontend Server cd /d "%~dp0frontend" echo Starting Frontend (Vite) on http://localhost:5173... start "FinMK Frontend" powershell -NoExit -Command "cd '%~dp0frontend'; npm run dev" echo. echo ========================================== echo Servers Started! echo ========================================== echo. echo Backend: http://localhost:8000 echo Frontend: http://localhost:5173 echo. echo Both servers are running in separate windows. echo Close the PowerShell windows to stop the servers. echo. echo Press any key to exit this setup window... pause >nul endlocal