You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .cursorrules
+15-13Lines changed: 15 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,25 @@ This project is called "Coder" - an application for managing remote development
4
4
5
5
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.
6
6
7
-
# Core Architecture
7
+
## Core Architecture
8
8
9
9
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.
10
10
11
11
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.
12
12
13
13
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.
14
14
15
-
# API Design
15
+
## API Design
16
16
17
17
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.
18
18
19
19
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.
20
20
21
-
# Network Architecture
21
+
## Network Architecture
22
22
23
23
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.
24
24
25
-
## Tailnet and DERP System
25
+
### Tailnet and DERP System
26
26
27
27
The networking system has three key components:
28
28
@@ -35,7 +35,7 @@ The networking system has three key components:
35
35
36
36
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.
37
37
38
-
## Workspace Proxies
38
+
### Workspace Proxies
39
39
40
40
Workspace proxies (in the Enterprise edition) provide regional relay points for browser-based connections, reducing latency for geo-distributed teams. Key characteristics:
41
41
@@ -45,9 +45,10 @@ Workspace proxies (in the Enterprise edition) provide regional relay points for
45
45
- Managed through the `coder wsproxy` commands
46
46
- Implemented primarily in the `enterprise/wsproxy/` package
47
47
48
-
# Agent System
48
+
## Agent System
49
49
50
50
The workspace agent runs within each provisioned workspace and provides core functionality including:
51
+
51
52
- SSH access to workspaces via the `agentssh` package
52
53
- Port forwarding
53
54
- Terminal connectivity via the `pty` package for pseudo-terminal support
@@ -57,7 +58,7 @@ The workspace agent runs within each provisioned workspace and provides core fun
57
58
58
59
Agents communicate with the control plane using the tailnet system and authenticate using secure tokens.
59
60
60
-
# Workspace Applications
61
+
## Workspace Applications
61
62
62
63
Workspace applications (or "apps") provide browser-based access to services running within workspaces. The system supports:
63
64
@@ -69,17 +70,17 @@ Workspace applications (or "apps") provide browser-based access to services runn
69
70
70
71
The implementation is primarily in the `coderd/workspaceapps/` directory with components for URL generation, proxying connections, and managing application state.
71
72
72
-
# Implementation Details
73
+
## Implementation Details
73
74
74
75
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.
75
76
76
77
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.
77
78
78
-
# Authorization System
79
+
## Authorization System
79
80
80
81
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.
81
82
82
-
# Testing Framework
83
+
## Testing Framework
83
84
84
85
The codebase has a comprehensive testing approach with several key components:
85
86
@@ -91,7 +92,7 @@ The codebase has a comprehensive testing approach with several key components:
91
92
92
93
4. **Enterprise Testing**: Enterprise features have dedicated test utilities in the `coderdenttest` package.
93
94
94
-
# Open Source and Enterprise Components
95
+
## Open Source and Enterprise Components
95
96
96
97
The repository contains both open source and enterprise components:
97
98
@@ -100,9 +101,10 @@ The repository contains both open source and enterprise components:
100
101
- The boundary between open source and enterprise is managed through a licensing system
101
102
- The same core codebase supports both editions, with enterprise features conditionally enabled
102
103
103
-
# Development Philosophy
104
+
## Development Philosophy
104
105
105
106
Coder emphasizes clear error handling, with specific patterns required:
107
+
106
108
- Concise error messages that avoid phrases like "failed to"
107
109
- Wrapping errors with `%w` to maintain error chains
108
110
- Using sentinel errors with the "err" prefix (e.g., `errNotFound`)
@@ -111,7 +113,7 @@ All tests should run in parallel using `t.Parallel()` to ensure efficient testin
111
113
112
114
Git contributions follow a standard format with commit messages structured as `type: <message>`, where type is one of `feat`, `fix`, or `chore`.
113
115
114
-
# Development Workflow
116
+
## Development Workflow
115
117
116
118
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.
- MUST DO! Any changes to database - adding queries, modifying queries should be done in the `coderd\database\queries\*.sql` files. Use `make gen` to generate necessary changes after.
69
+
- MUST DO! Queries are grouped in files relating to context - e.g. `prebuilds.sql`, `users.sql`, `provisionerjobs.sql`.
70
+
- After making changes to any `coderd\database\queries\*.sql` files you must run `make gen` to generate respective ORM changes.
71
+
72
+
## Architecture
73
+
74
+
### Core Components
75
+
76
+
-**coderd**: Main API service connecting workspaces, provisioners, and users
77
+
-**provisionerd**: Execution context for infrastructure-modifying providers
78
+
-**Agents**: Services in remote workspaces providing features like SSH and port forwarding
79
+
-**Workspaces**: Cloud resources defined by Terraform
80
+
81
+
## Sub-modules
82
+
83
+
### Template System
84
+
85
+
- Templates define infrastructure for workspaces using Terraform
86
+
- Environment variables pass context between Coder and templates
87
+
- Official modules extend development environments
88
+
89
+
### RBAC System
90
+
91
+
- Permissions defined at site, organization, and user levels
0 commit comments