Estrutura de pastas, arquivos e projetos
TÓPICOS: projetos; pastas; testes; arquivos;
Pasta
- Pasta deve ser escrito em minúsculo.
- Ex: controllers
-
Em componentes e widgets a pasta fica em
maiúsculo
Arquivos
-
Arquivos que tenha significado como entity, service, repository, model devem ter o tipo como sufixo.
- Ex: cliente.entity.ts
- Ex: cliente-composto.ts
Exemplo
/root
/.next/
/components/
Button/
button.spec.jsx
button.styles.jsx
index.jsx
/constants/
theme.js
page.js
/contexts/
Locale/
index.js
Page/
index.js
/pages/
_app.jsx
_document.jsx
about.jsx
index.jsx
/providers/
Locale/
index.js
Page/
index.js
/public/
favicon.ico
header.png
/redux/
actions/
users/
index.js
products/
index.js
reducers/
users/
index.js
products/
index.js
store/
index.js
types/
index.js
/shared/
jsons/
users.json
libs/
locale.js
styles/
global.css
/widgets/
PageHeader/
index.jsx
\
.eslintignore
.eslintrc
.env
babel.config.js
Dockerfile
jest.config.js
next.config.js
package.json
README.mdDetalhes das pastas
- Pages, “pages/”: You’ll need to have a “pages/” directory, which behaves as a sort of one-to-one static router for your site. Each page will match a .js(x) file.
- Components, “components/”: A repository with all your individual components. Each in an individual directory. Meaning that, if you have a Button component, you’ll create a “components/Button/index.js(x)”.
- Store, “redux/”: Let’s assume you are connecting to a Redux store (it can easily be extrapolated to any other store software). In the root, I create a redux directory. In it, 4 more directories:
- Store/Actions, “redux/actions/”: For instance, “users” actions will prompt this structure: “redux/store/actions/users/index.js”.
- Store/Reducers, “redux/reducers/”: Following up the previous example, for “users”: “redux/store/reducers/users/index.js”.
- Store/Types, “redux/types/”: Depending on the size of your project you can have a single file or a file per role. However, in most cases, I just create a single “redux/store/types/index.js”. Store, “redux/store/”: This would be the actual store to be passed to your app: “redux/store/index.js”.
- Widgets, “widgets/”: A widget will essentially encapsulate several components, they essentially work as containers. A Page Header widget could be created in this file: “widgets/PageHeader/index.js(x)”.
- Constants, “constants/”: Regularly I prefer to enclose modules in separate directories, this is to keep related files in the same folder (tests, styles, storybook files) however since constants usually do not need tests, styles or additional files, I just create a file per constant group in this directory, such as “constants/themes.js” or “constants/ui.js”.
- Static files, “public/”: Any file placed inside this directory will be transferred to the root of the build, this usually works for static files, such as images, text files, etc.