Consolidate Reports and Data Entry apps into a single Vue.js SPA with: Architecture: - Module-based structure with lazy-loaded routes (@reports, @data-entry) - Error boundaries per module to prevent cascade failures - Dual API proxy in Vite for microservices (reports:8001, data-entry:8003) - Pinia store factories for shared auth, company, and period stores - Vite path aliases for clear module boundaries (@shared, @reports, @data-entry) Service Management: - Granular service control scripts (backend-reports.sh, backend-data-entry.sh, bot.sh, frontend.sh) - 87% faster frontend restart: 7s vs 53s full restart - 38% faster full startup: 33s vs 53s via parallel backend initialization - Enhanced start-dev.sh with proper service timeouts (OCR: 30s, Vite: 15s, Bot: 10s) - status.sh for comprehensive health checks Features: - Auto-select first company on login with period auto-load - Hamburger menu with feature toggle support - JWT token auto-injection via axios interceptors - Unified header with company/period selectors - IIS web.config for production deployment with multi-API routing UX Improvements: - Vue watchers for reactive company/period loading - Lazy store initialization with graceful error handling - Period persistence per user+company in localStorage - Feature flags for optional modules Deployment: - Single IIS site serves unified frontend with API proxy rules - Maintains separate backend processes for microservices - Windows line ending fixes (.env CRLF → LF conversion) Stats: 112 files changed, 38,342 insertions(+), 2,342 deletions(-) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
169 lines
4.4 KiB
Bash
169 lines
4.4 KiB
Bash
#!/bin/bash
|
|
# Backend Data Entry Service Control Script for ROA2WEB Unified App
|
|
# Manages the FastAPI Data Entry backend on port 8003
|
|
|
|
# Script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ROOT_DIR="$SCRIPT_DIR"
|
|
|
|
# Source helper functions
|
|
source "$SCRIPT_DIR/scripts/service-helpers.sh"
|
|
|
|
# Service configuration
|
|
SERVICE_NAME="Data Entry Backend"
|
|
PORT=8003
|
|
LOG_FILE="/tmp/data-entry-backend.log"
|
|
BACKEND_DIR="$ROOT_DIR/data-entry-app/backend"
|
|
VENV_DIR="$BACKEND_DIR/venv"
|
|
ENV_FILE="$BACKEND_DIR/.env"
|
|
|
|
# Function to start backend
|
|
start_backend() {
|
|
print_header "Starting $SERVICE_NAME"
|
|
|
|
# Check if port is already in use
|
|
if ! check_port_available $PORT "$SERVICE_NAME"; then
|
|
print_warning "$SERVICE_NAME may already be running"
|
|
print_info "Use './backend-data-entry.sh status' to check or './backend-data-entry.sh stop' to stop it"
|
|
return 1
|
|
fi
|
|
|
|
# Check backend directory
|
|
if [ ! -d "$BACKEND_DIR" ]; then
|
|
print_error "Backend directory not found: $BACKEND_DIR"
|
|
return 1
|
|
fi
|
|
|
|
# Check virtual environment
|
|
if [ ! -d "$VENV_DIR" ]; then
|
|
print_error "Virtual environment not found: $VENV_DIR"
|
|
print_info "Please run setup first: cd data-entry-app/backend && python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
|
|
return 1
|
|
fi
|
|
|
|
# Check .env file
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
print_warning ".env file not found: $ENV_FILE"
|
|
print_info "Database connection may fail"
|
|
fi
|
|
|
|
# Start backend
|
|
print_info "Starting FastAPI server..."
|
|
cd "$BACKEND_DIR"
|
|
|
|
# Activate venv and start uvicorn in background
|
|
(
|
|
source venv/bin/activate
|
|
nohup uvicorn app.main:app --host 0.0.0.0 --port $PORT > "$LOG_FILE" 2>&1 &
|
|
echo $! > /tmp/data-entry-backend.pid
|
|
)
|
|
|
|
local pid=$(cat /tmp/data-entry-backend.pid 2>/dev/null)
|
|
print_info "Started with PID: $pid"
|
|
print_info "Log file: $LOG_FILE"
|
|
|
|
# Wait for port to be ready (Data Entry takes longer due to SQLite migrations)
|
|
if wait_for_port $PORT "$SERVICE_NAME" 35; then
|
|
# Check health endpoint
|
|
print_info "Checking health endpoint..."
|
|
sleep 2
|
|
local health_status=$(curl -s http://localhost:$PORT/health 2>&1 | head -1)
|
|
|
|
if echo "$health_status" | grep -q "ok"; then
|
|
print_success "$SERVICE_NAME started successfully and is healthy!"
|
|
else
|
|
print_success "$SERVICE_NAME started (health check inconclusive)"
|
|
fi
|
|
|
|
echo ""
|
|
print_info "🌐 API URLs:"
|
|
echo " • API Docs: http://localhost:$PORT/docs"
|
|
echo " • Health: http://localhost:$PORT/health"
|
|
echo ""
|
|
print_info "📄 View logs: tail -f $LOG_FILE"
|
|
return 0
|
|
else
|
|
print_error "Failed to start $SERVICE_NAME (timeout waiting for port $PORT)"
|
|
print_info "Check logs: tail -20 $LOG_FILE"
|
|
rm -f /tmp/data-entry-backend.pid
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Function to stop backend
|
|
stop_backend() {
|
|
print_header "Stopping $SERVICE_NAME"
|
|
|
|
kill_port $PORT "$SERVICE_NAME"
|
|
|
|
# Clean up PID file
|
|
if [ -f "/tmp/data-entry-backend.pid" ]; then
|
|
rm /tmp/data-entry-backend.pid
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
# Function to show backend status
|
|
status_backend() {
|
|
print_header "$SERVICE_NAME Status"
|
|
|
|
if check_service_status $PORT "$SERVICE_NAME"; then
|
|
echo ""
|
|
|
|
# Check health endpoint
|
|
print_info "Health check:"
|
|
local health=$(curl -s http://localhost:$PORT/health 2>&1)
|
|
if echo "$health" | grep -q "ok"; then
|
|
print_success "Health endpoint: OK"
|
|
else
|
|
print_warning "Health endpoint: Not responding"
|
|
fi
|
|
|
|
# Show recent logs
|
|
if [ -f "$LOG_FILE" ]; then
|
|
echo ""
|
|
tail_logs "$LOG_FILE" 10
|
|
fi
|
|
return 0
|
|
else
|
|
echo ""
|
|
print_warning "Service is not running"
|
|
|
|
# Show last logs if available
|
|
if [ -f "$LOG_FILE" ]; then
|
|
echo ""
|
|
print_info "Last logs before shutdown:"
|
|
tail_logs "$LOG_FILE" 10
|
|
fi
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Main script logic
|
|
case "${1:-}" in
|
|
start)
|
|
start_backend
|
|
;;
|
|
stop)
|
|
stop_backend
|
|
;;
|
|
status)
|
|
status_backend
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|status}"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " start - Start the Data Entry backend API server"
|
|
echo " stop - Stop the Data Entry backend API server"
|
|
echo " status - Show backend status and health check"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " ./backend-data-entry.sh start # Start backend"
|
|
echo " ./backend-data-entry.sh status # Check if running"
|
|
echo " ./backend-data-entry.sh stop # Stop backend"
|
|
exit 1
|
|
;;
|
|
esac
|