Next.js starter

Kick off your project with this boilerplate.

πŸš€ Quick Start

git clone
cd
yarn install
yarn run dev

your site is now running at http://localhost:3000

πŸ“ Folder Structure

A quick look at the directories you'll see in this project.

Root driectory layout

.
β”œβ”€β”€ pages               #
β”œβ”€β”€ public              #
β”œβ”€β”€ styles              #
β”œβ”€β”€ api                 #
β”œβ”€β”€ components          #
β”œβ”€β”€ context             # (alternatively `store`)
β”œβ”€β”€ hooks               # Custom hooks
β”œβ”€β”€ utils               #
β”œβ”€β”€ libs                #
β”œβ”€β”€ cypress             # Automated tests
β”œβ”€β”€ README.md           #
└── ...

Pages

Each page is associated with a route based on its file name.

.
β”œβ”€β”€ ...
β”œβ”€β”€ pages               #
β”‚   β”œβ”€β”€ api             # API endpoint
β”‚   β”œβ”€β”€ _app.tsx        # App component to initialize pages
β”‚   β”œβ”€β”€ _document.tsx   # Custom document to augment application's <html> and <body> tags
β”‚   └── ...
└── ...

Public

Next.js can serve static files, like images, under a folder called public in the root directory.

.
β”œβ”€β”€ ...
β”œβ”€β”€ public              #
β”‚   β”œβ”€β”€ favicons        #
β”‚   └── ...
└── ...

Styles

Css, theme configuration files are placed into this folder.

.
β”œβ”€β”€ ...
β”œβ”€β”€ styles              #
β”‚   β”œβ”€β”€ theme.tsx       #
β”‚   └── ...
└── ...

Api

Api call related functions.

Components

Components are independent and reusable bits of code.

.
β”œβ”€β”€ ...
β”œβ”€β”€ components          #
β”‚ β”œβ”€β”€ icons             #
β”‚ β”œβ”€β”€ atoms             #
β”‚ β”œβ”€β”€ molecules         #
β”‚ β”œβ”€β”€ organisms         #
β”‚ └── templates         #
└── ...

Context

Context provides a way to pass data through the component tree without having to pass props down manually at every level. (just like redux)

.
β”œβ”€β”€ ...
β”œβ”€β”€ context             #
β”‚   β”œβ”€β”€ auth            #
β”‚   └── ...
└── ...

Hooks

Custom hook allows you to extract some components logic into a reusable function that starts with use and that call can other hooks.

.
β”œβ”€β”€ ...
β”œβ”€β”€ hooks                #
β”‚   β”œβ”€β”€ useScript.tsx    #
β”‚   └── ...
└── ...

Utils

Small snippets you can use throughout the application. Short and specific functions and constants used throughout application.

Libs

Libraries you can use throughout the application. A library is a JavaScript file that contains a bunch of functions, and those functions accomplish some specific purpose.

.
β”œβ”€β”€ ...
β”œβ”€β”€ libs                  #
β”‚   β”œβ”€β”€ gtm.ts            #
β”‚   └── ...
└── ...

Cypress

Automated tests with cypress.

.
β”œβ”€β”€ ...
β”œβ”€β”€ cypess                #
β”‚ β”œβ”€β”€ fixtures            # Fixed data sets
β”‚ β”œβ”€β”€ integration         # End-to-end, integration tests (alternatively `e2e`)
β”‚ β”œβ”€β”€ plugins             #
β”‚ β”œβ”€β”€ support             #
└── ...

πŸ“› Naming

πŸ‘¨β€πŸ¦³ React Component

  • Extensions: Use .tsx extension for React components.

  • Filename: Use PascalCase for filenames. E.g., ReservationCard.tsx.

  • Reference Naming: Use PascalCase for React components and camelCase for their instances.

    // bad
    import reservationCard from './ReservationCard';
    
    // good
    import ReservationCard from './ReservationCard';
    
    // bad
    const ReservationItem = <ReservationCard />;
    
    // good
    const reservationItem = <ReservationCard />;
  • Component Naming: Use the filename as the component name. For example, ReservationCard.tsx should have a reference name of ReservationCard. However, for root components of a directory, use index.tsx as the filename and use the directory name as the component name:

    // bad
    import Footer from './Footer/Footer';
    
    // bad
    import Footer from './Footer/index';
    
    // good
    import Footer from './Footer';

πŸͺ Others

Always use camelCase for others.

  • scripts
  • folders
  • variables
  • functions

⭐️ Stack

  • Framework: Next.js
  • State Management: React Query, Context API
  • Styling: Chakra-ui, Emotion
  • Forms: React Hook Form
  • Testing: Cypress

Reference