Rules for where code lives and what it is called. The rules describe how to decide, not what exists today, so adding a folder or package needs no edit here. Change this file only when a rule changes.
The repo builds for two runtimes, split the same way as Electron's main and renderer processes:
- Extension host (
src/): Node.js plus thevscodeAPI. - Webviews (
packages/): isolated browser contexts with no Node orvscodeaccess.
Rules for code on either side:
- Cross the boundary only with messages. The extension and webviews talk
through the typed IPC contracts in
@repo/shared(see thewebview-sharedREADME), never by importing each other's code. - Keep
@repo/sharedruntime-free. Use plain TypeScript, with no Node built-ins, DOM orvscode. When behavior differs by runtime, take it as a parameter, the waytoErrortakes its serializer. - Dependencies point one way.
src/imports only@repo/shared. Panel packages may import@repo/webview-shared,@repo/uiand@repo/shared, and@repo/webview-sharedimports only@repo/shared. Nothing imports a panel package. - Import a package through its
exports(@repo/shared,@repo/webview-shared/react), never through a relative path into another package. Inside a package, shared internals can use#subpath imports. @repo/mocksand@repo/storybook-utilsare for tests and stories only. Lint rejects them in runtime code.
@repo/ui is a library of generic, VS Code-style React components, and it is
built to be split into its own package later:
- It imports no other workspace package, and lint enforces this.
- It styles only through its
--ui-*tokens, so it never depends on a particular panel. - Its public API is the package root and its CSS exports. Consumers never reach into its files.
A component that knows about Coder, tasks or workspaces belongs in a panel
package, even if it is built from @repo/ui parts. The
ui README covers the details.
Pick the first option that fits:
- One consumer: put it in that consumer's file.
- One feature: put it in a module in that feature's folder. A new
feature gets its own
src/<feature>/folder, and a new webview panel gets its own package. - Several features, one domain: put it in that domain's folder (the
folder for the Coder API, the CLI, storage, VS Code APIs, and so on).
Code that knows about a domain never goes in
src/common/. - Several features, no domain: put it in a topic file in
src/common/(for examplestrings.ts). Don't add a new top-level file for it.
In webviews, apply the same steps inside a package. Code used by more than one package goes in:
@repo/shared: types and IPC contracts the extension also uses@repo/webview-shared: IPC and React plumbing for webviews@repo/ui: generic components (see@repo/ui)
Move code to a shared place only once a second consumer needs it.
-
Name a module by its topic, so the name says what's inside (
severity.ts,httpAgent.ts). Insrc/andpackages/*/src/, never useutils,helpersormiscas a file or folder name. Test-only support code is the exception (see Tests). -
Group related functions in one module. Don't create one file per function. When a module mixes topics, split it by topic, not by size.
-
A class, component or hook gets its own file, named after it:
Kind File Main export Extension module fooManager.tsFooManagerorfooManagerReact component FooPanel.tsxFooPanelHook useFoo.tsuseFooStory FooPanel.stories.tsxstories for FooPanel -
In a panel package, hooks used by several components go in
hooks/. A hook used by one component sits next to that component. Library packages keep a hook next to the code it serves. -
Import from the module that defines a symbol. Re-export files exist only as a package's entry points, the paths listed in its
package.jsonexports.
- Tests mirror source:
src/<path>.ts→test/unit/<path>.test.tspackages/<pkg>/src/<path>.ts→test/webview/<pkg>/<path>.test.ts
- Split a large suite by aspect as
<module>.<aspect>.test.ts, for examplefooManager.concurrent.test.ts. - A suite that tests several modules through a public API sits in the
closest folder those modules share. Suites that guard repo config, like
oxlintConfig.test.ts, sit at thetest/unit/root. - Test support code goes next to the tests that use it. Mocks shared
across folders go in
test/mocks/, and tested helpers intest/utils/.
- Electron process model and VS Code webviews: isolated renderers that talk to the privileged side only through messages
- VS Code source organization:
runtime-free
commoncode that both sides can use, with dependencies pointing one way - VS Code
base/common: topic modules with several functions each - Colocation (Kent C. Dodds)