feat: Migrate to ultrathin monolith architecture
Consolidate 3 separate applications (reports-app, data-entry-app, telegram-bot) into a unified
architecture with single backend and frontend:
Backend Changes:
- Unified FastAPI backend at backend/ with modular structure
- Modules: reports, data_entry, telegram in backend/modules/
- Centralized config.py and main.py with all routers registered
- Single worker mode (--workers 1) for Telegram bot compatibility
- Shared Oracle connection pool and JWT authentication
- Unified requirements.txt and environment configuration
Frontend Changes:
- Single Vue.js SPA with module-based routing
- Unified frontend at src/ with modules in src/modules/{reports,data-entry}/
- Shared components and stores in src/shared/
- Error boundaries for module isolation
- Dual API proxy in Vite for module communication
Infrastructure:
- New unified startup scripts: start-prod.sh, start-test.sh, start-backend.sh
- Environment templates: .env.dev.example, .env.test.example, .env.prod.example
- Updated deployment scripts for Windows IIS
- Simplified SSH tunnel management
Documentation:
- Comprehensive CLAUDE.md with architecture overview
- Module-specific docs in docs/{data-entry,telegram}/
- Architecture decision records in docs/ARCHITECTURE-DECISIONS.md
- Deployment guides consolidated in deployment/windows/docs/
This migration reduces complexity, improves maintainability, and enables easier
deployment while maintaining all existing functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
300
start-test.sh
300
start-test.sh
@@ -1,10 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ROA2WEB Unified App - TEST Starter Script
|
||||
# ROA2WEB Ultrathin Monolith - TEST Starter Script
|
||||
# Starts all services for the unified application:
|
||||
# - Reports Backend (8001)
|
||||
# - Data Entry Backend (8003)
|
||||
# - Telegram Bot (8002)
|
||||
# - Unified Backend (8000) - includes Reports, Data Entry, and Telegram
|
||||
# - Unified Frontend (3000)
|
||||
|
||||
set -e # Exit on any error
|
||||
@@ -19,7 +17,7 @@ NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored messages
|
||||
print_message() {
|
||||
echo -e "${CYAN}[UNIFIED]${NC} $1"
|
||||
echo -e "${CYAN}[UNIFIED-TEST]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
@@ -48,28 +46,12 @@ check_port() {
|
||||
cleanup() {
|
||||
print_message "Stopping all services..."
|
||||
|
||||
# Stop Reports Backend (8001)
|
||||
if check_port 8001; then
|
||||
print_message "Stopping Reports Backend..."
|
||||
lsof -ti:8001 | xargs kill -TERM 2>/dev/null || true
|
||||
sleep 1
|
||||
lsof -ti:8001 | xargs kill -KILL 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Stop Data Entry Backend (8003)
|
||||
if check_port 8003; then
|
||||
print_message "Stopping Data Entry Backend..."
|
||||
lsof -ti:8003 | xargs kill -TERM 2>/dev/null || true
|
||||
sleep 1
|
||||
lsof -ti:8003 | xargs kill -KILL 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Stop Telegram Bot (8002)
|
||||
if check_port 8002; then
|
||||
print_message "Stopping Telegram Bot..."
|
||||
lsof -ti:8002 | xargs kill -TERM 2>/dev/null || true
|
||||
sleep 1
|
||||
lsof -ti:8002 | xargs kill -KILL 2>/dev/null || true
|
||||
# Stop Unified Backend (8000)
|
||||
if check_port 8000; then
|
||||
print_message "Stopping Unified Backend..."
|
||||
lsof -ti:8000 | xargs kill -TERM 2>/dev/null || true
|
||||
sleep 2
|
||||
lsof -ti:8000 | xargs kill -KILL 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Stop Unified Frontend (3000)
|
||||
@@ -98,14 +80,14 @@ fi
|
||||
# Set up signal handlers
|
||||
trap cleanup SIGINT SIGTERM
|
||||
|
||||
print_message "Starting ROA2WEB Unified App (TEST Environment)..."
|
||||
print_message "Starting ROA2WEB Ultrathin Monolith (TEST Environment)..."
|
||||
echo
|
||||
|
||||
# Step 1: Start SSH Tunnel
|
||||
print_message "1. Starting SSH Tunnel..."
|
||||
print_message "1. Starting SSH Tunnel (TEST server)..."
|
||||
if [ -f "./ssh-tunnel-test.sh" ]; then
|
||||
if ./ssh-tunnel-test.sh start; then
|
||||
print_success "SSH Tunnel started"
|
||||
print_success "SSH Tunnel started (TEST)"
|
||||
else
|
||||
print_warning "SSH tunnel may already be running or failed to start"
|
||||
fi
|
||||
@@ -115,197 +97,85 @@ fi
|
||||
|
||||
sleep 2
|
||||
|
||||
# Steps 2-4: Start backends in PARALLEL for faster startup
|
||||
print_message "2-4. Starting backends in parallel..."
|
||||
echo
|
||||
# Step 2: Start Unified Backend (8000)
|
||||
print_message "2. Starting Unified Backend on port 8000..."
|
||||
|
||||
# Start Reports Backend in background (parallel)
|
||||
(
|
||||
if check_port 8001; then
|
||||
print_warning "Port 8001 already in use - Reports Backend may be running"
|
||||
else
|
||||
print_message "[Reports] Starting backend on port 8001..."
|
||||
cd reports-app/backend/
|
||||
if check_port 8000; then
|
||||
print_warning "Port 8000 already in use - Unified Backend may be running"
|
||||
else
|
||||
cd backend/
|
||||
|
||||
# Create venv if doesn't exist
|
||||
if [ ! -d "venv" ]; then
|
||||
print_message "[Reports] Creating Python virtual environment..."
|
||||
python3 -m venv venv
|
||||
fi
|
||||
|
||||
# Activate venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Install dependencies if needed
|
||||
if ! python -c "import fastapi, uvicorn" 2>/dev/null; then
|
||||
print_message "[Reports] Installing dependencies..."
|
||||
pip install -q -r requirements.txt
|
||||
fi
|
||||
|
||||
# Load test environment
|
||||
if [ -f ".env.test" ]; then
|
||||
set -a
|
||||
source .env.test
|
||||
set +a
|
||||
fi
|
||||
|
||||
# Start backend
|
||||
nohup uvicorn app.main:app --host 0.0.0.0 --port 8001 > /tmp/reports_backend.log 2>&1 &
|
||||
|
||||
cd - > /dev/null
|
||||
# Create venv if doesn't exist
|
||||
if [ ! -d "venv" ]; then
|
||||
print_message "Creating Python virtual environment..."
|
||||
python3 -m venv venv
|
||||
fi
|
||||
) &
|
||||
REPORTS_START_PID=$!
|
||||
|
||||
# Start Data Entry Backend in background (parallel)
|
||||
(
|
||||
if check_port 8003; then
|
||||
print_warning "Port 8003 already in use - Data Entry Backend may be running"
|
||||
else
|
||||
print_message "[Data Entry] Starting backend on port 8003..."
|
||||
cd data-entry-app/backend/
|
||||
# Activate venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Create venv if doesn't exist
|
||||
if [ ! -d "venv" ]; then
|
||||
print_message "[Data Entry] Creating Python virtual environment..."
|
||||
python3 -m venv venv
|
||||
fi
|
||||
|
||||
# Activate venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Install dependencies if needed
|
||||
if ! python -c "import fastapi, uvicorn, sqlmodel" 2>/dev/null; then
|
||||
print_message "[Data Entry] Installing dependencies..."
|
||||
pip install -q -r requirements.txt
|
||||
fi
|
||||
|
||||
# Copy TEST environment
|
||||
if [ -f ".env.test" ]; then
|
||||
cp .env.test .env
|
||||
fi
|
||||
|
||||
# Load environment
|
||||
if [ -f ".env" ]; then
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
fi
|
||||
|
||||
# Start backend
|
||||
nohup uvicorn app.main:app --host 0.0.0.0 --port 8003 > /tmp/data_entry_backend.log 2>&1 &
|
||||
|
||||
cd - > /dev/null
|
||||
# Install dependencies if needed
|
||||
if ! python -c "import fastapi, uvicorn" 2>/dev/null; then
|
||||
print_message "Installing dependencies (this may take 3-5 minutes for ML packages)..."
|
||||
pip install -r requirements.txt
|
||||
fi
|
||||
) &
|
||||
DATA_ENTRY_START_PID=$!
|
||||
|
||||
# Start Telegram Bot in background (parallel)
|
||||
(
|
||||
if check_port 8002; then
|
||||
print_warning "Port 8002 already in use - Telegram Bot may be running"
|
||||
else
|
||||
cd reports-app/telegram-bot/
|
||||
|
||||
# Copy TEST environment if exists
|
||||
if [ -f ".env.test" ]; then
|
||||
cp .env.test .env
|
||||
elif [ ! -f ".env" ]; then
|
||||
print_warning "[Bot] .env not found - skipping"
|
||||
cd - > /dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -f ".env" ]; then
|
||||
print_message "[Bot] Starting Telegram bot on port 8002..."
|
||||
|
||||
# Create venv if doesn't exist
|
||||
if [ ! -d "venv" ]; then
|
||||
print_message "[Bot] Creating Python virtual environment..."
|
||||
python3 -m venv venv
|
||||
fi
|
||||
|
||||
# Activate venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Install dependencies if needed
|
||||
if ! python -c "import telegram" 2>/dev/null; then
|
||||
print_message "[Bot] Installing dependencies..."
|
||||
pip install -q -r requirements.txt
|
||||
fi
|
||||
|
||||
# Start bot
|
||||
nohup python -m app.main > /tmp/telegram_bot.log 2>&1 &
|
||||
|
||||
cd - > /dev/null
|
||||
# Check for TEST environment configuration
|
||||
if [ ! -f ".env.test" ]; then
|
||||
if [ -f ".env.test.example" ]; then
|
||||
print_error ".env.test not found!"
|
||||
print_warning "First-time setup required:"
|
||||
echo " 1. Copy template: cp backend/.env.test.example backend/.env.test"
|
||||
echo " 2. Fill in your TEST credentials in backend/.env.test"
|
||||
echo " 3. Run ./start-test.sh again"
|
||||
exit 1
|
||||
else
|
||||
print_error ".env.test and .env.test.example not found!"
|
||||
print_warning "Please check your backend/ directory structure"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
) &
|
||||
BOT_START_PID=$!
|
||||
|
||||
# Wait for all background startup processes to complete
|
||||
print_message "Waiting for backends to initialize..."
|
||||
wait $REPORTS_START_PID $DATA_ENTRY_START_PID $BOT_START_PID
|
||||
# Copy TEST environment to active .env
|
||||
print_message "Using TEST environment (.env.test)..."
|
||||
cp .env.test .env
|
||||
|
||||
# Now check if services are actually running on their ports
|
||||
echo
|
||||
print_message "Checking backend status..."
|
||||
# Load environment
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
|
||||
# Check Reports Backend (wait up to 20s)
|
||||
if ! check_port 8001; then
|
||||
print_message "Waiting for Reports Backend (Oracle pool initialization)..."
|
||||
for i in {1..20}; do
|
||||
sleep 1
|
||||
if check_port 8001; then
|
||||
# Start backend (without reload for test stability)
|
||||
print_message "Starting unified backend (includes Reports, Data Entry, and Telegram bot)..."
|
||||
nohup uvicorn main:app --host 0.0.0.0 --port 8000 > /tmp/unified_backend_test.log 2>&1 &
|
||||
|
||||
cd - > /dev/null
|
||||
|
||||
# Wait for backend to start (Oracle pool + cache + Telegram bot initialization)
|
||||
print_message "Waiting for Unified Backend to initialize (Oracle + Cache + DBs + Telegram)..."
|
||||
MAX_WAIT=40
|
||||
ELAPSED=0
|
||||
while [ $ELAPSED -lt $MAX_WAIT ]; do
|
||||
if check_port 8000; then
|
||||
print_success "Unified Backend started on http://localhost:8000"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if check_port 8001; then
|
||||
print_success "Reports Backend started on http://localhost:8001"
|
||||
else
|
||||
print_error "Reports Backend failed to start - check /tmp/reports_backend.log"
|
||||
cleanup
|
||||
fi
|
||||
|
||||
# Check Data Entry Backend (wait up to 25s for DB migrations)
|
||||
if ! check_port 8003; then
|
||||
print_message "Waiting for Data Entry Backend (database initialization)..."
|
||||
for i in {1..25}; do
|
||||
sleep 1
|
||||
if check_port 8003; then
|
||||
break
|
||||
ELAPSED=$((ELAPSED + 1))
|
||||
if [ $((ELAPSED % 5)) -eq 0 ]; then
|
||||
print_message "Still initializing... ($ELAPSED/${MAX_WAIT}s)"
|
||||
fi
|
||||
done
|
||||
|
||||
if ! check_port 8000; then
|
||||
print_error "Unified Backend failed to start - check /tmp/unified_backend_test.log"
|
||||
tail -n 30 /tmp/unified_backend_test.log
|
||||
cleanup
|
||||
fi
|
||||
fi
|
||||
|
||||
if check_port 8003; then
|
||||
print_success "Data Entry Backend started on http://localhost:8003"
|
||||
else
|
||||
print_error "Data Entry Backend failed to start - check /tmp/data_entry_backend.log"
|
||||
cleanup
|
||||
fi
|
||||
|
||||
# Check Telegram Bot
|
||||
if ! check_port 8002; then
|
||||
print_message "Waiting for Telegram Bot..."
|
||||
for i in {1..5}; do
|
||||
sleep 1
|
||||
if check_port 8002; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if check_port 8002; then
|
||||
print_success "Telegram Bot started on http://localhost:8002 (Internal API)"
|
||||
else
|
||||
print_warning "Telegram Bot may have failed - check /tmp/telegram_bot.log"
|
||||
fi
|
||||
|
||||
# Step 5: Start Unified Frontend (port 3000)
|
||||
print_message "5. Starting Unified Frontend (port 3000)..."
|
||||
# Step 3: Start Unified Frontend (port 3000)
|
||||
print_message "3. Starting Unified Frontend (port 3000)..."
|
||||
|
||||
if check_port 3000; then
|
||||
print_warning "Port 3000 already in use - Unified Frontend may be running"
|
||||
@@ -318,7 +188,7 @@ else
|
||||
|
||||
# Start frontend
|
||||
print_message "Starting Vite development server..."
|
||||
nohup npm run dev > /tmp/unified_frontend.log 2>&1 &
|
||||
nohup npm run dev > /tmp/unified_frontend_test.log 2>&1 &
|
||||
FRONTEND_PID=$!
|
||||
|
||||
# Wait for frontend to start
|
||||
@@ -326,26 +196,32 @@ else
|
||||
if check_port 3000; then
|
||||
print_success "Unified Frontend started on http://localhost:3000"
|
||||
else
|
||||
print_error "Unified Frontend failed to start - check /tmp/unified_frontend.log"
|
||||
cat /tmp/unified_frontend.log
|
||||
print_error "Unified Frontend failed to start - check /tmp/unified_frontend_test.log"
|
||||
cat /tmp/unified_frontend_test.log
|
||||
cleanup
|
||||
fi
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo
|
||||
print_success "🚀 ROA2WEB Unified App is now running!"
|
||||
print_success "🚀 ROA2WEB Ultrathin Monolith (TEST) is now running!"
|
||||
echo
|
||||
echo -e "${BLUE}Services:${NC}"
|
||||
echo " • SSH Tunnel: Active (Oracle DB connection)"
|
||||
echo " • Reports Backend: http://localhost:8001"
|
||||
echo " • Data Entry Backend: http://localhost:8003"
|
||||
echo " • Telegram Bot: http://localhost:8002 (Internal API)"
|
||||
echo " • SSH Tunnel: Active (Oracle TEST DB connection)"
|
||||
echo " • Unified Backend: http://localhost:8000"
|
||||
echo " • ├── Reports API: http://localhost:8000/api/reports/*"
|
||||
echo " • ├── Data Entry: http://localhost:8000/api/data-entry/*"
|
||||
echo " • ├── Telegram: http://localhost:8000/api/telegram/*"
|
||||
echo " • └── Bot: Running as background task"
|
||||
echo " • Unified Frontend: http://localhost:3000"
|
||||
echo
|
||||
echo -e "${BLUE}API Documentation:${NC}"
|
||||
echo " • Reports API: http://localhost:8001/docs"
|
||||
echo " • Data Entry API: http://localhost:8003/docs"
|
||||
echo " • Unified API Docs: http://localhost:8000/docs"
|
||||
echo " • Health Check: http://localhost:8000/health"
|
||||
echo
|
||||
echo -e "${BLUE}Log Files:${NC}"
|
||||
echo " • Unified Backend: /tmp/unified_backend_test.log"
|
||||
echo " • Unified Frontend: /tmp/unified_frontend_test.log"
|
||||
echo
|
||||
echo -e "${YELLOW}Press Ctrl+C to stop all services${NC}"
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user