Skip to main content

File structure

We recommend the following file structure:

My-App
├─ public // see nextjs documentation
│ ├─ locales
│ │ └─ en
│ │ │ └─ translation.json // locales in english
│ │ └─ fr
│ │ │ └─ translation.json // locales in french
│ ├─ logo.svg
│ ├─ robots.txt
│ └─ ... // You are free to create your own structure

├─ src
│ ├─ components // folder containing all components but routes
│ │ ├─ myComponent // a folder is created for each standalone component (camelCase)
│ │ │ ├─ myComponentHeader // Each slave component has its own folder
│ │ │ │ └─ ... // Same structure as myComponent folder
│ │ │ ├─ index.js // a file that export MyComponent
│ │ │ ├─ MyComponent.module.css // Optional: the CSS of the component (PascalCase)
│ │ │ ├─ MyComponent.js // The component itself (PascalCase)
│ │ │ └─ MyComponent.test.js // Unit tests of the component (PascalCase)
│ │
│ ├─ css
│ │ └─ app.css // see nextjs documentation
│ │
│ ├─ layout // folder containing all layouts
│ │ ├─ siteLayout // a folder is created for each standalone component (camelCase)
│ │ │ ├─ Header // Each slave component has its own folder
│ │ │ │ └─ ... // Same structure as SiteLayout folder
│ │ │ ├─ index.js // a file that export SiteLayout
│ │ │ ├─ SiteLayout.module.css // Optional: the CSS of the component (PascalCase)
│ │ │ ├─ SiteLayout.js // The component itself (PascalCase)
│ │ │ └─ SiteLayout.test.js // Unit tests of the component (PascalCase)
│ │
│ ├─ pages // folder containing all pages. Pages are the entry points (see nextjs doc)
│ │ ├─ [lang]] // a folder is created for each top route
│ │ │ ├─ users // a folder is created for each top route
│ │ │ │ ├─ [id] // Dynamic route, see nextjs documentation
│ │ │ │ │ ├─ edit.js //edit user page /users/:id/edit
│ │ │ │ │ └─ index.js //view user page /users/:id
│ │ │ │ ├─ index.js // list all users page /users
│ │ │ │ └─ new.js // new user page /users/new
│ │ ├─ _app.js // the wrapper component common to all pages that bootstraps the App (<NextApp />)
│ │ └─ index.js // the index page /. Redirect to the correct locale
│ │
│ ├─ utils // a folder to contain any utility code. You are free to create your own structure
│ │ ├─ string.js
│ │ └─ ...
│ │
│ └─ settings.js // a central file to configure your app

├─ .env.development // contain variables specific to the DEV environement
├─ .env.development.local // contains sensitive data (not commited on GIT)
├─ .gitignore
├─ next.config.js // not mandatory. Specific configuration for nextjs
├─ package.json
├─ postcss.config.js // not mandatory. Only present if postcss is used
├─ README.md
├─ yarn.lock