peacecheejecake / next-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next.js starter

Kick off your project with this boilerplate.

πŸš€ Quick Start

git clone https://github.com/TokTokHan/next-init-2.0.git <Project Name>
cd <Project Name>
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              #
β”œβ”€β”€ apis                #
β”œβ”€β”€ models              #
β”œβ”€β”€ components          #
β”œβ”€β”€ hooks               # Custom hooks
β”œβ”€β”€ utils               #
β”œβ”€β”€ libs                #
β”œβ”€β”€ cypress             # Automated tests
β”œβ”€β”€ README.md           #
└── ...

Pages

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

.
β”œβ”€β”€ ...
β”œβ”€β”€ pages               #
β”‚   β”œβ”€β”€ apis            # 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            # μ•„μ΄μ½˜~
β”‚ β”œβ”€β”€ @Layout           # λ ˆμ΄μ•„μ›ƒ~
β”‚ β”œβ”€β”€ Select            #
β”‚ β”œβ”€β”€ Calendar          #
β”‚ └── ...               #
└── ...

Container

Components are independent and reusable bits of code.

.
β”œβ”€β”€ ...
β”œβ”€β”€ containers                  # containers에 ν•˜μœ„ 폴더듀은 pages와 1:1 맀칭
β”‚ β”œβ”€β”€ login                     #
β”‚ β”‚  β”œβ”€β”€ _fragments             # _fragmentλŠ” Login νŽ˜μ΄μ§€μ—μ„œλ§Œ μ‚¬μš©λ˜λŠ” μ»΄ν¬λ„ŒνŠΈ
β”‚ β”‚  β”‚  β”œβ”€β”€ LoginForm.tsx       # μ€‘λ³΅λ˜λŠ” κ²½μš°μ—λŠ” components ν΄λ”λ‘œ 이동
β”‚ β”‚  β”‚  └── Intro.tsx           #
β”‚ β”‚  β”œβ”€β”€ Login.tsx              #
β”‚ β”‚  β”œβ”€β”€ LoginContainer.tsx     # LoginContainer μ—μ„œ λͺ¨λ“  λ‘œμ§μ— λŒ€ν•œ λΆ€λΆ„λ“€ μž‘μ—… (state, props)
β”‚ β”‚  └── index.tsx              #
β”‚ β”œβ”€β”€ home                      #
β”‚ └── ...                       #
└── ...

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            #
β”‚   └── ...
└── ...

Generated

Generated files such as apis, components, ...

.
β”œβ”€β”€ ...
β”œβ”€β”€ generated         If you run generate-script, it will be created
β”‚ β”œβ”€β”€ apis            # by swagger-typescript-api
β”‚ β”œβ”€β”€ mock         # by orval
└── ...
  • generate apis
  1. set config about gen_api on your .env

  2. script

    npm(or yarn) run gen:api
    
  3. usage mock data

    mock-data-path: /generated/mock/[filename].msw
    mock-data: Use Function "~Mock"
    network-mocking: Use function "~MSW" and set on "_App.ts"
    

    mock-data by orval, faker, msw api-data by swagger-typescript-api

Cypress

Automated tests with cypress.

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

Scripts

there is useful scripts in package.json

  • yarn run gen:api
    • swagger => axios-api, react-hook, mock-data
  • yarn run gen:icon
    • svg => chakra-icon

see more README.md

πŸ“› 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';
    
    
    
    
    /
    import ReservationCard from './ReservationCard';
    
    
    //
    const ReservationItem = <ReservationCard />;
    
    
    // g
    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

About


Languages

Language:TypeScript 82.3%Language:JavaScript 17.6%Language:Shell 0.1%