Development Setup
This guide will help you set up a development environment for Code Search.
Prerequisites
Section titled “Prerequisites”- Go 1.21+
- Node.js 18+
- pnpm
- Docker & Docker Compose
- Git
- PostgreSQL (or use Docker)
- Redis (or use Docker)
Quick Start
Section titled “Quick Start”1. Clone the repository
Section titled “1. Clone the repository”git clone https://github.com/your-org/code-search.gitcd code-search2. Start dependencies
Section titled “2. Start dependencies”docker-compose -f docker-compose.dev.yml up -dThis starts PostgreSQL, Redis, and Zoekt.
3. Configure environment
Section titled “3. Configure environment”cp config.example.yaml config.yaml# Edit config.yaml with your settings4. Run migrations
Section titled “4. Run migrations”make migrate5. Start the API server
Section titled “5. Start the API server”make run-api6. Start the indexer (in another terminal)
Section titled “6. Start the indexer (in another terminal)”make run-indexer7. Start the web UI (in another terminal)
Section titled “7. Start the web UI (in another terminal)”cd webpnpm installpnpm devThe application is now running at:
- Web UI: http://localhost:3001
- API: http://localhost:3000
Project Structure
Section titled “Project Structure”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/ # DockerfilesDevelopment Commands
Section titled “Development Commands”Make Targets
Section titled “Make Targets”# Build everythingmake build
# Run testsmake test
# Run lintermake lint
# Format codemake fmt
# Generate codemake generate
# Run API servermake run-api
# Run indexermake run-indexer
# Run migrationsmake migrateGo Commands
Section titled “Go Commands”# Run tests with coveragego test -cover ./...
# Run specific package testsgo test ./internal/search/...
# Build binarygo build -o bin/code-search ./cmd/api
# Run with race detectorgo run -race ./cmd/apiWeb Commands
Section titled “Web Commands”cd web
# Install dependenciespnpm install
# Development serverpnpm dev
# Production buildpnpm build
# Run linterpnpm lint
# Type checkpnpm typecheckConfiguration
Section titled “Configuration”Development Config
Section titled “Development Config”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 testingconnections: - name: test-github type: github token: "${GITHUB_TOKEN}" orgs: - your-test-orgEnvironment Variables
Section titled “Environment Variables”export GITHUB_TOKEN="ghp_xxxxx"export GITLAB_TOKEN="glpat-xxxxx"export DATABASE_PASSWORD="postgres"export REDIS_PASSWORD=""Testing
Section titled “Testing”Unit Tests
Section titled “Unit Tests”# Run all testsmake test
# Run with verbose outputgo test -v ./...
# Run specific testgo test -v ./internal/search -run TestSearchQueryIntegration Tests
Section titled “Integration Tests”# Start test dependenciesdocker-compose -f docker-compose.test.yml up -d
# Run integration testsmake test-integration
# Clean updocker-compose -f docker-compose.test.yml downEnd-to-End Tests
Section titled “End-to-End Tests”cd webpnpm e2eDebugging
Section titled “Debugging”API Server
Section titled “API Server”# Run with delve debuggerdlv debug ./cmd/api -- --config config.yaml
# Attach to running processdlv attach <pid>VS Code Launch Config
Section titled “VS Code Launch Config”{ "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"] } ]}Logging
Section titled “Logging”Enable debug logging:
log: level: debug format: text # or jsonDatabase
Section titled “Database”Running Migrations
Section titled “Running Migrations”# Apply migrationsmake migrate
# Rollback last migrationmake migrate-down
# Create new migrationmake migrate-create name=add_new_tableAccessing Database
Section titled “Accessing Database”# Via psqlpsql -h localhost -U postgres -d code_search_dev
# Via makemake db-shellDocker Development
Section titled “Docker Development”Building Images
Section titled “Building Images”# Build all imagesmake docker-build
# Build specific imagedocker build -f docker/api.Dockerfile -t code-search-api .Running in Docker
Section titled “Running in Docker”# Start everythingdocker-compose up
# Start with rebuilddocker-compose up --build
# View logsdocker-compose logs -f apiCode Style
Section titled “Code Style”- Follow Effective Go
- Use
gofmtfor formatting - Run
golangci-lintfor linting
TypeScript
Section titled “TypeScript”- Follow the project’s ESLint config
- Use Prettier for formatting
- Use strict TypeScript
Commit Messages
Section titled “Commit Messages”Follow conventional commits:
feat: add new search filterfix: resolve connection timeout issuedocs: update API documentationrefactor: simplify indexer logictest: add search testsNext Steps
Section titled “Next Steps”- Contributing - Contribution guidelines
- Building - Build process details