refactor: implement unified binary architecture
🏗️ **Major Architecture Refactoring: Separate CLI + Server → Unified Binary** **Key Changes:** ✅ **Unified Binary**: Single 'insertr' binary with subcommands (enhance, serve) ✅ **Preserved Database Architecture**: Maintained sophisticated sqlc multi-DB setup ✅ **Smart Configuration**: Viper + YAML config with CLI flag precedence ✅ **Updated Build System**: Unified justfile, Air, and npm scripts **Command Structure:** - `insertr enhance [input-dir]` - Build-time content injection - `insertr serve` - HTTP API server (dev + production modes) - `insertr --config insertr.yaml` - YAML configuration support **Architecture Benefits:** - **Shared Database Layer**: Single source of truth for content models - **Flexible Workflows**: Local DB for dev, remote API for production - **Simple Deployment**: One binary for all use cases - **Better UX**: Consistent configuration across build and runtime **Preserved Features:** - Multi-database support (SQLite + PostgreSQL) - sqlc code generation and type safety - Version control system with rollback - Professional API endpoints - Content enhancement pipeline **Development Workflow:** - `just dev` - Full-stack development (API server + demo site) - `just serve` - API server only - `just enhance` - Build-time content injection - `air` - Hot reload unified binary **Migration:** Consolidated insertr-cli/ and insertr-server/ → unified root structure
This commit is contained in:
94
justfile
94
justfile
@@ -11,7 +11,7 @@ install:
|
||||
cd lib && npm install
|
||||
|
||||
# Start full-stack development (primary workflow)
|
||||
dev: build-lib server-build
|
||||
dev: build-lib build
|
||||
#!/usr/bin/env bash
|
||||
echo "🚀 Starting Full-Stack Insertr Development..."
|
||||
echo "================================================"
|
||||
@@ -34,9 +34,8 @@ dev: build-lib server-build
|
||||
|
||||
# Start API server with prefixed output
|
||||
echo "🔌 Starting API server (localhost:8080)..."
|
||||
cd insertr-server && ./insertr-server --port 8080 2>&1 | sed 's/^/🔌 [SERVER] /' &
|
||||
./insertr serve --dev-mode --db ./dev.db 2>&1 | sed 's/^/🔌 [SERVER] /' &
|
||||
SERVER_PID=$!
|
||||
cd ..
|
||||
|
||||
# Wait for server startup
|
||||
echo "⏳ Waiting for API server startup..."
|
||||
@@ -68,10 +67,10 @@ demo-only:
|
||||
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html
|
||||
|
||||
# Start development server for about page
|
||||
dev-about: build-lib server-build
|
||||
dev-about: build-lib build
|
||||
#!/usr/bin/env bash
|
||||
echo "🚀 Starting full-stack development (about page)..."
|
||||
cd insertr-server && ./insertr-server --port 8080 &
|
||||
./insertr serve --dev-mode --db ./dev.db &
|
||||
SERVER_PID=$!
|
||||
sleep 3
|
||||
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/about.html
|
||||
@@ -79,13 +78,13 @@ dev-about: build-lib server-build
|
||||
|
||||
# Check project status and validate setup
|
||||
check:
|
||||
npm run dev:check
|
||||
npm run check
|
||||
|
||||
# Show demo instructions
|
||||
demo:
|
||||
npm run dev:demo
|
||||
npm run demo
|
||||
|
||||
# Build the entire project (library + CLI)
|
||||
# Build the entire project (library + unified binary)
|
||||
build:
|
||||
npm run build
|
||||
|
||||
@@ -97,67 +96,61 @@ build-lib:
|
||||
watch:
|
||||
cd lib && npm run dev
|
||||
|
||||
# Start Air hot-reload for Go CLI development
|
||||
# Start Air hot-reload for unified binary development
|
||||
air:
|
||||
cd insertr-cli && air
|
||||
air
|
||||
|
||||
# Build Go CLI only
|
||||
build-cli:
|
||||
cd insertr-cli && go build -o insertr
|
||||
# Build unified binary only
|
||||
build-insertr:
|
||||
go build -o insertr .
|
||||
|
||||
# Run CLI help
|
||||
cli-help:
|
||||
cd insertr-cli && go run main.go --help
|
||||
# Run insertr help
|
||||
help:
|
||||
./insertr --help
|
||||
|
||||
# Parse demo site with CLI
|
||||
parse:
|
||||
cd insertr-cli && go run main.go parse ../demo-site/
|
||||
./insertr enhance demo-site/ --output ./dist --mock
|
||||
|
||||
# Start CLI development server
|
||||
servedev:
|
||||
cd insertr-cli && go run main.go servedev -i ../demo-site -p 3000
|
||||
# Enhance demo site (build-time content injection)
|
||||
enhance input="demo-site" output="dist":
|
||||
./insertr enhance {{input}} --output {{output}} --mock
|
||||
|
||||
# === Content API Server Commands ===
|
||||
|
||||
# Generate Go code from SQL (using sqlc)
|
||||
server-generate:
|
||||
cd insertr-server && sqlc generate
|
||||
|
||||
# Build the content API server binary
|
||||
server-build:
|
||||
cd insertr-server && go build -o insertr-server ./cmd/server
|
||||
|
||||
# Start content API server (default port 8080)
|
||||
server port="8080":
|
||||
cd insertr-server && ./insertr-server --port {{port}}
|
||||
serve port="8080":
|
||||
./insertr serve --port {{port}} --dev-mode --db ./dev.db
|
||||
|
||||
# Start API server in production mode
|
||||
serve-prod port="8080" db="./insertr.db":
|
||||
./insertr serve --port {{port}} --db {{db}}
|
||||
|
||||
# Start API server with auto-restart on Go file changes
|
||||
server-dev port="8080":
|
||||
cd insertr-server && find . -name "*.go" | entr -r go run ./cmd/server --port {{port}}
|
||||
serve-dev port="8080":
|
||||
find . -name "*.go" | entr -r ./insertr serve --port {{port}} --dev-mode --db ./dev.db
|
||||
|
||||
# Check API server health
|
||||
server-health port="8080":
|
||||
health port="8080":
|
||||
@echo "🔍 Checking API server health..."
|
||||
@curl -s http://localhost:{{port}}/health | jq . || echo "❌ Server not responding at localhost:{{port}}"
|
||||
|
||||
# Clean database (development only - removes all content!)
|
||||
server-clean-db:
|
||||
@echo "🗑️ Removing development database..."
|
||||
rm -f insertr-server/insertr.db
|
||||
@echo "✅ Database cleaned (will be recreated on next server start)"
|
||||
|
||||
# Clean all build artifacts
|
||||
clean:
|
||||
rm -rf lib/dist
|
||||
rm -rf insertr-cli/insertr
|
||||
rm -rf insertr
|
||||
rm -rf tmp
|
||||
rm -rf dist
|
||||
rm -rf node_modules
|
||||
rm -rf lib/node_modules
|
||||
rm -f dev.db
|
||||
rm -f insertr.db
|
||||
|
||||
# Lint code (placeholder for now)
|
||||
lint:
|
||||
npm run lint
|
||||
|
||||
# Run tests (placeholder for now)
|
||||
# Run tests (placeholder for now)
|
||||
test:
|
||||
npm run test
|
||||
|
||||
@@ -167,26 +160,27 @@ dev-setup: install build-lib dev
|
||||
# Production workflow: install deps, build everything
|
||||
prod-build: install build
|
||||
|
||||
|
||||
|
||||
# Show project status
|
||||
status:
|
||||
@echo "🏗️ Insertr Project Status"
|
||||
@echo "========================="
|
||||
@echo "📁 Root files:"
|
||||
@ls -la package.json justfile 2>/dev/null || echo " Missing files"
|
||||
@ls -la package.json justfile go.mod insertr.yaml 2>/dev/null || echo " Missing files"
|
||||
@echo "\n📚 Library files:"
|
||||
@ls -la lib/package.json lib/src lib/dist 2>/dev/null || echo " Missing library components"
|
||||
@echo "\n🔧 CLI files:"
|
||||
@ls -la insertr-cli/main.go insertr-cli/insertr 2>/dev/null || echo " Missing CLI components"
|
||||
@echo "\n🔌 Server files:"
|
||||
@ls -la insertr-server/cmd insertr-server/insertr-server 2>/dev/null || echo " Missing server components"
|
||||
@echo "\n🔧 Unified binary:"
|
||||
@ls -la insertr main.go cmd/ internal/ 2>/dev/null || echo " Missing unified binary components"
|
||||
@echo "\n🌐 Demo site:"
|
||||
@ls -la demo-site/index.html demo-site/about.html 2>/dev/null || echo " Missing demo files"
|
||||
@echo ""
|
||||
@echo "🚀 Development Commands:"
|
||||
@echo " just dev - Full-stack development (recommended)"
|
||||
@echo " just demo-only - Demo site only (no persistence)"
|
||||
@echo " just server - API server only (localhost:8080)"
|
||||
@echo " just serve - API server only (localhost:8080)"
|
||||
@echo " just enhance - Build-time content injection"
|
||||
@echo ""
|
||||
@echo "🔍 Check server: just server-health"
|
||||
@echo "🔍 Check server: just health"
|
||||
|
||||
# Generate sqlc code (for database schema changes)
|
||||
sqlc:
|
||||
sqlc generate
|
||||
Reference in New Issue
Block a user