Successfully implemented a comprehensive one-shot bootstrap script (master.sh)
that scaffolds a complete full-stack starter project with FastAPI backend,
Vite/React frontend, and PostgreSQL database.
- Lines of Code: 1,037
- Set strict mode:
set -euo pipefail - Modular architecture: Separated into clear sections
-
Configuration (Lines 6-27)
- Environment variables for all configurable options
- Defaults for PROJECT_NAME, ports, DB credentials, versions
- Support for DEFAULT_GITHUB_ORG and DEFAULT_GITHUB_VISIBILITY
-
Utilities (Lines 29-60)
warn()- Warning messageserr()- Error messages with exitask()- Interactive prompts with defaultsinfo()- Information messagessuccess()- Success messages
-
Environment Detection (Lines 62-128)
detect_python()- Detects Python 3 and versiondetect_node()- Detects Node.js and versiondetect_npm()- Detects npm and versiondetect_docker()- Detects Docker and versiondetect_docker_compose()- Detects Docker Composedetect_git()- Detects Git and versioncmd_detect()- Displays detection summary
-
Scaffold Creation (Lines 130-364)
create_directories()- Creates api, ui, .github/workflows, hookscreate_api_files()- Generates all API files:api/main.py- FastAPI with root and /health endpointsapi/requirements.txt- FastAPI, Uvicorn, python-dotenvapi/start.sh- Startup script with configurable API_PORTapi/Dockerfile- Multi-stage Docker build
create_ui_files()- Generates all UI files:ui/package.json- React, Vite dependenciesui/index.html- HTML entry pointui/src/main.jsx- React app hitting API /healthui/vite.config.mjs- Vite configurationui/Dockerfile- Multi-stage build (Node + nginx)
-
Service Setup (Lines 366-404)
setup_api()- Creates Python virtualenv, installs dependenciessetup_ui()- Runs npm install for UI dependencies
-
Docker Compose (Lines 406-480)
create_docker_compose()- Generates docker-compose.yml:- PostgreSQL service with health checks
- API service depending on DB health
- UI service depending on API
- Persistent volumes for database
- Configurable ports and environment variables
-
Git and Hooks (Lines 482-565)
setup_git()- Initializes Git repository- Creates
.gitignorewith comprehensive rules - Creates
hooks/pre-commit.shwith placeholder - Symlinks hook to
.git/hooks/pre-commit
-
GitHub Actions CI (Lines 567-628)
create_ci_workflow()- Generates.github/workflows/ci.yml:- API tests job (Python setup, dependency install)
- UI build job (Node setup, dependency install, build)
- Artifact upload for UI build
- Triggers on push/PR to main/master
-
Command Handlers (Lines 630-813)
cmd_setup()- Orchestrates full setup processcmd_run()- Starts API and UI locallycmd_docker()- Starts services with Docker Composecmd_github_push()- Interactive GitHub remote setup and pushcmd_help()- Comprehensive help message
-
Main (Lines 815-1037)
- Command routing and argument parsing
- Error handling for unknown commands
- Detection initialization for each command
project/
├── master.sh (executable)
├── api/
│ ├── main.py (FastAPI with / and /health endpoints)
│ ├── requirements.txt (fastapi, uvicorn, python-dotenv)
│ ├── start.sh (executable startup script)
│ ├── Dockerfile (Python 3.11-slim based)
│ └── venv/ (Python virtual environment)
├── ui/
│ ├── src/
│ │ └── main.jsx (React app polling /health)
│ ├── index.html
│ ├── package.json (React, Vite, @vitejs/plugin-react)
│ ├── vite.config.mjs (port 3001 configuration)
│ ├── Dockerfile (Node 18 builder + nginx)
│ └── node_modules/
├── .github/
│ └── workflows/
│ └── ci.yml (API tests + UI build)
├── hooks/
│ └── pre-commit.sh (executable, placeholder checks)
├── .git/
│ └── hooks/
│ └── pre-commit (symlink to ../../hooks/pre-commit.sh)
├── docker-compose.yml (Postgres + API + UI)
└── .gitignore
All via environment variables:
PROJECT_NAME(default: myapp)DEFAULT_GITHUB_ORG(for github-push helper)DEFAULT_GITHUB_VISIBILITY(public/private)API_PORT(default: 8000)UI_PORT(default: 3001)DB_PORT(default: 5432)DB_NAME(default: ${PROJECT_NAME}_db)DB_USER(default: postgres)DB_PASSWORD(default: postgres)PY_VERSION(default: 3.11)NODE_VERSION_HINT(default: 18)FORCE_OVERWRITE(default: 0, set to 1 to overwrite existing files)
- detect - Shows available tools and versions
- setup - Full project scaffold and setup
- run - Start API+UI locally without Docker
- docker - Start services with Docker Compose
- github-push - Interactive GitHub remote setup
- help - Comprehensive usage information
- ✅ Idempotent: Running setup multiple times is safe
- ✅ Conditional setup: Only installs deps if tools available
- ✅ Non-destructive: Doesn't overwrite existing files by default
- ✅ Executable scripts: All .sh files are marked executable
- ✅ Proper error handling: Uses
set -euo pipefail - ✅ User-friendly output: Colored emoji indicators (ℹ️ ✅
⚠️ ❌)
GET /- Returns message and statusGET /health- Returns health status for UI monitoring
- CORS middleware configured
- FastAPI automatic docs at /docs
- Configurable port via API_PORT
- Uvicorn with auto-reload in development
- React 18 with Vite
- Polls API /health every 5 seconds
- Visual status indicator (green/red)
- Displays API response in formatted JSON
- Responsive design with inline styles
- Environment variable support (VITE_API_URL)
- Base: python:3.11-slim
- Installs dependencies from requirements.txt
- Exposes configurable API_PORT
- Runs with Python directly
- Multi-stage build
- Builder: node:18-alpine
- Production: nginx:alpine
- Custom nginx config for SPA routing
- Exposes configurable UI_PORT
- PostgreSQL 15-alpine with health check
- API service depends on DB health
- UI service depends on API
- Persistent volume for PostgreSQL data
- Configurable environment variables
- Restart policies configured
- Pre-commit hook placeholder for:
- Linting
- Code formatting
- Unit tests
- Static analysis
- Triggers: push/PR to main or master branches
- API Tests Job:
- Python 3.11 setup
- Pip caching
- Dependency installation
- Placeholder for pytest tests
- UI Build Job:
- Node 18 setup
- npm caching
- Dependency installation (npm ci)
- Production build
- Artifact upload
✅ Help command displays correctly ✅ Detect command shows all tools ✅ Setup creates all required files ✅ Idempotent setup (safe to re-run) ✅ Custom configuration works (PROJECT_NAME, ports) ✅ Generated files have correct content ✅ Scripts are executable ✅ Git hooks are properly symlinked ✅ Invalid commands show helpful error ✅ Shell syntax is valid (bash -n)
✅ master.sh with set -euo pipefail ✅ Configuration section with all env vars ✅ Utility functions (warn, err, ask) ✅ Environment detection (Python, Node, Docker, Git) ✅ Scaffold creation for api and ui directories ✅ FastAPI main.py with root and /health endpoints ✅ requirements.txt with fastapi and uvicorn ✅ start.sh with configurable API_PORT ✅ API Dockerfile ✅ Python virtualenv creation and dependency install ✅ Minimal Vite/React scaffold ✅ UI package.json, index.html, main.jsx, vite.config.mjs ✅ UI Dockerfile (multi-stage with nginx) ✅ docker-compose.yml with Postgres, API, UI ✅ Environment variables and volumes configured ✅ Service dependencies (db → api → ui) ✅ Git initialization ✅ .gitignore creation ✅ hooks/pre-commit.sh with placeholder ✅ Symlink to .git/hooks/pre-commit ✅ .github/workflows/ci.yml with Python and Node setup ✅ All commands: detect, setup, run, docker, github-push, help ✅ Scripts marked executable ✅ Idempotent file generation
Created comprehensive documentation (MASTER_SH_GUIDE.md, 412 lines):
- Features overview
- Quick start guide
- Generated structure explanation
- All commands with examples
- Configuration options table
- API and UI implementation details
- Docker services documentation
- GitHub Actions CI explanation
- Pre-commit hook information
- Troubleshooting section
- Best practices
- Production deployment guidance
- ✅ Code review: No issues found
- ✅ Security scan: CodeQL - No issues (bash not analyzed)
- ✅ Shell syntax validation: Passed (bash -n)
- ✅ Proper error handling throughout
- ✅ Clear variable naming
- ✅ Comprehensive comments
- ✅ Modular function design
-
master.sh (created, 1,037 lines)
- Complete bootstrap script implementation
- All required functionality
-
.gitignore (updated)
- Added Python artifacts: venv/, pycache/, _.pyc, _.egg-info/
-
MASTER_SH_GUIDE.md (created, 412 lines)
- Comprehensive user documentation
- Examples and troubleshooting
The implementation is complete and fully functional. All requirements from the problem statement have been met:
- ✅ One-shot bootstrap script with all required sections
- ✅ Complete project structure generation (api, ui, .github, hooks)
- ✅ FastAPI backend with endpoints and Dockerfile
- ✅ Vite/React UI with health check polling and Dockerfile
- ✅ Docker Compose with Postgres, API, and UI services
- ✅ Git integration with hooks and GitHub Actions CI
- ✅ All commands implemented and tested
- ✅ Configuration via environment variables
- ✅ Logging utilities with proper formatting
- ✅ Idempotent and safe operation
- ✅ Comprehensive documentation
The script provides a turnkey full-stack starter with automated detection, scaffolding, development run modes (local and Docker), git hooks, and CI/CD ready workflows.