This commit is contained in:
Shubhankar45
2026-11-13 12:14:55 +00:00
commit 53dbfa976b
191 changed files with 12074 additions and 0 deletions
Executable
+72
View File
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Local development helper (DB + API + website). Usage: scripts/dev.sh {start|stop|status|logs|test|migrate}
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BACKEND="$ROOT/backend"
FRONTEND="$ROOT/frontend"
PIDFILE="$BACKEND/.uvicorn.pid"
LOGFILE="$BACKEND/uvicorn.log"
WEB_PIDFILE="$FRONTEND/.vite.pid"
WEB_LOGFILE="$FRONTEND/vite.log"
API_PORT="${API_PORT:-8020}"
db_up() {
(cd "$ROOT" && docker compose up -d db >/dev/null)
for _ in $(seq 1 30); do
[ "$(docker inspect -f '{{.State.Health.Status}}' saurashakti-website-dev-db 2>/dev/null)" = "healthy" ] && return 0
sleep 1
done
echo "Database did not become healthy" >&2; return 1
}
api_running() { [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; }
web_running() { [ -f "$WEB_PIDFILE" ] && kill -0 "$(cat "$WEB_PIDFILE")" 2>/dev/null; }
start_web() {
if web_running; then echo "Website : already running (pid $(cat "$WEB_PIDFILE"))"; return; fi
[ -d "$FRONTEND/node_modules" ] || (cd "$FRONTEND" && npm install)
cd "$FRONTEND"
nohup node_modules/.bin/vite >"$WEB_LOGFILE" 2>&1 &
echo $! >"$WEB_PIDFILE"
cd "$ROOT"
sleep 2
web_running && echo "Website : http://localhost:5173 (admin: http://localhost:5173/admin)"
}
case "${1:-}" in
start)
db_up && echo "PostgreSQL : 127.0.0.1:5440 (container saurashakti-website-dev-db)"
(cd "$BACKEND" && .venv/bin/alembic upgrade head)
if api_running; then echo "API : already running (pid $(cat "$PIDFILE"))"; start_web; exit 0; fi
cd "$BACKEND"
nohup .venv/bin/uvicorn app.main:app --host 127.0.0.1 --port "$API_PORT" --reload >"$LOGFILE" 2>&1 &
echo $! >"$PIDFILE"
cd "$ROOT"
sleep 2
api_running && echo "API : http://localhost:$API_PORT (docs: /docs, log: backend/uvicorn.log)"
start_web
;;
stop)
if web_running; then kill "$(cat "$WEB_PIDFILE")" && echo "Website stopped"; fi
rm -f "$WEB_PIDFILE"
if api_running; then
pid="$(cat "$PIDFILE")"
pkill -TERM -P "$pid" 2>/dev/null || true # reload worker
kill "$pid" && echo "API stopped"
else
echo "API not running"
fi
rm -f "$PIDFILE"
(cd "$ROOT" && docker compose stop db >/dev/null) && echo "PostgreSQL stopped (data kept)"
;;
status)
api_running && echo "API : running (pid $(cat "$PIDFILE"))" || echo "API : stopped"
web_running && echo "Website: running (pid $(cat "$WEB_PIDFILE"))" || echo "Website: stopped"
echo "DB : $(docker inspect -f '{{.State.Status}}/{{.State.Health.Status}}' saurashakti-website-dev-db 2>/dev/null || echo missing)"
;;
logs) tail -f "$LOGFILE" "$WEB_LOGFILE" ;;
test) db_up && (cd "$BACKEND" && .venv/bin/python -m pytest "${@:2}") ;;
migrate) db_up && (cd "$BACKEND" && .venv/bin/alembic upgrade head) ;;
*) echo "Usage: $0 {start|stop|status|logs|test|migrate}"; exit 1 ;;
esac