-
Notifications
You must be signed in to change notification settings - Fork 0
Project structure and conventions
This is a ruleset that defines guides of a project structure management. Why does it exist? There are several reasons for that:
- It is easier for teammates to help if you follow the common structure
- It helps us to perform a code review and ensure the highest quality of your code
- It implements the leading and proven software engineering practices
There are several generic, vague rules that put other things in structure. All other rules and minor things would be easy to understand if you remember those.
Create single-responsibility, open to extension, closed for modification, replaceable components with specific interfaces that depend on abstractions. That's what the SOLID principle does. Ignore this approach right after you master it.
Do not write code if you can. Take something that is written, re-use, override. 99% of challenges were solved by others previously.
If you copy something, read the documentation and understand how it works. No need to dive into details, but you need to understand the purpose and the outcomes of everything that's copied.
Do not create structures if you can. Do not create a folder if there are only 1-2 files in it.
If you follow logic, follow it everywhere. If the logic doesn't work, come up with another one that covers all cases or states that there is no logic behind it.
The basic project level would look like this:
projectname
├── (.files) – config files you don't need to touch
├── node_modules – installed modules, no need to touch
├── packages – folder for all independent apps
│ ├── cms – content management app folder
│ └── website – front-end app folder
├── .env – main environment file
├── .env.dist – main environment template
├── package.json – project configurations and global scripts
├── README.md – project readme
├── LICENSE – license details
├── (*.lock files) – autogenerated files
└── (*.yaml files) – deployment and configs
Main notes:
- Most of the files on this level change rarely. If you write to a file here constantly, then there is a probability you are doing something wrong.
-
.envfile is your own local file that should not go to git. You can find more about.envfiles in this article -
.lockfiles are autogenerated. You can always delete and re-generate them in case you face conflicts.
The App level (cms, website, or something new) looks like this:
appname
├── (.folders) – temporary folders you can ignore
├── build – a folder with the generated build
├── node_modules – installed modules, no need to touch
├── src – your main folder
│ ├── components – a folder with all custom components
│ ├── graphql – a folder with all connectivity items
│ ├── types – a folder with all custom type definitions
│ ├── ... – other project-specific folders
│ └── index.tsx – app entry point
├── .env – main environment file
├── .env.* – environment templates
├── Dockerfile – containerization instructions for further deployment
├── package.json – app configurations and global scripts
├── README.md – app readme
├── tsconfig.json – app typescript settings, don't touch
└── vite.config.ts – app building config
Notes:
- You would find some app-specific files here and there, because of each app specifics.
- `.env' file should be created manually followed by instructions.
-
package.jsonis the main place to add npm packages, run scripts, etc. -
README.mdshould answer questions on what app does and how to run it. - We strongly advise understanding how the app is compiled by reading the
vite.config.tsfile.
The source code level (src) for a front-end app looks like this:
src
├── components – a folder with all custom components
│ ├── app – base single-page app component
│ │ ├── index.less – base CSS container that implements Ant styles and overrides
│ │ └── index.tsx – generic app code
│ ├── layouts – layouts folder
│ │ ├── index.tsx – container for exporting
│ │ ├── <CompName>.tsx – layout code
│ │ ├── <CompName>.less — layout styles
│ │ └── assets — layout assets
│ ├── <compname> – custom component you are coding
│ │ ├── <CompName>.tsx – custom component code
│ │ ├── <CompName>.less — custom component styles
│ │ └── assets — custom component assets
│ └── ... — your other component folders
├── graphql – a folder with all connectivity items
│ ├── fragments – graphql fragments go here
│ ├── mutations – graphql mutations go here
│ ├── queries – graphql queries go here
│ └── index.tsx – autogenerated, do not touch
├── types – a folder with all custom type definitions
│ └── <type>.d.ts – type definition for TS autocomplete
├── pages – a folder to keep all pages
│ └── <pagename> – a folder for a page
│ ├── index.tsx – page implementation
│ └── (something).tsx – additional page related items (hooks, contexts)
├── index.tsx – app entry point
└── index.less – container for app-level variables
Notes:
- Keep
componentsandpagesfolders flat, do not create a folder with folders inside.
- Files should be named with
lowerCamelCaseconvention - Component files should be named with
UpperCamelCaseconvention -
.lessfile should have the same name as.tsxfile