A community based topic aggregation platform built on atproto
1.PHONY: help dev-up dev-down dev-logs dev-status dev-reset test e2e-test clean verify-stack create-test-account mobile-full-setup
2
3# Default target - show help
4.DEFAULT_GOAL := help
5
6# Colors for output
7CYAN := \033[36m
8RESET := \033[0m
9GREEN := \033[32m
10YELLOW := \033[33m
11
12# Load test database configuration from .env.dev
13include .env.dev
14export
15
16##@ General
17
18help: ## Show this help message
19 @echo ""
20 @echo "$(CYAN)Coves Development Commands$(RESET)"
21 @echo ""
22 @awk 'BEGIN {FS = ":.*##"; printf "Usage: make $(CYAN)<target>$(RESET)\n"} \
23 /^[a-zA-Z_-]+:.*?##/ { printf " $(CYAN)%-15s$(RESET) %s\n", $$1, $$2 } \
24 /^##@/ { printf "\n$(YELLOW)%s$(RESET)\n", substr($$0, 5) }' $(MAKEFILE_LIST)
25 @echo ""
26
27##@ Local Development (All-in-One)
28
29dev-up: ## Start PDS + PostgreSQL + Jetstream + PLC Directory for local development
30 @echo "$(GREEN)Starting Coves development stack...$(RESET)"
31 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile jetstream --profile plc up -d postgres postgres-plc plc-directory pds jetstream
32 @echo ""
33 @echo "$(GREEN)✓ Development stack started!$(RESET)"
34 @echo ""
35 @echo "Services available at:"
36 @echo " - PostgreSQL: localhost:5435"
37 @echo " - PDS (XRPC): http://localhost:3001"
38 @echo " - PDS Firehose: ws://localhost:3001/xrpc/com.atproto.sync.subscribeRepos"
39 @echo " - Jetstream: ws://localhost:6008/subscribe $(CYAN)(Read-Forward)$(RESET)"
40 @echo " - Jetstream Metrics: http://localhost:6009/metrics"
41 @echo " - PLC Directory: http://localhost:3002 $(CYAN)(Local DID registry)$(RESET)"
42 @echo ""
43 @echo "$(CYAN)Next steps:$(RESET)"
44 @echo " 1. Run: make run (starts AppView)"
45 @echo " 2. AppView will auto-index users from Jetstream"
46 @echo ""
47 @echo "$(CYAN)Note:$(RESET) Using local PLC directory - DIDs registered locally (won't pollute plc.directory)"
48 @echo "Run 'make dev-logs' to view logs"
49
50dev-down: ## Stop all development services
51 @echo "$(YELLOW)Stopping Coves development stack...$(RESET)"
52 @docker-compose -f docker-compose.dev.yml --env-file .env.dev down
53 @echo "$(GREEN)✓ Development stack stopped$(RESET)"
54
55dev-logs: ## Tail logs from all development services
56 @docker-compose -f docker-compose.dev.yml --env-file .env.dev logs -f
57
58dev-status: ## Show status of all development containers
59 @echo "$(CYAN)Development Stack Status:$(RESET)"
60 @docker-compose -f docker-compose.dev.yml --env-file .env.dev ps
61
62dev-reset: ## Nuclear option - stop everything and remove all volumes
63 @echo "$(YELLOW)⚠️ WARNING: This will delete ALL data (PostgreSQL + PDS)!$(RESET)"
64 @read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || exit 1
65 @echo "$(YELLOW)Stopping and removing containers and volumes...$(RESET)"
66 @docker-compose -f docker-compose.dev.yml --env-file .env.dev down -v
67 @echo "$(GREEN)✓ Reset complete - all data removed$(RESET)"
68 @echo "Run 'make dev-up' to start fresh"
69
70##@ Database Management
71
72db-shell: ## Open PostgreSQL shell for development database
73 @echo "$(CYAN)Connecting to development database...$(RESET)"
74 @docker exec -it coves-dev-postgres psql -U dev_user -d coves_dev
75
76db-migrate: ## Run database migrations
77 @echo "$(GREEN)Running database migrations...$(RESET)"
78 @goose -dir internal/db/migrations postgres "postgresql://dev_user:dev_password@localhost:5433/coves_dev?sslmode=disable" up
79 @echo "$(GREEN)✓ Migrations complete$(RESET)"
80
81db-migrate-down: ## Rollback last migration
82 @echo "$(YELLOW)Rolling back last migration...$(RESET)"
83 @goose -dir internal/db/migrations postgres "postgresql://dev_user:dev_password@localhost:5433/coves_dev?sslmode=disable" down
84 @echo "$(GREEN)✓ Rollback complete$(RESET)"
85
86db-reset: ## Reset database (delete all data and re-run migrations)
87 @echo "$(YELLOW)⚠️ WARNING: This will delete all database data!$(RESET)"
88 @read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || exit 1
89 @echo "$(YELLOW)Resetting database...$(RESET)"
90 @docker-compose -f docker-compose.dev.yml --env-file .env.dev rm -sf postgres
91 @docker volume rm coves-dev-postgres-data || true
92 @docker-compose -f docker-compose.dev.yml --env-file .env.dev up -d postgres
93 @echo "Waiting for PostgreSQL to be ready..."
94 @sleep 3
95 @make db-migrate
96 @echo "$(GREEN)✓ Database reset complete$(RESET)"
97
98##@ Testing
99
100test: ## Run fast unit/integration tests (skips slow E2E tests)
101 @echo "$(GREEN)Starting test database...$(RESET)"
102 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test up -d postgres-test
103 @echo "Waiting for test database to be ready..."
104 @sleep 3
105 @echo "$(GREEN)Running migrations on test database...$(RESET)"
106 @goose -dir internal/db/migrations postgres "postgresql://$(POSTGRES_TEST_USER):$(POSTGRES_TEST_PASSWORD)@localhost:$(POSTGRES_TEST_PORT)/$(POSTGRES_TEST_DB)?sslmode=disable" up || true
107 @echo "$(GREEN)Running fast tests (use 'make e2e-test' for E2E tests)...$(RESET)"
108 @go test ./cmd/... ./internal/... ./tests/... -short -v
109 @echo "$(GREEN)✓ Tests complete$(RESET)"
110
111e2e-test: ## Run automated E2E tests (requires: make dev-up + make run in another terminal)
112 @echo "$(CYAN)========================================$(RESET)"
113 @echo "$(CYAN) E2E Test: Full User Signup Flow $(RESET)"
114 @echo "$(CYAN)========================================$(RESET)"
115 @echo ""
116 @echo "$(CYAN)Prerequisites:$(RESET)"
117 @echo " 1. Run 'make dev-up' (starts PDS + Jetstream)"
118 @echo " 2. Run 'make run' in another terminal (AppView must be running)"
119 @echo ""
120 @echo "$(GREEN)Running E2E tests...$(RESET)"
121 @go test ./tests/e2e -run TestE2E_UserSignup -v
122 @echo ""
123 @echo "$(GREEN)✓ E2E tests complete!$(RESET)"
124
125e2e-vote-test: ## Run vote E2E tests (requires: make dev-up)
126 @echo "$(CYAN)========================================$(RESET)"
127 @echo "$(CYAN) E2E Test: Vote System $(RESET)"
128 @echo "$(CYAN)========================================$(RESET)"
129 @echo ""
130 @echo "$(CYAN)Prerequisites:$(RESET)"
131 @echo " 1. Run 'make dev-up' (starts PDS + Jetstream + PostgreSQL)"
132 @echo " 2. Test database will be used (port 5434)"
133 @echo ""
134 @echo "$(GREEN)Running vote E2E tests...$(RESET)"
135 @echo ""
136 @echo "$(CYAN)Running simulated E2E test (fast)...$(RESET)"
137 @go test ./tests/integration -run TestVote_E2E_WithJetstream -v
138 @echo ""
139 @echo "$(CYAN)Running live PDS E2E test (requires PDS + Jetstream)...$(RESET)"
140 @go test ./tests/integration -run TestVote_E2E_LivePDS -v || echo "$(YELLOW)Live PDS test skipped (run 'make dev-up' first)$(RESET)"
141 @echo ""
142 @echo "$(GREEN)✓ Vote E2E tests complete!$(RESET)"
143
144test-db-reset: ## Reset test database
145 @echo "$(GREEN)Resetting test database...$(RESET)"
146 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test rm -sf postgres-test
147 @docker volume rm coves-test-postgres-data || true
148 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test up -d postgres-test
149 @echo "Waiting for PostgreSQL to be ready..."
150 @sleep 3
151 @goose -dir internal/db/migrations postgres "postgresql://$(POSTGRES_TEST_USER):$(POSTGRES_TEST_PASSWORD)@localhost:$(POSTGRES_TEST_PORT)/$(POSTGRES_TEST_DB)?sslmode=disable" up || true
152 @echo "$(GREEN)✓ Test database reset$(RESET)"
153
154test-db-stop: ## Stop test database
155 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test stop postgres-test
156 @echo "$(GREEN)✓ Test database stopped$(RESET)"
157
158##@ Code Quality
159
160fmt: ## Format all Go code with gofmt
161 @echo "$(GREEN)Formatting Go code...$(RESET)"
162 @gofmt -w ./cmd ./internal ./tests
163 @echo "$(GREEN)✓ Formatting complete$(RESET)"
164
165fmt-check: ## Check if Go code is properly formatted
166 @echo "$(GREEN)Checking code formatting...$(RESET)"
167 @unformatted=$$(gofmt -l ./cmd ./internal ./tests); \
168 if [ -n "$$unformatted" ]; then \
169 echo "$(RED)✗ The following files are not formatted:$(RESET)"; \
170 echo "$$unformatted"; \
171 echo "$(YELLOW)Run 'make fmt' to fix$(RESET)"; \
172 exit 1; \
173 fi
174 @echo "$(GREEN)✓ All files are properly formatted$(RESET)"
175
176lint: fmt-check ## Run golangci-lint on the codebase (includes format check)
177 @echo "$(GREEN)Running linter...$(RESET)"
178 @golangci-lint run ./cmd/... ./internal/... ./tests/...
179 @echo "$(GREEN)✓ Linting complete$(RESET)"
180
181lint-fix: ## Run golangci-lint and auto-fix issues
182 @echo "$(GREEN)Running linter with auto-fix...$(RESET)"
183 @golangci-lint run --fix ./cmd/... ./internal/... ./tests/...
184 @gofmt -w ./cmd ./internal ./tests
185 @echo "$(GREEN)✓ Linting complete$(RESET)"
186
187##@ Build & Run
188
189build: ## Build the Coves server (production - no dev code)
190 @echo "$(GREEN)Building Coves server (production)...$(RESET)"
191 @go build -o server ./cmd/server
192 @echo "$(GREEN)✓ Build complete: ./server$(RESET)"
193
194build-dev: ## Build the Coves server with dev mode (includes localhost OAuth resolvers)
195 @echo "$(GREEN)Building Coves server (dev mode)...$(RESET)"
196 @go build -tags dev -o server ./cmd/server
197 @echo "$(GREEN)✓ Build complete: ./server (with dev tags)$(RESET)"
198
199run: ## Run the Coves server with dev environment (requires database running)
200 @./scripts/dev-run.sh
201
202##@ Cleanup
203
204clean: ## Clean build artifacts and temporary files
205 @echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
206 @rm -f server main validate-lexicon
207 @go clean
208 @echo "$(GREEN)✓ Clean complete$(RESET)"
209
210clean-all: clean ## Clean everything including Docker volumes (DESTRUCTIVE)
211 @echo "$(YELLOW)⚠️ WARNING: This will remove ALL Docker volumes!$(RESET)"
212 @read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || exit 1
213 @make dev-reset
214 @echo "$(GREEN)✓ All clean$(RESET)"
215
216##@ Workflows (Common Tasks)
217
218fresh-start: ## Complete fresh start (reset everything, start clean)
219 @echo "$(CYAN)Starting fresh development environment...$(RESET)"
220 @make dev-reset || true
221 @sleep 2
222 @make dev-up
223 @sleep 3
224 @make db-migrate
225 @echo ""
226 @echo "$(GREEN)✓ Fresh environment ready!$(RESET)"
227 @make dev-status
228
229quick-restart: ## Quick restart of development stack (keeps data)
230 @make dev-down
231 @make dev-up
232
233##@ Mobile Testing
234
235mobile-setup: ## Setup Android port forwarding for USB-connected devices (recommended)
236 @echo "$(CYAN)Setting up Android mobile testing environment...$(RESET)"
237 @./scripts/setup-mobile-ports.sh
238
239mobile-reset: ## Remove all Android port forwarding
240 @echo "$(YELLOW)Removing Android port forwarding...$(RESET)"
241 @adb reverse --remove-all || echo "$(YELLOW)No device connected$(RESET)"
242 @echo "$(GREEN)✓ Port forwarding removed$(RESET)"
243
244verify-stack: ## Verify local development stack (PLC, PDS, configs)
245 @./scripts/verify-local-stack.sh
246
247create-test-account: ## Create a test account on local PDS for OAuth testing
248 @./scripts/create-test-account.sh
249
250mobile-full-setup: verify-stack create-test-account mobile-setup ## Full mobile setup: verify stack, create account, setup ports
251 @echo ""
252 @echo "$(GREEN)═══════════════════════════════════════════════════════════$(RESET)"
253 @echo "$(GREEN) Mobile development environment ready! $(RESET)"
254 @echo "$(GREEN)═══════════════════════════════════════════════════════════$(RESET)"
255 @echo ""
256 @echo "$(CYAN)Run the Flutter app with:$(RESET)"
257 @echo " $(YELLOW)cd /home/bretton/Code/coves-mobile$(RESET)"
258 @echo " $(YELLOW)flutter run --dart-define=ENVIRONMENT=local$(RESET)"
259 @echo ""
260
261ngrok-up: ## Start ngrok tunnels (for iOS or WiFi testing - requires paid plan for 3 tunnels)
262 @echo "$(GREEN)Starting ngrok tunnels for mobile testing...$(RESET)"
263 @./scripts/start-ngrok.sh
264
265ngrok-down: ## Stop all ngrok tunnels
266 @./scripts/stop-ngrok.sh
267
268##@ Utilities
269
270validate-lexicon: ## Validate all Lexicon schemas
271 @echo "$(GREEN)Validating Lexicon schemas...$(RESET)"
272 @./validate-lexicon
273 @echo "$(GREEN)✓ Lexicon validation complete$(RESET)"
274
275##@ Documentation
276
277docs: ## Open project documentation
278 @echo "$(CYAN)Project Documentation:$(RESET)"
279 @echo " - Setup Guide: docs/LOCAL_DEVELOPMENT.md"
280 @echo " - Project Structure: PROJECT_STRUCTURE.md"
281 @echo " - Build Guide: CLAUDE.md"
282 @echo " - atProto Guide: ATPROTO_GUIDE.md"
283 @echo " - PRD: PRD.md"