Files
silo/Makefile
Zoe Forbes 78ae2c9783 feat(web): scaffold React + Vite + TypeScript frontend
Phase 1 of frontend migration (epic #6, issue #7).

Project setup (web/):
- React 19, React Router 7, Vite 6, TypeScript 5.7
- Catppuccin Mocha theme CSS variables matching existing Go templates
- Vite dev proxy to Go backend at :8080 for /api/*, /login, /logout,
  /auth/*, /health, /ready

Shared infrastructure:
- api/client.ts: typed fetch wrapper (get/post/put/del) with 401
  redirect and credentials:include for session cookies
- api/types.ts: TypeScript interfaces for all API response types
  (User, Item, Project, Schema, Revision, BOMEntry, Audit, Error)
- context/AuthContext.tsx: AuthProvider calling GET /api/auth/me
- hooks/useAuth.ts: useAuth() hook exposing user/loading/logout

UI shell:
- AppShell.tsx: header nav matching current Go template navbar
  (Items, Projects, Schemas, Audit, Settings) with role badges
  (admin=mauve, editor=blue, viewer=teal) and active tab highlighting
- LoginPage: redirects to Go-served /login during transition
- Placeholder pages: Items, Projects, Schemas fetch from API and
  display data in tables; Audit shows summary stats; Settings shows
  current user profile

Go server changes:
- routes.go: serve web/dist/ at /app/* with SPA index.html fallback
  (only activates when web/dist/ directory exists)
- .gitignore: web/node_modules/, web/dist/
- Makefile: web-install, web-dev, web-build targets
2026-02-06 16:19:52 -06:00

184 lines
5.0 KiB
Makefile

.PHONY: build run test clean migrate fmt lint \
docker-build docker-up docker-down docker-logs docker-ps \
docker-clean docker-rebuild \
web-install web-dev web-build
# =============================================================================
# Local Development
# =============================================================================
# Build all binaries
build:
go build -o silo ./cmd/silo
go build -o silod ./cmd/silod
# Run the API server locally
run:
go run ./cmd/silod -config config.yaml
# Run the CLI
cli:
go run ./cmd/silo $(ARGS)
# Run tests
test:
go test -v ./...
# Clean build artifacts
clean:
rm -f silo silod
rm -f *.out
# Format code
fmt:
go fmt ./...
goimports -w .
# Lint code
lint:
golangci-lint run
# Tidy dependencies
tidy:
go mod tidy
# =============================================================================
# Database
# =============================================================================
# Run database migrations (requires SILO_DB_* environment variables)
migrate:
./scripts/init-db.sh
# Connect to database (requires psql)
db-shell:
PGPASSWORD=$${SILO_DB_PASSWORD:-silodev} psql -h $${SILO_DB_HOST:-localhost} -U $${SILO_DB_USER:-silo} -d $${SILO_DB_NAME:-silo}
# =============================================================================
# Docker
# =============================================================================
# Build Docker image
docker-build:
docker build -t silo:latest -f build/package/Dockerfile .
# Start the full stack (postgres + minio + silo)
docker-up:
docker compose -f deployments/docker-compose.yaml up -d
# Start with rebuild
docker-up-build:
docker compose -f deployments/docker-compose.yaml up -d --build
# Stop the stack
docker-down:
docker compose -f deployments/docker-compose.yaml down
# Stop and remove volumes (WARNING: deletes data)
docker-clean:
docker compose -f deployments/docker-compose.yaml down -v
# View logs
docker-logs:
docker compose -f deployments/docker-compose.yaml logs -f
# View logs for specific service
docker-logs-silo:
docker compose -f deployments/docker-compose.yaml logs -f silo
docker-logs-postgres:
docker compose -f deployments/docker-compose.yaml logs -f postgres
docker-logs-minio:
docker compose -f deployments/docker-compose.yaml logs -f minio
# Show running containers
docker-ps:
docker compose -f deployments/docker-compose.yaml ps
# Rebuild and restart
docker-rebuild: docker-down docker-build docker-up
# Shell into silo container
docker-shell:
docker compose -f deployments/docker-compose.yaml exec silo /bin/sh
# =============================================================================
# API Testing
# =============================================================================
# Test health endpoint
api-health:
curl -s http://localhost:8080/health | jq .
# Test ready endpoint
api-ready:
curl -s http://localhost:8080/ready | jq .
# List schemas
api-schemas:
curl -s http://localhost:8080/api/schemas | jq .
# List items
api-items:
curl -s http://localhost:8080/api/items | jq .
# Create sample item
api-create-item:
curl -s -X POST http://localhost:8080/api/items \
-H "Content-Type: application/json" \
-d '{"schema":"kindred-rd","project":"CS100","category":"F01","material":"316","description":"Test screw"}' | jq .
# =============================================================================
# Web Frontend
# =============================================================================
web-install:
cd web && npm ci
web-dev:
cd web && npm run dev
web-build:
cd web && npm run build
# =============================================================================
# Help
# =============================================================================
help:
@echo "Silo Makefile targets:"
@echo ""
@echo "Local Development:"
@echo " build - Build CLI and server binaries"
@echo " run - Run API server locally"
@echo " cli ARGS=... - Run CLI with arguments"
@echo " test - Run tests"
@echo " fmt - Format code"
@echo " lint - Run linter"
@echo " tidy - Tidy go.mod"
@echo ""
@echo "Docker:"
@echo " docker-build - Build Docker image"
@echo " docker-up - Start full stack (postgres + minio + silo)"
@echo " docker-down - Stop the stack"
@echo " docker-clean - Stop and remove volumes (deletes data)"
@echo " docker-logs - View all logs"
@echo " docker-ps - Show running containers"
@echo " docker-rebuild - Rebuild and restart"
@echo ""
@echo "Database:"
@echo " migrate - Run database migrations"
@echo " db-shell - Connect to database with psql"
@echo ""
@echo "API Testing:"
@echo " api-health - Test health endpoint"
@echo " api-schemas - List schemas"
@echo " api-items - List items"
@echo " api-create-item - Create a test item"
@echo ""
@echo "Web Frontend:"
@echo " web-install - Install npm dependencies"
@echo " web-dev - Start Vite dev server"
@echo " web-build - Build production bundle"