From 13fc6f585489af07c85ef519bc3f6239c15fad69 Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Fri, 1 Nov 2024 17:49:25 +0000 Subject: [PATCH] [Dashboard] Docs: Adds basic code organization instructions (#5255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## PR-Codex overview This PR updates the `README.md` file for the `dashboard` application to include guidelines on code structure and style, particularly focusing on component organization and data fetching practices. ### Detailed summary - Added a section on code structure and style guide. - Specified that components should be placed in a `components` folder next to their respective app pages. - Clarified where to place reused components and low-level components. - Recommended using RSC for data fetching. - Suggested keeping data fetching functions in the same file as their components unless reused across multiple components. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- apps/dashboard/README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/README.md b/apps/dashboard/README.md index 71175f11e23..f9f9ffd7fd7 100644 --- a/apps/dashboard/README.md +++ b/apps/dashboard/README.md @@ -23,4 +23,17 @@ Some env vars can be overridden that are required for some external services to To define env vars please create a `.env` file based on the `.env.example` template at the root level of the project. This file is ignored by git so you can safely add it to your local copy of the project. -**Add your thirdweb clientID and secret key to build a basic functioning version of the site.** \ No newline at end of file +**Add your thirdweb clientID and secret key to build a basic functioning version of the site.** + +## Code Structure and Style Guide + +### Components +- Components should go in a `components` folder next to the app page they are used in. +- If a component is reused in multiple pages, it should go in the lowest level route folder it is used in. For example, if a chart component is used in all analytics subroutes `/analytics/...`, it should go in the `/analytics/components` folder. +- All low-level components such as buttons, inputs, etc. should be shadcn components found in `@/ui`. +- All composed components reused across all page routes are `blocks`, and should also go in the `@/ui` folder. + +### Data fetching +- Use RSC wherever possible. +- Write data fetching code in its own function in the same file as the component it is used in, not exported. +- If the same data fetching function is used in multiple components, place it in a file in an `api` folder at the lowest level possible (just like components). If you need to do this you probable aren't organizing your components properly.