-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-local.sh
More file actions
732 lines (644 loc) · 21.9 KB
/
start-local.sh
File metadata and controls
732 lines (644 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
#!/bin/bash
# VRecommendation System - Local Startup Script (No Docker)
# For Linux/Unix systems
set -e
# Colors
GREEN='\033[0;92m'
RED='\033[0;91m'
YELLOW='\033[0;93m'
BLUE='\033[0;94m'
CYAN='\033[0;96m'
NC='\033[0m' # No Color
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# PID files location
PID_DIR="$SCRIPT_DIR/.pids"
mkdir -p "$PID_DIR"
echo ""
echo -e "${BLUE}========================================================${NC}"
echo -e "${BLUE} VRecommendation System - Local Startup (No Docker) ${NC}"
echo -e "${BLUE}========================================================${NC}"
echo ""
# ========================================
# Setup Environment Files
# ========================================
setup_env_files() {
echo -e "${YELLOW}[INFO]${NC} Checking environment files..."
# Check/create root .env
if [ ! -f ".env" ]; then
echo -e "${YELLOW}[INFO]${NC} Creating .env from example-env..."
if [ -f "example-env" ]; then
cp "example-env" ".env"
# Update for local development
sed -i.bak 's/REDIS_HOST=redis/REDIS_HOST=localhost/g' ".env" 2>/dev/null || \
sed -i '' 's/REDIS_HOST=redis/REDIS_HOST=localhost/g' ".env"
sed -i.bak 's/MYSQL_HOST=mysql/MYSQL_HOST=localhost/g' ".env" 2>/dev/null || \
sed -i '' 's/MYSQL_HOST=mysql/MYSQL_HOST=localhost/g' ".env"
sed -i.bak 's/MONGODB_HOST=mongodb/MONGODB_HOST=localhost/g' ".env" 2>/dev/null || \
sed -i '' 's/MONGODB_HOST=mongodb/MONGODB_HOST=localhost/g' ".env"
sed -i.bak 's/KAFKA_BOOTSTRAP_SERVERS=kafka:9093/KAFKA_BOOTSTRAP_SERVERS=localhost:9092/g' ".env" 2>/dev/null || \
sed -i '' 's/KAFKA_BOOTSTRAP_SERVERS=kafka:9093/KAFKA_BOOTSTRAP_SERVERS=localhost:9092/g' ".env"
rm -f ".env.bak" 2>/dev/null
echo -e "${GREEN}[OK]${NC} Root .env created (local mode)"
else
create_default_env
fi
else
echo -e "${GREEN}[OK]${NC} Root .env exists"
fi
# Check/create API server .env
if [ ! -f "backend/api_server/.env" ]; then
echo -e "${YELLOW}[INFO]${NC} Creating API server .env..."
if [ -f "backend/api_server/example-env" ]; then
cp "backend/api_server/example-env" "backend/api_server/.env"
# Update AI_SERVER_URL for local
sed -i.bak 's/AI_SERVER_URL=http:\/\/ai_server:/AI_SERVER_URL=http:\/\/localhost:/g' "backend/api_server/.env" 2>/dev/null || \
sed -i '' 's/AI_SERVER_URL=http:\/\/ai_server:/AI_SERVER_URL=http:\/\/localhost:/g' "backend/api_server/.env"
rm -f "backend/api_server/.env.bak" 2>/dev/null
echo -e "${GREEN}[OK]${NC} API server .env created (local mode)"
else
create_api_env_local
fi
else
echo -e "${GREEN}[OK]${NC} API server .env exists"
fi
# Check/create AI server .env
if [ ! -f "backend/ai_server/.env" ]; then
echo -e "${YELLOW}[INFO]${NC} Creating AI server .env..."
if [ -f "backend/ai_server/example-env" ]; then
cp "backend/ai_server/example-env" "backend/ai_server/.env"
echo -e "${GREEN}[OK]${NC} AI server .env created"
else
create_ai_env_local
fi
else
echo -e "${GREEN}[OK]${NC} AI server .env exists"
fi
# Check/create frontend .env
if [ ! -f "frontend/project/.env" ]; then
echo -e "${YELLOW}[INFO]${NC} Creating frontend .env..."
if [ -f "frontend/project/example-env" ]; then
cp "frontend/project/example-env" "frontend/project/.env"
echo -e "${GREEN}[OK]${NC} Frontend .env created"
else
create_frontend_env_local
fi
else
echo -e "${GREEN}[OK]${NC} Frontend .env exists"
fi
echo ""
}
create_default_env() {
echo -e "${YELLOW}[INFO]${NC} Creating default .env file for local development..."
cat > ".env" << 'EOF'
# VRecommendation Environment Configuration - Local Development
# Auto-generated - Please update with your settings
# Environment
STATUS_DEV=dev
# Host Configuration
HOST_IP=localhost
# API Server Configuration
API_SERVER_HOST=0.0.0.0
API_SERVER_PORT=2030
API_SERVER_READ_TIMEOUT=60
# AI Server Configuration
AI_SERVER_HOST=0.0.0.0
AI_SERVER_PORT=9999
# Frontend Configuration
FRONTEND_PORT=5173
FRONTEND_URL=http://localhost:5173
# Redis Configuration - For local, use localhost
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# Database Configuration (MySQL) - For local development
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=admin
MYSQL_PASSWORD=pokiwar0981
MYSQL_DATABASE=shop
# Database Configuration (MongoDB) - For local development
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_USERNAME=root
MONGODB_PASSWORD=password
MONGODB_AUTH_SOURCE=admin
# Kafka Configuration - For local development
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
KAFKA_GROUP_ID=vrecom_ai_server_group
# JWT Configuration
JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
SESSION_SECRET=your-super-secret-session-key-change-in-production
# API URLs for frontend (local development)
VITE_API_SERVER_URL=http://localhost:2030
VITE_AI_SERVER_URL=http://localhost:9999
# Google OAuth - Get from Google Cloud Console
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=http://localhost:2030/api/v1/auth/google/callback
EOF
echo -e "${GREEN}[OK]${NC} Default .env created for local development"
}
create_api_env_local() {
echo -e "${YELLOW}[INFO]${NC} Creating API server .env for local development..."
cat > "backend/api_server/.env" << 'EOF'
# Environment can be set to 'dev', 'test' or 'prod'
STATUS_DEV=dev
HOST_ADDRESS=0.0.0.0
HOST_PORT=2030
HOST_READ_TIMEOUT=60
# Google OAuth2 credentials
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=http://localhost:2030/api/v1/auth/google/callback
SESSION_SECRET=your_strong_session_secret
# AI Server Configuration - Local URL
AI_SERVER_URL=http://localhost:9999
# Frontend URL for OAuth redirect
FRONTEND_URL=http://localhost:5173
HOST_IP=localhost
JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
# Redis Configuration - Local
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
EOF
echo -e "${GREEN}[OK]${NC} API server .env created"
}
create_ai_env_local() {
echo -e "${YELLOW}[INFO]${NC} Creating AI server .env for local development..."
cat > "backend/ai_server/.env" << 'EOF'
# Port server
HOST=0.0.0.0
PORT=9999
# Session Secret
SESSION_SECRET=your_strong_session_secret
JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
# Database Configuration (MySQL) - Local
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=admin
MYSQL_PASSWORD=pokiwar0981
MYSQL_DATABASE=shop
# Database Configuration (MongoDB) - Local
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_USERNAME=root
MONGODB_PASSWORD=password
# Kafka Configuration - Local
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
KAFKA_GROUP_ID=vrecom_ai_server_group
EOF
echo -e "${GREEN}[OK]${NC} AI server .env created"
}
create_frontend_env_local() {
echo -e "${YELLOW}[INFO]${NC} Creating frontend .env for local development..."
cat > "frontend/project/.env" << 'EOF'
# API Configuration - Local Development
VITE_AI_SERVER_URL=http://localhost:9999
VITE_API_SERVER_URL=http://localhost:2030
EOF
echo -e "${GREEN}[OK]${NC} Frontend .env created"
}
# ========================================
# Check Dependencies
# ========================================
check_deps() {
echo -e "${BLUE}[INFO]${NC} Checking dependencies..."
echo ""
local ALL_OK=1
# Check Go
echo "Checking Go..."
if command -v go &> /dev/null; then
GO_VERSION=$(go version | awk '{print $3}')
echo -e " ${GREEN}[OK]${NC} $GO_VERSION"
else
echo -e " ${RED}[MISSING]${NC} Go is not installed"
echo " Download from: https://golang.org/dl/"
ALL_OK=0
fi
# Check Python
echo "Checking Python..."
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version 2>&1)
echo -e " ${GREEN}[OK]${NC} $PYTHON_VERSION"
elif command -v python &> /dev/null; then
PYTHON_VERSION=$(python --version 2>&1)
echo -e " ${GREEN}[OK]${NC} $PYTHON_VERSION"
else
echo -e " ${RED}[MISSING]${NC} Python is not installed"
echo " Download from: https://python.org/downloads/"
ALL_OK=0
fi
# Check Poetry
echo "Checking Poetry..."
if command -v poetry &> /dev/null; then
POETRY_VERSION=$(poetry --version 2>&1)
echo -e " ${GREEN}[OK]${NC} $POETRY_VERSION"
else
echo -e " ${RED}[MISSING]${NC} Poetry is not installed"
echo " Install with: pip install poetry"
echo " Or visit: https://python-poetry.org/docs/"
ALL_OK=0
fi
# Check Node.js
echo "Checking Node.js..."
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version)
echo -e " ${GREEN}[OK]${NC} Node.js $NODE_VERSION"
else
echo -e " ${RED}[MISSING]${NC} Node.js is not installed"
echo " Download from: https://nodejs.org/"
ALL_OK=0
fi
# Check npm
echo "Checking npm..."
if command -v npm &> /dev/null; then
NPM_VERSION=$(npm --version)
echo -e " ${GREEN}[OK]${NC} npm $NPM_VERSION"
else
echo -e " ${RED}[MISSING]${NC} npm is not installed"
ALL_OK=0
fi
echo ""
if [ "$ALL_OK" -eq 1 ]; then
echo -e "${GREEN}[SUCCESS]${NC} All dependencies are installed!"
else
echo -e "${RED}[WARNING]${NC} Some dependencies are missing. Please install them before running the system."
fi
echo ""
return $((1 - ALL_OK))
}
# Silent dependency check
check_deps_silent() {
command -v go &> /dev/null && \
command -v poetry &> /dev/null && \
command -v node &> /dev/null
}
# ========================================
# Install All Dependencies
# ========================================
install_all() {
echo -e "${BLUE}[INFO]${NC} Installing all dependencies..."
echo ""
# Install AI Server dependencies
echo -e "${CYAN}[1/3]${NC} Installing AI Server dependencies..."
if [ -f "backend/ai_server/pyproject.toml" ]; then
cd backend/ai_server
poetry install
if [ $? -eq 0 ]; then
echo -e "${GREEN}[OK]${NC} AI Server dependencies installed"
else
echo -e "${RED}[ERROR]${NC} Failed to install AI Server dependencies"
fi
cd ../..
else
echo -e "${RED}[ERROR]${NC} pyproject.toml not found"
fi
# Install API Server dependencies
echo ""
echo -e "${CYAN}[2/3]${NC} Installing API Server dependencies..."
if [ -f "backend/api_server/go.mod" ]; then
cd backend/api_server
go mod download
go mod tidy
if [ $? -eq 0 ]; then
echo -e "${GREEN}[OK]${NC} API Server dependencies installed"
else
echo -e "${RED}[ERROR]${NC} Failed to install API Server dependencies"
fi
cd ../..
else
echo -e "${RED}[ERROR]${NC} go.mod not found"
fi
# Install Frontend dependencies
echo ""
echo -e "${CYAN}[3/3]${NC} Installing Frontend dependencies..."
if [ -f "frontend/project/package.json" ]; then
cd frontend/project
npm install
if [ $? -eq 0 ]; then
echo -e "${GREEN}[OK]${NC} Frontend dependencies installed"
else
echo -e "${RED}[ERROR]${NC} Failed to install Frontend dependencies"
fi
cd ../..
else
echo -e "${RED}[ERROR]${NC} package.json not found"
fi
echo ""
echo -e "${GREEN}[SUCCESS]${NC} Dependency installation completed!"
echo ""
}
# ========================================
# Start Services
# ========================================
start_ai() {
echo -e "${BLUE}[INFO]${NC} Starting AI Server..."
cd "$SCRIPT_DIR/backend/ai_server"
# Check if already running
if [ -f "$PID_DIR/ai_server.pid" ]; then
PID=$(cat "$PID_DIR/ai_server.pid")
if kill -0 "$PID" 2>/dev/null; then
echo -e "${YELLOW}[WARN]${NC} AI Server is already running (PID: $PID)"
return
fi
fi
poetry run server > "$SCRIPT_DIR/logs/ai_server.log" 2>&1 &
echo $! > "$PID_DIR/ai_server.pid"
echo -e "${GREEN}[OK]${NC} AI Server started (PID: $!)"
echo " URL: http://localhost:9999"
echo " Docs: http://localhost:9999/docs"
echo " Logs: $SCRIPT_DIR/logs/ai_server.log"
cd "$SCRIPT_DIR"
}
start_api() {
echo -e "${BLUE}[INFO]${NC} Starting API Server..."
cd "$SCRIPT_DIR/backend/api_server"
# Check if already running
if [ -f "$PID_DIR/api_server.pid" ]; then
PID=$(cat "$PID_DIR/api_server.pid")
if kill -0 "$PID" 2>/dev/null; then
echo -e "${YELLOW}[WARN]${NC} API Server is already running (PID: $PID)"
return
fi
fi
go run main.go > "$SCRIPT_DIR/logs/api_server.log" 2>&1 &
echo $! > "$PID_DIR/api_server.pid"
echo -e "${GREEN}[OK]${NC} API Server started (PID: $!)"
echo " URL: http://localhost:2030"
echo " Logs: $SCRIPT_DIR/logs/api_server.log"
cd "$SCRIPT_DIR"
}
start_frontend() {
echo -e "${BLUE}[INFO]${NC} Starting Frontend..."
cd "$SCRIPT_DIR/frontend/project"
# Check if already running
if [ -f "$PID_DIR/frontend.pid" ]; then
PID=$(cat "$PID_DIR/frontend.pid")
if kill -0 "$PID" 2>/dev/null; then
echo -e "${YELLOW}[WARN]${NC} Frontend is already running (PID: $PID)"
return
fi
fi
npm run dev > "$SCRIPT_DIR/logs/frontend.log" 2>&1 &
echo $! > "$PID_DIR/frontend.pid"
echo -e "${GREEN}[OK]${NC} Frontend started (PID: $!)"
echo " URL: http://localhost:5173"
echo " Logs: $SCRIPT_DIR/logs/frontend.log"
cd "$SCRIPT_DIR"
}
start_all() {
echo -e "${BLUE}[INFO]${NC} Starting all services locally (without Docker)..."
echo ""
# Check dependencies
if ! check_deps_silent; then
echo -e "${RED}[ERROR]${NC} Missing dependencies. Run './start-local.sh check' to see what's missing."
exit 1
fi
# Create logs directory
mkdir -p "$SCRIPT_DIR/logs"
echo -e "${YELLOW}[NOTE]${NC} Services will run in background. Use './start-local.sh logs' to view logs."
echo ""
# Start services
echo -e "${CYAN}[1/3]${NC} Starting AI Server (Python/FastAPI)..."
start_ai
sleep 3
echo ""
echo -e "${CYAN}[2/3]${NC} Starting API Server (Go)..."
start_api
sleep 3
echo ""
echo -e "${CYAN}[3/3]${NC} Starting Frontend (React/Vite)..."
start_frontend
echo ""
echo -e "${GREEN}========================================================${NC}"
echo -e "${GREEN} All services started successfully! ${NC}"
echo -e "${GREEN}========================================================${NC}"
echo ""
echo -e "${CYAN}Service URLs:${NC}"
echo " - Frontend: http://localhost:5173"
echo " - API Server: http://localhost:2030"
echo " - AI Server: http://localhost:9999"
echo ""
echo -e "${CYAN}Health Check URLs:${NC}"
echo " - API Server: http://localhost:2030/api/v1/ping"
echo " - AI Server: http://localhost:9999/api/v1/health"
echo " - AI Server Docs: http://localhost:9999/docs"
echo ""
echo -e "${YELLOW}[TIP]${NC} View logs: ./start-local.sh logs [ai|api|frontend]"
echo -e "${YELLOW}[TIP]${NC} Stop services: ./start-local.sh stop"
echo ""
}
# ========================================
# Stop Services
# ========================================
stop_service() {
local name=$1
local pid_file="$PID_DIR/${name}.pid"
if [ -f "$pid_file" ]; then
PID=$(cat "$pid_file")
if kill -0 "$PID" 2>/dev/null; then
kill "$PID" 2>/dev/null
# Wait a moment and force kill if necessary
sleep 1
if kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID" 2>/dev/null
fi
echo -e "${GREEN}[OK]${NC} $name stopped (was PID: $PID)"
else
echo -e "${YELLOW}[WARN]${NC} $name was not running"
fi
rm -f "$pid_file"
else
echo -e "${YELLOW}[WARN]${NC} No PID file for $name"
fi
}
stop_all() {
echo -e "${BLUE}[INFO]${NC} Stopping all services..."
echo ""
# Stop by PID files
stop_service "ai_server"
stop_service "api_server"
stop_service "frontend"
# Also try to kill by port as fallback
echo ""
echo "Cleaning up any remaining processes..."
# Kill processes on ports
for port in 9999 2030 5173; do
PID=$(lsof -ti :$port 2>/dev/null)
if [ -n "$PID" ]; then
kill $PID 2>/dev/null
echo " Killed process on port $port"
fi
done
echo ""
echo -e "${GREEN}[OK]${NC} All services stopped"
echo ""
}
# ========================================
# Restart Services
# ========================================
restart_all() {
echo -e "${BLUE}[INFO]${NC} Restarting all services..."
stop_all
sleep 2
start_all
}
# ========================================
# Check Status
# ========================================
check_status() {
echo -e "${BLUE}[INFO]${NC} Checking service status..."
echo ""
# Check AI Server
echo "AI Server (port 9999):"
if lsof -i :9999 &>/dev/null || netstat -tuln 2>/dev/null | grep -q ":9999 "; then
echo -e " ${GREEN}[RUNNING]${NC} http://localhost:9999"
else
echo -e " ${RED}[STOPPED]${NC} Not running"
fi
# Check API Server
echo "API Server (port 2030):"
if lsof -i :2030 &>/dev/null || netstat -tuln 2>/dev/null | grep -q ":2030 "; then
echo -e " ${GREEN}[RUNNING]${NC} http://localhost:2030"
else
echo -e " ${RED}[STOPPED]${NC} Not running"
fi
# Check Frontend
echo "Frontend (port 5173):"
if lsof -i :5173 &>/dev/null || netstat -tuln 2>/dev/null | grep -q ":5173 "; then
echo -e " ${GREEN}[RUNNING]${NC} http://localhost:5173"
else
echo -e " ${RED}[STOPPED]${NC} Not running"
fi
echo ""
}
# ========================================
# View Logs
# ========================================
view_logs() {
local service=$1
case "$service" in
ai|ai_server)
echo -e "${BLUE}[INFO]${NC} Showing AI Server logs (Ctrl+C to exit)..."
tail -f "$SCRIPT_DIR/logs/ai_server.log"
;;
api|api_server)
echo -e "${BLUE}[INFO]${NC} Showing API Server logs (Ctrl+C to exit)..."
tail -f "$SCRIPT_DIR/logs/api_server.log"
;;
frontend|fe)
echo -e "${BLUE}[INFO]${NC} Showing Frontend logs (Ctrl+C to exit)..."
tail -f "$SCRIPT_DIR/logs/frontend.log"
;;
all|"")
echo -e "${BLUE}[INFO]${NC} Showing all logs (Ctrl+C to exit)..."
tail -f "$SCRIPT_DIR/logs/"*.log
;;
*)
echo -e "${RED}[ERROR]${NC} Unknown service: $service"
echo "Usage: ./start-local.sh logs [ai|api|frontend|all]"
;;
esac
}
# ========================================
# Help
# ========================================
show_help() {
echo -e "${CYAN}VRecommendation System - Local Startup Script (No Docker)${NC}"
echo ""
echo "Usage: ./start-local.sh [COMMAND] [OPTIONS]"
echo ""
echo "Commands:"
echo " start, up Start all services locally (default)"
echo " stop, down Stop all running services"
echo " restart Restart all services"
echo " status Check status of all services"
echo " install Install all dependencies"
echo " check Check if all dependencies are installed"
echo " ai Start only AI Server"
echo " api Start only API Server"
echo " frontend Start only Frontend"
echo " logs [service] View logs (ai|api|frontend|all)"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " ./start-local.sh Start all services"
echo " ./start-local.sh status Check service status"
echo " ./start-local.sh stop Stop all services"
echo " ./start-local.sh install Install dependencies"
echo " ./start-local.sh ai Start only AI Server"
echo " ./start-local.sh logs ai View AI Server logs"
echo ""
echo "Requirements:"
echo " - Go 1.24+ (for API Server)"
echo " - Python 3.9+ (for AI Server)"
echo " - Poetry (for AI Server dependency management)"
echo " - Node.js 18+ (for Frontend)"
echo " - npm (for Frontend)"
echo ""
echo "Service URLs (after starting):"
echo " - Frontend: http://localhost:5173"
echo " - API Server: http://localhost:2030"
echo " - AI Server: http://localhost:9999"
echo " - AI Server Docs: http://localhost:9999/docs"
echo ""
echo -e "${YELLOW}Note:${NC} External services (Redis, MySQL, MongoDB, Kafka) must be"
echo " running separately if required by your configuration."
echo ""
}
# ========================================
# Main
# ========================================
# Setup environment files first
setup_env_files
# Parse command
COMMAND=${1:-start}
case "$COMMAND" in
start|up)
start_all
;;
stop|down)
stop_all
;;
restart)
restart_all
;;
status)
check_status
;;
install)
install_all
;;
check)
check_deps
;;
ai)
mkdir -p "$SCRIPT_DIR/logs"
start_ai
;;
api)
mkdir -p "$SCRIPT_DIR/logs"
start_api
;;
frontend|fe)
mkdir -p "$SCRIPT_DIR/logs"
start_frontend
;;
logs)
view_logs "$2"
;;
help|--help|-h)
show_help
;;
*)
echo -e "${RED}[ERROR]${NC} Unknown command: $COMMAND"
echo ""
show_help
exit 1
;;
esac