Skip to content

Development Setup

This guide will help you set up a development environment for Code Search.

  • Go 1.21+
  • Node.js 18+
  • pnpm
  • Docker & Docker Compose
  • Git
  • PostgreSQL (or use Docker)
  • Redis (or use Docker)
Terminal window
git clone https://github.com/your-org/code-search.git
cd code-search
Terminal window
docker-compose -f docker-compose.dev.yml up -d

This starts PostgreSQL, Redis, and Zoekt.

Terminal window
cp config.example.yaml config.yaml
# Edit config.yaml with your settings
Terminal window
make migrate
Terminal window
make run-api

6. Start the indexer (in another terminal)

Section titled “6. Start the indexer (in another terminal)”
Terminal window
make run-indexer
Terminal window
cd web
pnpm install
pnpm dev

The application is now running at:

code-search/
├── cmd/ # Application entrypoints
│ ├── api/ # API server
│ ├── cli/ # CLI tool
│ └── indexer/ # Indexer service
├── internal/ # Internal packages
│ ├── config/ # Configuration
│ ├── db/ # Database access
│ ├── codehost/ # Code host integrations
│ ├── indexer/ # Indexing logic
│ ├── search/ # Search logic
│ └── queue/ # Job queue
├── web/ # Next.js frontend
│ ├── app/ # App router pages
│ ├── components/ # React components
│ └── lib/ # Utilities
├── migrations/ # SQL migrations
├── docs/ # Documentation
└── docker/ # Dockerfiles
Terminal window
# Build everything
make build
# Run tests
make test
# Run linter
make lint
# Format code
make fmt
# Generate code
make generate
# Run API server
make run-api
# Run indexer
make run-indexer
# Run migrations
make migrate
Terminal window
# Run tests with coverage
go test -cover ./...
# Run specific package tests
go test ./internal/search/...
# Build binary
go build -o bin/code-search ./cmd/api
# Run with race detector
go run -race ./cmd/api
Terminal window
cd web
# Install dependencies
pnpm install
# Development server
pnpm dev
# Production build
pnpm build
# Run linter
pnpm lint
# Type check
pnpm typecheck

Create config.yaml for development:

server:
host: "0.0.0.0"
port: 3000
database:
host: "localhost"
port: 5432
name: "code_search_dev"
user: "postgres"
password: "postgres"
redis:
host: "localhost"
port: 6379
zoekt:
data_dir: "./data"
index_dir: "./data/index"
indexer:
concurrency: 2
data_dir: "./data"
# Development connections for testing
connections:
- name: test-github
type: github
token: "${GITHUB_TOKEN}"
orgs:
- your-test-org
Terminal window
export GITHUB_TOKEN="ghp_xxxxx"
export GITLAB_TOKEN="glpat-xxxxx"
export DATABASE_PASSWORD="postgres"
export REDIS_PASSWORD=""
Terminal window
# Run all tests
make test
# Run with verbose output
go test -v ./...
# Run specific test
go test -v ./internal/search -run TestSearchQuery
Terminal window
# Start test dependencies
docker-compose -f docker-compose.test.yml up -d
# Run integration tests
make test-integration
# Clean up
docker-compose -f docker-compose.test.yml down
Terminal window
cd web
pnpm e2e
Terminal window
# Run with delve debugger
dlv debug ./cmd/api -- --config config.yaml
# Attach to running process
dlv attach <pid>
{
"version": "0.2.0",
"configurations": [
{
"name": "API Server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/api",
"args": ["--config", "config.yaml"]
},
{
"name": "Indexer",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/indexer",
"args": ["--config", "config.yaml"]
}
]
}

Enable debug logging:

config.yaml
log:
level: debug
format: text # or json
Terminal window
# Apply migrations
make migrate
# Rollback last migration
make migrate-down
# Create new migration
make migrate-create name=add_new_table
Terminal window
# Via psql
psql -h localhost -U postgres -d code_search_dev
# Via make
make db-shell
Terminal window
# Build all images
make docker-build
# Build specific image
docker build -f docker/api.Dockerfile -t code-search-api .
Terminal window
# Start everything
docker-compose up
# Start with rebuild
docker-compose up --build
# View logs
docker-compose logs -f api
  • Follow Effective Go
  • Use gofmt for formatting
  • Run golangci-lint for linting
  • Follow the project’s ESLint config
  • Use Prettier for formatting
  • Use strict TypeScript

Follow conventional commits:

feat: add new search filter
fix: resolve connection timeout issue
docs: update API documentation
refactor: simplify indexer logic
test: add search tests