- Notifications
You must be signed in to change notification settings - Fork1
modularcode/modular-styleguide
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An opinonated guide about how to organize your app code in modular way
UsePascalCase for the component-related filenames and their directories, usecamelCase for the rest of the files.
# Badsrc/ Main.js someComponent/ someComponent.jsx# Goodsrc/ main.js otherNonComponentFile.js SomeComponent/ SomeComponent.jsxThere can be an exceptions for this rule though when declaring TypeScript interfaces
# badsrc/ user.ts# goodsrc/ User.ts# even bettersrc/ _types/ User.ts# Badsrc/ SomeComponent/ SomeComponent.js# Goodsrc/ SomeComponent/ SomeComponent.tsxsrc/ SomeComponent/ SomeComponent.jsx# Badsrc/ someFile.js someFileTest.js SomeComponent/ SomeComponent.jsx SomeComponentTest.jsx# Goodsrc/ someFile.js someFile.spec.js SomeComponent/ SomeComponent.jsx SomeComponent.spec.jsx# BadButton/Dropdown/Footer/Header/Icon/Sidebar/Typography/# GoodBaseButton/BaseDropdown/BaseIcon/BaseTypography/TheFooter/TheHeader/TheSidebar/# GoodAppFooter/AppHeader/AppSidebar/BaseButton/BaseDropdown/BaseIcon/BaseTypography/# Badsrc/ config/ layouts/ OtherComponent/ services/ SomeComponent/ styles/# Goodsrc/ _config/ _layouts/ _services/ _styles/ OtherComponent/ SomeComponent/In the bad example we need to spend more time figuring out what type of directories are responsible for which things. Also the ordering is messed up, we have organizational directories likeservices/ in between two component directories.
In contrast in the good example we can immediately visually distinguish ComponentDirectories from non-component directories. The IDEs will show the directories with underscore on top of the project file explorer which is very convenient.
# Badsrc/ assets/ MyComponentRelatedImg.svg MyComponent/ MyComponent.jsx styles/ MyComponent.scsstests/ unit/ MyComponent.spec.jsxstorybook/ MyComponent.stories.mdx# Goodsrc/ MyComponent/ MyComponent.jsx MyComponent.scss MyComponent.spec.jsx MyComponent.stories.mdx MyComponentRelatedImg.svg# Goodsrc/ MyComponent/ _tests/ MyComponentMocksData.jsx MyComponentMocks.jsx MyComponent.spec.jsx MyComponent.jsx MyComponent.scss MyComponent.stories.mdx MyComponentRelatedImg.svgIn the bad example the component related files are scattered across the project directories, so when working on that component we will have to jump back and forth through directories which is super inefficient.
In contrast in the good example all the files related to the component are under the hand, which makesMyComponent more maintainable and self-contained.
# Badsrc/ components/ BaseButton.jsx TheHeader.jsx# Badsrc/ components/ BaseButton/ BaseButton.jsx TheHeader/ TheHeader.jsx# Goodsrc/ _components/ BaseButton/ BaseButton.jsx TheHeader/ TheHeader.jsx# Goodsrc/ _common/ BaseButton/ BaseButton.jsx TheHeader/ TheHeader.jsx# Badsrc/ components/ Button/ Title/ pages/ AuthPage/ AuthLoginPage/ AuthSignupPage/ BlogPage/ BlogArticlesPage/ BlogArticlePage/ BlogArticleEditPage/ DocsPage/ TutorialPage/ TutorialItemPage/ templates/ Header/ Sidebar/ Footer/ utils/ auth.js# Goodsrc/ _common/ BaseButton/ BaseTitle/ TheHeader/ TheSidebar/ TheSidebar/ AuthPage/ _common/ AuthHeader/ _services/ authService.js AuthLoginPage/ AuthSignupPage/ BlogPage/ BlogListPage/ BlogItemPage/ BlogEditorPage/ DocsPage/ TutorialsPage/ TutorialsListPage/ TutorialsItemPage/About
Guide how to organize your app code in modular way
Resources
Uh oh!
There was an error while loading.Please reload this page.