-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

React Application Architecture for Production
By :

Next.js is a web framework built on top of React and Node.js, allowing us to build web applications. Because it can run on the server, it can be used as a full-stack framework.
Using Next.js has multiple benefits. We want to use it because of several reasons:
Besides the challenges of setting up the project, it is very challenging to maintain all those dependencies over time. Next.js hides all those complexities away from developers and allows them to get started quickly with a new project.
We will be using different strategies based on the application’s needs.
That sums up why we want to use Next.js for our application. Now, let’s see what the Next.js application structure looks like.
The easiest way to get started with Next.js is to use the create-next-app
CLI to generate a new application.
Since we have already generated the application as part of the code samples, we do not need to use the CLI, but if we were generating the application from scratch, we would execute the following command:
npx create-next-app@latest jobs-app --typescript
By executing this command, we would generate a new Next.js application with TypeScript configured out of the box.
There are a couple of things that are specific to Next.js. Let’s look at the following file and folder structure of a simple Next.js application:
- .next - public - src - pages - _app.tsx - index.tsx - next.config.js - package.json
Let’s analyze each file and folder one by one:
.next
: Contains production-ready files generated by running the build
command of Next.js.public
: Contains all static assets of the application.src/pages
: This is a special folder in Next.js where all pages defined here become available at corresponding routes. This is possible thanks to the filesystem-based routing system. The pages
folder can also live in the root of the project, but it is nice to keep everything in the src
folder.src/pages/_app.tsx
: The _app.tsx
file is a special file that exports a React component that wraps every page when rendered. By wrapping pages with this special component, we can add custom behavior for our application, such as adding any global configurations, providers, styles, layouts, and more to all the pages.src/pages/index.tsx
: This is how we declare pages of the application. This shows how the root page is defined. We will dive into Next.js-specific routing in the upcoming chapters.next.config.js
: This is where we can extend the default functionalities such as Webpack configuration and other things in a simple way.package.json
: Every Next.js application includes the following npm scripts:dev
: Starts a development server on localhost:3000
build
: Builds the application for productionstart
: Starts the production build on localhost:3000
We will cover more on these topics in the following chapters, but for now, this should give us enough information to get started with Next.js.