You are
You will start from the basics concepts of Nextjs then you will grow up by learning responsive design with TailwindCss and Nextjs from a Figma Design template and so much more.
This is how the project looks:
Throughout this course, you will improve your technical frontend skill set such as:
-
Proficiency in JavaScript (ES6+), React.js, and Next.js framework.
-
Knowledge of React Components, State Management, and Hooks;
-
Experience with server-side rendering (SSR), static site generation (SSG), client-side rendering, etc.;
-
Experience with RESTful APIs and efficient methods of requesting data from backend servicesetc...;
-
Experience with CSS Framework (Tailwindcss) and the principles of responsive web design;
-
Experience with version control systems (Git)
-
Experience with testing frameworks (Jest,React testing library, Cypress) and experience with code quality tools;
-
Basic knowledge of web performance optimization techniques and the principles of an accessible web.
This tutorial assumes knowledge of HTML, CSS, JavaScript, and no knowledge of React or NextJs.
-
Before you start this course, make sure you have the following installed:
-
Node.js 20.12.0 or later installed.
-
Operating systems: macOS, Windows (including WSL), or Linux.
-
VSCode or another text editor of your choice.
The project contains all Next.js App Router pages and layouts, and takes care of the routing.
.
├───actions
├───app
│ └───(website)
│ ├───(auth)
│ │ ├───sign-in
│ │ │ └───[[...sign-in]]
│ │ └───sign-up
│ │ └───[[...sign-up]]
│ └───(pages)
│ ├───(home)
│ ├───account
│ │ ├───address
│ │ ├───dashboard
│ │ └───orders
│ ├───cart
│ ├───categories
│ │ └───[slug]
│ │ └───products
│ ├───checkout
│ ├───order
│ │ └───[id]
│ └───products
│ └───[slug]
├───components
│ ├───custom
│ ├───modules
│ │ └───website
│ │ ├───account
│ │ ├───cart
│ │ ├───categories
│ │ ├───Chechout
│ │ ├───footer
│ │ ├───header
│ │ ├───home
│ │ ├───order
│ │ ├───Product
│ │ ├───products
│ │ └───review
│ └───ui
├───constants
├───cypress
│ ├───e2e
│ ├───fixtures
│ ├───pages
│ ├───selectors
│ └───support
├───data
├───hooks
├───lib
├───providers
├───public
│ └───assets
│ └───images
├───store
├───types
└───_tests_
└───ui
This structure enables efficient routing and organization of different parts of the app.
This folder contains asynchronous functions that are executed on the server. They can be called in Server and Client Components to handle form submissions and data mutations in Next.js applications.
This folder is the Root directory of the app. it is also known as the app router. It supports shared layouts, nested routing, loading states, error handling, and more.
(website)
├───(auth)
│ │ layout.tsx
│ │
│ │
│ ├───sign-in
│ │ └───[[...sign-in]]
│ │ page.tsx
│ │
│ └───sign-up
│ └───[[...sign-up]]
│ page.tsx
│
└───(pages)
│ │ layout.tsx
│ │
│ │
│ ├───(home)
│ │ page.tsx
│ │
│ ├───account
│ │ │ layout.tsx
│ │ │
│ │ │
│ │ ├───address
│ │ │ page.tsx
│ │ │
│ │ ├───dashboard
│ │ │ page.tsx
│ │ │
│ │ └───orders
│ │ page.tsx
│ │
│ ├───cart
│ │ page.tsx
│ │
│ ├───categories
│ │ └───[slug]
│ │ └───products
│ │ page.tsx
│ │
│ ├───checkout
│ │ page.tsx
│ │
│ ├───order
│ │ └───[id]
│ │ page.tsx
│ │
│ └───products
│ │ page.tsx
│ │
│ └───[slug]
│ page.tsx
Next.js provides a set of special files to create UI with specific behavior in nested routes such as
That is shared between multiple routes. On navigation, layouts preserve state, remain interactive, and do not re-render. You can define a layout by default exporting a React component from a layout.js file. The component should accept a children prop that will be populated with a child layout (if it exists) or a page during rendering
By default, layouts are nested, which means they wrap child layouts via their children prop.
In Next js Errors can be divided into two categories: expected errors and unexpected exceptions: Expected errors can be handled with try or catch and UseActionState. But uncaught exceptions is handled by using error.tsx and global-error.tsx files
unexpected errors that indicate bugs or issues that should not occur during the normal flow of your application.
in other words, Next.js uses error boundaries to handle unexpected exceptions. it catches errors and shows a fallback UI instead of the component tree that crashed.
This is the main css file of the application. You can use this file to add CSS rules to all the routes in your application - such as CSS reset rules, site-wide styles for HTML elements like links, and more.
it allows you to create custom fonts with next/font. Next.js automatically optimizes fonts in the application when you use the next/font module. It downloads font files at build time there are no additional network requests for fonts which would increase performance.
The loading file is a special file that can be nested. it allows you to create fallback UI to show as a replacement while page content loads.
Next has some special files like manifest, robot , sitemap . Each file convention can be defined using a static file (e.g. manifest.xml), or a dynamic variant that uses code to generate the file for example manifest.ts
In the app directory, nested folders are normally mapped to URL paths. However, you can mark a folder as a Route Group to prevent the folder from being included in the route's URL path.
This allows you to organize your route segments and project files into logical groups without affecting the URL path structure. A route group can be created by wrapping a folder's name in parenthesis like this: (folderName)
This folder contains all the routes and javascript files needed to build frontend app.
We have:
This group route is used to organize clerk authentification routes like sign-in and sign-up
This group is used to organize all frontend routes
this folder contains three folders custom, modules and ui
- Custom directory
this folder contains react components which are independent and reusable.
- Module directory
This folders contains wrapper components: A wrapper components are components that surround unknown components and provide a default structure to display the child components.
- ui directory
This folders contains react components which are independent and reusable created by a third party like shadcn UI
We use this folder to create static constantes
This is the directory that Jest will use to look up tests.
This is the root directory where Cypress-related files and folders are stored.
├───e2e
├───fixtures
├───pages
├───selectors
└───support
- e2e directory
This directory is where you should place your test files. Cypress will automatically detect and run tests from this folder. Test files typically have .spec.ts or .test.ts file extension.
- fixtures directory
You can use this directory to store static data or fixture files that your tests might need, such as JSON, CSV, or text files.
- pages directory
You can use this directory to create object page models. The Page Object Model (POM) is a design pattern commonly used in software testing, specifically in the context of test automation for web applications. It helps in creating an organized and maintainable structure for test scripts by encapsulating the details of the web pages and their elements.
- selectors directory
You can use this directory to group all selector for every pages for testing. each file contains all selectors needed to perform test for a specific page
this folders contains all custom hooks which will be used on client components
this folder contains all the utility functions.
This folder is kind of root folder for third party library. it is used to wrap all those libraries which is needed throughout the app
This folder serve static assets, like images, fonts files.
This folder contains state management files for redux toolkit.
all types we are going to create should be stored in that folder
Next.js comes with built-in support for environment variables, which allows you to create multiple environments variables :
Next.js allows you to set defaults in .env (all environments), .env.development (development environment), and .env.production (production environment) .env.testing (production environment).
-
gitignore
-
babel.config
-
cypress.config
-
eslint.config
-
jest files
jest.config.ts is the default jest config file : it defines Jest configurations.
on the other hand jest.setup.ts configuration which are supposed to run before every test case.
middleware
next.config
package-lock
postcss
README
tailwind
tsconfig
To spin up this example loccaly, follow these steps
Use the git clone
CLI to clone template directly to your machine
npm install
-
Environment Setup
Create a env file on the root of project PUT THIS INSIDE
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_API_URL=https://fractal-api-zeta.vercel.app
# Clerk integration
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
# Stripe integration
NEXT_PUBLIC_STRIPE_CLIENT_KEY=
STRIPE_SECRET_KEY=
-
Project Folders & Files Structure
-
Setup Eslint & typscript
-
Setup Jest
# create jest config file
npm init jest@latest
npm install --save-dev jest jest-environment-jsdom @testing-library/dom @testing-library/jest-dom
npm install --save-dev @testing-library/react@latest --legacy-peer-deps
#Add to script in package json
"test": "jest",
"test:watch": "jest --watch"
#add this to jest.config
import nextJest from "next/jest.js";
# // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
const createJestConfig = nextJest({
dir: './',
})
# // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config)
# or
- Setup Cypress
#install
npm install cypress --save-dev
#add to pakage json
"start:test": "cross-env NODE_ENV=test && next build && next start",
"cypress:open": "cross-env NODE_ENV=test cypress open",
"cypress:start": "start-server-and-test 'npm run start:test' 3000 'npm run cypress:open' "
#lauch
npm run cypress:open
#Some files will be created;
#add base url localhost to cypress.config
baseUrl: "http://localhost:3000",
- Setup ShadCn and Some Libraries
#install
npx shadcn-ui@latest init
npm i framer-motion react-hot-toast react-icons
- Setup Frontend UI Kit ( Colors - Fonts - Container )
- Setup Container screens
screens: {
xs: "360px",
# => @media (min-width: 360px) { ... }
sm: "575px",
# => @media (min-width: 575px) { ... }
md: "768px",
# => @media (min-width: 768px) { ... }
lg: "1024px",
# => @media (min-width: 1024px) { ... }
xl: "1280px",
# => @media (min-width: 1280px) { ... }
"2xl": "1440px",
# => @media (min-width: 1536px) { ... }
"3xl": "1680px",
# => @media (min-width: 1536px) { ... }
"4xl": "1920px",
# => @media (min-width: 1536px) { ... }
},
- Setup layout for pages
import React from "react";
import Container from "@/components/custom/Container";
export default function layout() {
return (
<div className="border border-black">
<Container>set up responsive layout</Container>
</div>
);
}
- Setup padding for screens
import React from "react";
import Container from "@/components/custom/Container";
export default function layout() {
return (
<div className="border border-black">
<Container>set up responsive layout</Container>
</div>
);
}
- Setup colors
#inspirations website
https://tailwindcss.com/docs/customizing-colors
https://coolors.co
https://uicolors.app/create
- Create Home UI
- Header component
-
Create Product page UI
-
Create Product Detail UI
-
Create Cart UI
-
Create Checkout UI
-
Create Payment UI
-
Create Dashoard UI
-
Fixing bug
-
Test Jest
-
Test Cypress
-
Deploy