Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: travisbikkle/coder
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: coder/coder
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
Showing 7,045 changed files with 231,644 additions and 77,584 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
124 changes: 124 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Cursor Rules

This project is called "Coder" - an application for managing remote development environments.

Coder provides a platform for creating, managing, and using remote development environments (also known as Cloud Development Environments or CDEs). It leverages Terraform to define and provision these environments, which are referred to as "workspaces" within the project. The system is designed to be extensible, secure, and provide developers with a seamless remote development experience.

## Core Architecture

The heart of Coder is a control plane that orchestrates the creation and management of workspaces. This control plane interacts with separate Provisioner processes over gRPC to handle workspace builds. The Provisioners consume workspace definitions and use Terraform to create the actual infrastructure.

The CLI package serves dual purposes - it can be used to launch the control plane itself and also provides client functionality for users to interact with an existing control plane instance. All user-facing frontend code is developed in TypeScript using React and lives in the `site/` directory.

The database layer uses PostgreSQL with SQLC for generating type-safe database code. Database migrations are carefully managed to ensure both forward and backward compatibility through paired `.up.sql` and `.down.sql` files.

## API Design

Coder's API architecture combines REST and gRPC approaches. The REST API is defined in `coderd/coderd.go` and uses Chi for HTTP routing. This provides the primary interface for the frontend and external integrations.

Internal communication with Provisioners occurs over gRPC, with service definitions maintained in `.proto` files. This separation allows for efficient binary communication with the components responsible for infrastructure management while providing a standard REST interface for human-facing applications.

## Network Architecture

Coder implements a secure networking layer based on Tailscale's Wireguard implementation. The `tailnet` package provides connectivity between workspace agents and clients through DERP (Designated Encrypted Relay for Packets) servers when direct connections aren't possible. This creates a secure overlay network allowing access to workspaces regardless of network topology, firewalls, or NAT configurations.

### Tailnet and DERP System

The networking system has three key components:

1. **Tailnet**: An overlay network implemented in the `tailnet` package that provides secure, end-to-end encrypted connections between clients, the Coder server, and workspace agents.

2. **DERP Servers**: These relay traffic when direct connections aren't possible. Coder provides several options:
- A built-in DERP server that runs on the Coder control plane
- Integration with Tailscale's global DERP infrastructure
- Support for custom DERP servers for lower latency or offline deployments

3. **Direct Connections**: When possible, the system establishes peer-to-peer connections between clients and workspaces using STUN for NAT traversal. This requires both endpoints to send UDP traffic on ephemeral ports.

### Workspace Proxies

Workspace proxies (in the Enterprise edition) provide regional relay points for browser-based connections, reducing latency for geo-distributed teams. Key characteristics:

- Deployed as independent servers that authenticate with the Coder control plane
- Relay connections for SSH, workspace apps, port forwarding, and web terminals
- Do not make direct database connections
- Managed through the `coder wsproxy` commands
- Implemented primarily in the `enterprise/wsproxy/` package

## Agent System

The workspace agent runs within each provisioned workspace and provides core functionality including:

- SSH access to workspaces via the `agentssh` package
- Port forwarding
- Terminal connectivity via the `pty` package for pseudo-terminal support
- Application serving
- Healthcheck monitoring
- Resource usage reporting

Agents communicate with the control plane using the tailnet system and authenticate using secure tokens.

## Workspace Applications

Workspace applications (or "apps") provide browser-based access to services running within workspaces. The system supports:

- HTTP(S) and WebSocket connections
- Path-based or subdomain-based access URLs
- Health checks to monitor application availability
- Different sharing levels (owner-only, authenticated users, or public)
- Custom icons and display settings

The implementation is primarily in the `coderd/workspaceapps/` directory with components for URL generation, proxying connections, and managing application state.

## Implementation Details

The project structure separates frontend and backend concerns. React components and pages are organized in the `site/src/` directory, with Jest used for testing. The backend is primarily written in Go, with a strong emphasis on error handling patterns and test coverage.

Database interactions are carefully managed through migrations in `coderd/database/migrations/` and queries in `coderd/database/queries/`. All new queries require proper database authorization (dbauthz) implementation to ensure that only users with appropriate permissions can access specific resources.

## Authorization System

The database authorization (dbauthz) system enforces fine-grained access control across all database operations. It uses role-based access control (RBAC) to validate user permissions before executing database operations. The `dbauthz` package wraps the database store and performs authorization checks before returning data. All database operations must pass through this layer to ensure security.

## Testing Framework

The codebase has a comprehensive testing approach with several key components:

1. **Parallel Testing**: All tests must use `t.Parallel()` to run concurrently, which improves test suite performance and helps identify race conditions.

2. **coderdtest Package**: This package in `coderd/coderdtest/` provides utilities for creating test instances of the Coder server, setting up test users and workspaces, and mocking external components.

3. **Integration Tests**: Tests often span multiple components to verify system behavior, such as template creation, workspace provisioning, and agent connectivity.

4. **Enterprise Testing**: Enterprise features have dedicated test utilities in the `coderdenttest` package.

## Open Source and Enterprise Components

The repository contains both open source and enterprise components:

- Enterprise code lives primarily in the `enterprise/` directory
- Enterprise features focus on governance, scalability (high availability), and advanced deployment options like workspace proxies
- The boundary between open source and enterprise is managed through a licensing system
- The same core codebase supports both editions, with enterprise features conditionally enabled

## Development Philosophy

Coder emphasizes clear error handling, with specific patterns required:

- Concise error messages that avoid phrases like "failed to"
- Wrapping errors with `%w` to maintain error chains
- Using sentinel errors with the "err" prefix (e.g., `errNotFound`)

All tests should run in parallel using `t.Parallel()` to ensure efficient testing and expose potential race conditions. The codebase is rigorously linted with golangci-lint to maintain consistent code quality.

Git contributions follow a standard format with commit messages structured as `type: <message>`, where type is one of `feat`, `fix`, or `chore`.

## Development Workflow

Development can be initiated using `scripts/develop.sh` to start the application after making changes. Database schema updates should be performed through the migration system using `create_migration.sh <name>` to generate migration files, with each `.up.sql` migration paired with a corresponding `.down.sql` that properly reverts all changes.

If the development database gets into a bad state, it can be completely reset by removing the PostgreSQL data directory with `rm -rf .coderv2/postgres`. This will destroy all data in the development database, requiring you to recreate any test users, templates, or workspaces after restarting the application.

Code generation for the database layer uses `coderd/database/generate.sh`, and developers should refer to `sqlc.yaml` for the appropriate style and patterns to follow when creating new queries or tables.

The focus should always be on maintaining security through proper database authorization, clean error handling, and comprehensive test coverage to ensure the platform remains robust and reliable.
7 changes: 6 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -9,5 +9,10 @@
}
},
// SYS_PTRACE to enable go debugging
"runArgs": ["--cap-add=SYS_PTRACE"]
"runArgs": ["--cap-add=SYS_PTRACE"],
"customizations": {
"vscode": {
"extensions": ["biomejs.biome"]
}
}
}
6 changes: 0 additions & 6 deletions .dockerignore

This file was deleted.

3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Generated files
agent/agentcontainers/acmock/acmock.go linguist-generated=true
agent/agentcontainers/dcspec/dcspec_gen.go linguist-generated=true
agent/agentcontainers/testdata/devcontainercli/*/*.log linguist-generated=true
coderd/apidoc/docs.go linguist-generated=true
docs/reference/api/*.md linguist-generated=true
docs/reference/cli/*.md linguist-generated=true
6 changes: 6 additions & 0 deletions .github/.linkspector.yml
Original file line number Diff line number Diff line change
@@ -18,5 +18,11 @@ ignorePatterns:
- pattern: "i.imgur.com"
- pattern: "code.visualstudio.com"
- pattern: "www.emacswiki.org"
- pattern: "linux.die.net/man"
- pattern: "www.gnu.org"
- pattern: "wiki.ubuntu.com"
- pattern: "mutagen.io"
- pattern: "docs.github.com"
- pattern: "claude.ai"
aliveStatusCodes:
- 200
79 changes: 79 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "🐞 Bug"
description: "File a bug report."
title: "bug: "
labels: ["needs-triage"]
type: "Bug"
body:
- type: checkboxes
id: existing_issues
attributes:
label: "Is there an existing issue for this?"
description: "Please search to see if an issue already exists for the bug you encountered."
options:
- label: "I have searched the existing issues"
required: true

- type: textarea
id: issue
attributes:
label: "Current Behavior"
description: "A concise description of what you're experiencing."
placeholder: "Tell us what you see!"
validations:
required: false

- type: textarea
id: logs
attributes:
label: "Relevant Log Output"
description: "Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks."
render: shell

- type: textarea
id: expected
attributes:
label: "Expected Behavior"
description: "A concise description of what you expected to happen."
validations:
required: false

- type: textarea
id: steps_to_reproduce
attributes:
label: "Steps to Reproduce"
description: "Provide step-by-step instructions to reproduce the issue."
placeholder: |
1. First step
2. Second step
3. Another step
4. Issue occurs
validations:
required: true

- type: textarea
id: environment
attributes:
label: "Environment"
description: |
Provide details about your environment:
- **Host OS**: (e.g., Ubuntu 24.04, Debian 12)
- **Coder Version**: (e.g., v2.18.4)
placeholder: |
Run `coder version` to get Coder version
value: |
- Host OS:
- Coder version:
validations:
required: false

- type: dropdown
id: additional_info
attributes:
label: "Additional Context"
description: "Select any applicable options:"
multiple: true
options:
- "The issue occurs consistently"
- "The issue is new (previously worked fine)"
- "The issue happens on multiple deployments"
- "I have tested this on the latest version"
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contact_links:
- name: Questions, suggestion or feature requests?
url: https://github.com/coder/coder/discussions/new/choose
about: Our preferred starting point if you have any questions or suggestions about configuration, features or unexpected behavior.
- name: Coder Docs
url: https://coder.com/docs
about: Check our docs.
- name: Coder Discord Community
url: https://discord.gg/coder
about: Get in touch with the Coder developers and community for support.
10 changes: 10 additions & 0 deletions .github/actions/install-cosign/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Install cosign"
description: |
Cosign Github Action.
runs:
using: "composite"
steps:
- name: Install cosign
uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
with:
cosign-release: "v2.4.3"
10 changes: 10 additions & 0 deletions .github/actions/install-syft/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Install syft"
description: |
Downloads Syft to the Action tool cache and provides a reference.
runs:
using: "composite"
steps:
- name: Install syft
uses: anchore/sbom-action/download-syft@f325610c9f50a54015d37c8d16cb3b0e2c8f4de0 # v0.18.0
with:
syft-version: "v1.20.0"
57 changes: 57 additions & 0 deletions .github/actions/setup-go-paths/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Setup Go Paths"
description: Overrides Go paths like GOCACHE and GOMODCACHE to use temporary directories.
outputs:
gocache:
description: "Value of GOCACHE"
value: ${{ steps.paths.outputs.gocache }}
gomodcache:
description: "Value of GOMODCACHE"
value: ${{ steps.paths.outputs.gomodcache }}
gopath:
description: "Value of GOPATH"
value: ${{ steps.paths.outputs.gopath }}
gotmp:
description: "Value of GOTMPDIR"
value: ${{ steps.paths.outputs.gotmp }}
cached-dirs:
description: "Go directories that should be cached between CI runs"
value: ${{ steps.paths.outputs.cached-dirs }}
runs:
using: "composite"
steps:
- name: Override Go paths
id: paths
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const path = require('path');
// RUNNER_TEMP should be backed by a RAM disk on Windows if
// coder/setup-ramdisk-action was used
const runnerTemp = process.env.RUNNER_TEMP;
const gocacheDir = path.join(runnerTemp, 'go-cache');
const gomodcacheDir = path.join(runnerTemp, 'go-mod-cache');
const gopathDir = path.join(runnerTemp, 'go-path');
const gotmpDir = path.join(runnerTemp, 'go-tmp');
core.exportVariable('GOCACHE', gocacheDir);
core.exportVariable('GOMODCACHE', gomodcacheDir);
core.exportVariable('GOPATH', gopathDir);
core.exportVariable('GOTMPDIR', gotmpDir);
core.setOutput('gocache', gocacheDir);
core.setOutput('gomodcache', gomodcacheDir);
core.setOutput('gopath', gopathDir);
core.setOutput('gotmp', gotmpDir);
const cachedDirs = `${gocacheDir}\n${gomodcacheDir}`;
core.setOutput('cached-dirs', cachedDirs);
- name: Create directories
shell: bash
run: |
set -e
mkdir -p "$GOCACHE"
mkdir -p "$GOMODCACHE"
mkdir -p "$GOPATH"
mkdir -p "$GOTMPDIR"
14 changes: 14 additions & 0 deletions .github/actions/setup-go-tools/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Setup Go tools"
description: |
Set up tools for `make gen`, `offlinedocs` and Schmoder CI.
runs:
using: "composite"
steps:
- name: go install tools
shell: bash
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.34
go install golang.org/x/tools/cmd/goimports@v0.31.0
go install github.com/mikefarah/yq/v4@v4.44.3
go install go.uber.org/mock/mockgen@v0.5.0
17 changes: 14 additions & 3 deletions .github/actions/setup-go/action.yaml
Original file line number Diff line number Diff line change
@@ -4,18 +4,29 @@ description: |
inputs:
version:
description: "The Go version to use."
default: "1.22.8"
default: "1.24.2"
use-preinstalled-go:
description: "Whether to use preinstalled Go."
default: "false"
use-cache:
description: "Whether to use the cache."
default: "true"
runs:
using: "composite"
steps:
- name: Setup Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ inputs.version }}
go-version: ${{ inputs.use-preinstalled-go == 'false' && inputs.version || '' }}
cache: ${{ inputs.use-cache }}

- name: Install gotestsum
shell: bash
run: go install gotest.tools/gotestsum@latest
run: go install gotest.tools/gotestsum@0d9599e513d70e5792bb9334869f82f6e8b53d4d # main as of 2025-05-15

- name: Install mtimehash
shell: bash
run: go install github.com/slsyy/mtimehash/cmd/mtimehash@a6b5da4ed2c4a40e7b805534b004e9fde7b53ce0 # v1.0.0

# It isn't necessary that we ever do this, but it helps
# separate the "setup" from the "run" times.
2 changes: 1 addition & 1 deletion .github/actions/setup-sqlc/action.yaml
Original file line number Diff line number Diff line change
@@ -7,4 +7,4 @@ runs:
- name: Setup sqlc
uses: sqlc-dev/setup-sqlc@c0209b9199cd1cce6a14fc27cabcec491b651761 # v4.0.0
with:
sqlc-version: "1.25.0"
sqlc-version: "1.27.0"
2 changes: 1 addition & 1 deletion .github/actions/setup-tf/action.yaml
Original file line number Diff line number Diff line change
@@ -7,5 +7,5 @@ runs:
- name: Install Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: 1.9.8
terraform_version: 1.11.4
terraform_wrapper: false
Loading