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
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
125test-db-reset: ## Reset test database
126 @echo "$(GREEN)Resetting test database...$(RESET)"
127 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test rm -sf postgres-test
128 @docker volume rm coves-test-postgres-data || true
129 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test up -d postgres-test
130 @echo "Waiting for PostgreSQL to be ready..."
131 @sleep 3
132 @goose -dir internal/db/migrations postgres "postgresql://$(POSTGRES_TEST_USER):$(POSTGRES_TEST_PASSWORD)@localhost:$(POSTGRES_TEST_PORT)/$(POSTGRES_TEST_DB)?sslmode=disable" up || true
133 @echo "$(GREEN)✓ Test database reset$(RESET)"
134
135test-db-stop: ## Stop test database
136 @docker-compose -f docker-compose.dev.yml --env-file .env.dev --profile test stop postgres-test
137 @echo "$(GREEN)✓ Test database stopped$(RESET)"
138
139##@ Code Quality
140
141fmt: ## Format all Go code with gofmt
142 @echo "$(GREEN)Formatting Go code...$(RESET)"
143 @gofmt -w ./cmd ./internal ./tests
144 @echo "$(GREEN)✓ Formatting complete$(RESET)"
145
146fmt-check: ## Check if Go code is properly formatted
147 @echo "$(GREEN)Checking code formatting...$(RESET)"
148 @unformatted=$$(gofmt -l ./cmd ./internal ./tests); \
149 if [ -n "$$unformatted" ]; then \
150 echo "$(RED)✗ The following files are not formatted:$(RESET)"; \
151 echo "$$unformatted"; \
152 echo "$(YELLOW)Run 'make fmt' to fix$(RESET)"; \
153 exit 1; \
154 fi
155 @echo "$(GREEN)✓ All files are properly formatted$(RESET)"
156
157lint: fmt-check ## Run golangci-lint on the codebase (includes format check)
158 @echo "$(GREEN)Running linter...$(RESET)"
159 @golangci-lint run ./cmd/... ./internal/... ./tests/...
160 @echo "$(GREEN)✓ Linting complete$(RESET)"
161
162lint-fix: ## Run golangci-lint and auto-fix issues
163 @echo "$(GREEN)Running linter with auto-fix...$(RESET)"
164 @golangci-lint run --fix ./cmd/... ./internal/... ./tests/...
165 @gofmt -w ./cmd ./internal ./tests
166 @echo "$(GREEN)✓ Linting complete$(RESET)"
167
168##@ Build & Run
169
170build: ## Build the Coves server
171 @echo "$(GREEN)Building Coves server...$(RESET)"
172 @go build -o server ./cmd/server
173 @echo "$(GREEN)✓ Build complete: ./server$(RESET)"
174
175run: ## Run the Coves server (requires database running)
176 @echo "$(GREEN)Starting Coves server...$(RESET)"
177 @go run ./cmd/server
178
179##@ Cleanup
180
181clean: ## Clean build artifacts and temporary files
182 @echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
183 @rm -f server main validate-lexicon
184 @go clean
185 @echo "$(GREEN)✓ Clean complete$(RESET)"
186
187clean-all: clean ## Clean everything including Docker volumes (DESTRUCTIVE)
188 @echo "$(YELLOW)⚠️ WARNING: This will remove ALL Docker volumes!$(RESET)"
189 @read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || exit 1
190 @make dev-reset
191 @echo "$(GREEN)✓ All clean$(RESET)"
192
193##@ Workflows (Common Tasks)
194
195fresh-start: ## Complete fresh start (reset everything, start clean)
196 @echo "$(CYAN)Starting fresh development environment...$(RESET)"
197 @make dev-reset || true
198 @sleep 2
199 @make dev-up
200 @sleep 3
201 @make db-migrate
202 @echo ""
203 @echo "$(GREEN)✓ Fresh environment ready!$(RESET)"
204 @make dev-status
205
206quick-restart: ## Quick restart of development stack (keeps data)
207 @make dev-down
208 @make dev-up
209
210##@ Utilities
211
212validate-lexicon: ## Validate all Lexicon schemas
213 @echo "$(GREEN)Validating Lexicon schemas...$(RESET)"
214 @./validate-lexicon
215 @echo "$(GREEN)✓ Lexicon validation complete$(RESET)"
216
217##@ Documentation
218
219docs: ## Open project documentation
220 @echo "$(CYAN)Project Documentation:$(RESET)"
221 @echo " - Setup Guide: docs/LOCAL_DEVELOPMENT.md"
222 @echo " - Project Structure: PROJECT_STRUCTURE.md"
223 @echo " - Build Guide: CLAUDE.md"
224 @echo " - atProto Guide: ATPROTO_GUIDE.md"
225 @echo " - PRD: PRD.md"