| name | debugging |
| description | Debug common issues in the Shorted project. Use when troubleshooting errors, fixing bugs, or diagnosing problems with the backend, frontend, or database. |
| allowed-tools | Read, Bash(make:*), Bash(docker:*), Bash(lsof:*), Bash(curl:*), Bash(psql:*), Grep, Glob |
Debugging Guide
This skill helps you diagnose and fix common issues in the Shorted project.
Quick Diagnostics
make dev-db && docker ps
lsof -i :3020
lsof -i :9091
lsof -i :5438
make clean-ports
make dev-stop && make dev
Common Issues
Backend Not Starting
Symptom: make dev-backend fails or hangs
Steps:
-
Check for port conflicts:
lsof -i :9091
-
Kill stale processes:
make clean-ports
-
Check database is running:
docker ps | grep shorted_db
-
Test database connection:
psql postgresql://admin:password@localhost:5438/shorts -c "SELECT 1"
-
Check for Go compilation errors:
cd services && go build ./shorts/cmd/server/...
-
Check environment variables:
echo $DATABASE_URL
Frontend Not Starting
Symptom: make dev-frontend fails
Steps:
-
Clear Next.js cache:
make clean-cache
-
Reinstall dependencies:
cd web && rm -rf node_modules && npm install
-
Check for TypeScript errors:
cd web && npx tsc --noEmit
-
Check port availability:
lsof -i :3020
Database Connection Issues
Symptom: "connection refused" or timeout errors
Steps:
-
Start the database:
make dev-db
-
Check container status:
docker ps
docker logs shorted_db
-
Wait for database to be ready:
until docker exec shorted_db pg_isready -U admin -d shorts; do
sleep 2
done
-
Test connection:
psql postgresql://admin:password@localhost:5438/shorts -c "\dt"
-
If container won't start, reset:
cd analysis/sql && docker compose down -v
cd analysis/sql && docker compose up -d postgres
API Returning 500 Errors
Symptom: Backend returns internal server errors
Steps:
-
Check backend logs (run in foreground):
cd services && DATABASE_URL=postgresql://admin:password@localhost:5438/shorts \
go run shorts/cmd/server/main.go
-
Test specific endpoint:
curl -v -X POST http://localhost:9091/v1/topShorts \
-H "Content-Type: application/json" \
-d '{"period": "1m", "limit": 10}'
-
Check database has data:
psql postgresql://admin:password@localhost:5438/shorts \
-c "SELECT COUNT(*) FROM shorts"
-
Verify database schema:
cd services && make migrate-version
cd services && make migrate-up
Data Not Showing on Frontend
Symptom: UI shows empty state or loading forever
Steps:
-
Check backend is responding:
curl http://localhost:9091/health
-
Test API directly:
curl -X POST http://localhost:9091/v1/topShorts \
-H "Content-Type: application/json" \
-d '{"period": "1m", "limit": 10}' | jq
-
Check browser console for errors (open DevTools)
-
Check network tab for failed requests
-
Verify environment variables in .env.local:
cat web/.env.local
Integration Tests Failing
Symptom: make test-integration-local fails
Steps:
-
Ensure Docker is running:
docker info
-
Clean up old containers:
docker system prune -f
-
Run with verbose output:
cd services && go test -v ./test/integration/... -timeout=20m
-
Check testcontainer logs in test output
Slow Database Queries
Symptom: API responses take >1 second
Steps:
-
Diagnose slow queries:
make db-diagnose
-
Apply performance indexes:
make db-optimize
-
Update statistics:
psql postgresql://admin:password@localhost:5438/shorts \
-c "ANALYZE shorts; ANALYZE \"company-metadata\"; ANALYZE stock_prices;"
-
Check query plan:
EXPLAIN ANALYZE
SELECT * FROM shorts
WHERE "PRODUCT_CODE" = 'BHP'
ORDER BY "DATE" DESC
LIMIT 100;
Build/Lint Errors
Symptom: make test fails on linting
Steps:
-
Run linting separately:
make lint-frontend
make lint-backend
-
Auto-fix TypeScript issues:
cd web && npm run lint -- --fix
-
Auto-fix Go issues:
cd services && make lint-fix
-
Format code:
make format
Debug Mode
Backend Verbose Logging
cd services && LOG_LEVEL=debug \
DATABASE_URL=postgresql://admin:password@localhost:5438/shorts \
go run shorts/cmd/server/main.go
Frontend Debug
Add to web/.env.local:
DEBUG=*
PostgreSQL Query Logging
SET log_statement = 'all';
SET log_duration = on;
Health Checks
curl http://localhost:9091/health
docker exec shorted_db pg_isready -U admin -d shorts
make health-check
Log Locations
| Service | How to View |
|---|
| Backend | Terminal output (foreground) or docker logs |
| Frontend | Terminal output + browser DevTools |
| Database | docker logs shorted_db |
| Cloud Run | make daily-sync-logs |
Useful Commands
docker ps
lsof -i :3020,9091,5438,8090
psql postgresql://admin:password@localhost:5438/shorts
cd services && make run.shorts 2>&1 | tee backend.log
cd services && go generate ./...