1
1
# Frontend
2
2
3
- This is a guide to help the Coder community and also Coder members contribute to
4
- our UI. It is ongoing work but we hope it provides some useful information to
5
- get started. If you have any questions or need help, please send us a message on
6
- our [ Discord server] ( https://discord.com/invite/coder ) . We'll be happy to help
3
+ Welcome to the guide for contributing to the Coder frontend. Whether you’re part
4
+ of the community or a Coder team member, this documentation will help you get
5
+ started.
6
+
7
+ If you have any questions, feel free to reach out on our
8
+ [ Discord server] ( https://discord.com/invite/coder ) , and we’ll be happy to assist
7
9
you.
8
10
9
11
## Running the UI
10
12
11
13
You can run the UI and access the Coder dashboard in two ways:
12
14
13
- - Build the UI pointing to an external Coder server:
14
- ` CODER_HOST=https://mycoder.com pnpm dev ` inside of the ` site ` folder. This is
15
- helpful when you are building something in the UI and already have the data on
16
- your deployed server.
17
- - Build the entire Coder server + UI locally: ` ./scripts/develop.sh ` in the root
18
- folder. This is useful for contributing to features that are not deployed yet
19
- or that involve both the frontend and backend.
15
+ 1 . Build the UI pointing to an external Coder server:
16
+ ` CODER_HOST=https://mycoder.com pnpm dev ` inside of the ` site ` folder. This
17
+ is helpful when you are building something in the UI and already have the
18
+ data on your deployed server.
19
+ 2 . Build the entire Coder server + UI locally: ` ./scripts/develop.sh ` in the
20
+ root folder. This is useful for contributing to features that are not
21
+ deployed yet or that involve both the frontend and backend.
20
22
21
- In both cases, you can access the dashboard on ` http://localhost:8080 ` . If you
22
- are running ` ./scripts/develop.sh ` you can log in using the default credentials.
23
+ In both cases, you can access the dashboard on ` http://localhost:8080 ` . If using
24
+ ` ./scripts/develop.sh ` you can log in with the default credentials.
23
25
24
26
### Default Credentials: ` admin@coder.com ` and ` SomeSecurePassword! ` .
25
27
26
- ## Tech Stack
28
+ ## Tech Stack Overview
27
29
28
30
All our dependencies are described in ` site/package.json ` but the following are
29
31
the most important:
30
32
31
- - [ React] ( https://reactjs.org/ ) as framework
33
+ - [ React] ( https://reactjs.org/ ) for the UI framework
32
34
- [ Typescript] ( https://www.typescriptlang.org/ ) to keep our sanity
33
35
- [ Vite] ( https://vitejs.dev/ ) to build the project
34
36
- [ Material V5] ( https://mui.com/material-ui/getting-started/ ) for UI components
@@ -40,64 +42,62 @@ the most important:
40
42
- [ Jest] ( https://jestjs.io/ ) for integration testing
41
43
- [ Storybook] ( https://storybook.js.org/ ) and
42
44
[ Chromatic] ( https://www.chromatic.com/ ) for visual testing
43
- - [ PNPM] ( https://pnpm.io/ ) as package manager
45
+ - [ PNPM] ( https://pnpm.io/ ) as the package manager
44
46
45
47
## Structure
46
48
47
- All the code related to the UI resides in the ` site ` folder.
49
+ All UI-related code is in the ` site ` folder. Key directories include:
48
50
49
51
- ** e2e** - End-to-end (E2E) tests
50
52
- ** src** - Source code
51
53
- ** mocks** - [ Manual mocks] ( https://jestjs.io/docs/manual-mocks ) used by Jest
52
54
- ** @types ** - Custom types for dependencies that don't have defined types
53
55
(largely code that has no server-side equivalent)
54
- - ** api** - API code as function calls and types
56
+ - ** api** - API function calls and types
55
57
- ** queries** - react-query queries and mutations
56
- - ** components** - Generic UI components without Coder specific business logic
57
- - ** hooks** - React hooks that can be used across the application
58
- - ** modules** - Coder specific UI components
59
- - ** pages** - Page components
60
- - ** testHelpers** - Helper functions to help with integration tests
61
- - ** theme** - configuration and color definitions for the color themes
58
+ - ** components** - Reusable UI components without Coder specific business
59
+ logic
60
+ - ** hooks** - Custom React hooks
61
+ - ** modules** - Coder-specific UI components
62
+ - ** pages** - Page-level components
63
+ - ** testHelpers** - Helper functions for integration testing
64
+ - ** theme** - theme configuration and color definitions
62
65
- ** util** - Helper functions that can be used across the application
63
- - ** static** - Static UI assets like images, fonts, icons, etc
66
+ - ** static** - Static assets like images, fonts, icons, etc
64
67
65
68
## Routing
66
69
67
70
We use [ react-router] ( https://reactrouter.com/en/main ) as our routing engine.
68
71
69
- - Authenticated routes - routes needing authentication should be placed inside
70
- the ` <RequireAuth> ` route. The ` RequireAuth ` component handles all the
72
+ - Authenticated routes - Place routes requiring authentication inside the
73
+ ` <RequireAuth> ` route. The ` RequireAuth ` component handles all the
71
74
authentication logic for the routes.
72
75
- Dashboard routes - routes that live in the dashboard should be placed under
73
76
the ` <DashboardLayout> ` route. The ` DashboardLayout ` adds a navbar and passes
74
77
down common dashboard data.
75
78
76
79
## Pages
77
80
78
- Pages are the top-level components of the app. The page component lives under
79
- the ` src/pages ` folder and each page should have its own folder to better group
80
- the views, tests, utility functions and so on . The code is structured so that a
81
- page component is responsible for fetching all the data and passing it down to
82
- the view. We explain this decision a bit better in the next section.
81
+ Page components are the top-level components of the app and reside in the
82
+ ` src/pages ` folder. Each page should have its own folder to group relevant
83
+ views, tests, and utility functions . The page component fetches necessary data
84
+ and passes to the view. We explain this decision a bit better in the next
85
+ section.
83
86
84
- > ℹ️ Code that is only related to the page should live inside of the page folder
85
- > but if at some point it is used in other pages or components, you should
86
- > consider moving it to the ` src ` level in the ` utils ` , ` hooks ` , ` components ` ,
87
- > or ` modules ` folder.
87
+ > ℹ️ If code within a page becomes reusable across other parts of the app,
88
+ > consider moving it to ` src/utils ` , ` hooks ` , ` components ` , or ` modules ` .
88
89
89
- ### States
90
+ ### Handling States
90
91
91
- A page usually has at least three states: ** loading** , ** ready** /** success** ,
92
- and ** error** , so always remember to handle these scenarios while you are coding
93
- a page. Visual testing is expected for these three states using a ` *.stories.ts `
94
- file.
92
+ A page typically has three states: ** loading** , ** ready** /** success** , and
93
+ ** error** . Ensure you manage these states when developing pages. Use visual
94
+ tests for these states with ` *.stories.ts ` files.
95
95
96
- ## Fetching data
96
+ ## Data Fetching
97
97
98
98
We use [ TanStack Query v4] ( https://tanstack.com/query/v4/docs/react/quick-start )
99
- to fetch data from the API. The queries and mutation should be placed inside of
100
- the api/queries folder.
99
+ to fetch data from the API. Queries and mutation should be placed in the
100
+ ` api/queries ` folder.
101
101
102
102
### Where to fetch data
103
103
@@ -143,10 +143,10 @@ export const WithQuota: Story = {
143
143
144
144
### API
145
145
146
- Our project utilizes [ axios] ( https://github.com/axios/axios ) as the HTTP client
147
- for making API requests. The API functions are centralized in
148
- ` site/src/api/api.ts ` . We leverage auto -generated TypeScript types derived from
149
- our Go server, which are located in ` site/src/api/typesGenerated.ts ` .
146
+ Our project uses [ axios] ( https://github.com/axios/axios ) as the HTTP client for
147
+ making API requests. The API functions are centralized in ` site/src/api/api.ts ` .
148
+ Auto -generated TypeScript types derived from our Go server are located in
149
+ ` site/src/api/typesGenerated.ts ` .
150
150
151
151
Typically, each API endpoint corresponds to its own ` Request ` and ` Response `
152
152
types. However, some endpoints require additional parameters for successful
@@ -177,9 +177,9 @@ export const updateWorkspaceVersion = async (
177
177
178
178
## Components and Modules
179
179
180
- Components should be atomic, generic and should not describe any specific
181
- business logic. Modules are similar to components except that they can be more
182
- complex and they do contain business logic specific to the product.
180
+ Components should be atomic, reusable and free of business logic. Modules are
181
+ similar to components except that they can be more complex and can contain
182
+ business logic specific to the product.
183
183
184
184
### MUI
185
185
0 commit comments