Structuring A Large-Scale Application With Next - Js 13 - App Router - by Mohammed Poolwala - Medium
Structuring A Large-Scale Application With Next - Js 13 - App Router - by Mohammed Poolwala - Medium
253 5
Once again, it’s 5 in the morning, and here I am. Since I began learning
ReactJS, I’ve developed a bit of an obsession with folder structure and
naming conventions. I’ve faced numerous failures in this area; my GitHub
repository is essentially a graveyard for those unsuccessful projects.
However, I believe I’ve finally cracked the code.
I’ve created couple projects that adhere to this specific folder structure, and
I’ve grown quite comfortable with it. I assume that you are using Next.js 14^,
with the app directory, server actions, TypeScript, and Tailwind. I’ll keep it
short; here we go 👇
Quick Disclaimer
The presented approach should not be regarded as the definitive or
mandatory method for establishing a folder structure. While it has proven
effective in my own experience, it is important to acknowledge that the
organization of folders may not always adhere to a fixed or immutable
framework. Its suitability is contingent upon the specific project
requirements and the technology stack employed.
This is the folder three that i use most of the NextJS projects. Here is the
descriptions of some of the folders:
Open in app
App Folder
Search Write
This folder is the main feature of Next.js 13. You can handle all the page and
API routes within this folder. I prefer to create a separate folder named “api”
for API routes. I feel more organized this way. There is tons of options that
you can use in the “app” folder. Fore detailed information, take a look at the
offical NextJS documantation.
Actions Folder
Server actions are the experimental feature (hello from future, now it’s
stable) that provides a built-in solution for server mutations. You may use
server-side form action within this folder. For more information, vist the
offical docs!
Components Folder
I believe there’s no need for an elaborate description, I suppose xD. The only
point I would like to make is that you can include “style” and “test” files
within a component folder. In this particular case, I prefer to maintain them
in separate folders.
Containers Folder
Well, I especially want to talk about the ‘containers’ folder. This folder
essentially serves as a container for your route sections. For example, in the
‘hero-section’ folder, I have an ‘index.tsx’ file, and this file represents a
‘section’ on my home page. With this way, you may have more control over
your page sections.
And you can render those sections in the associated ‘page.tsx’ file like this:
DB Folder
You may choose to place the database configuration inside the ‘libs’ folder, I
guess? I have optionally decided to store the database configurations in a
separate folder named ‘db’.
Store Folder
This folder serves as the repository where I store my global states. In this
project, I have employed Zustand. You have the option to utilize libraries
such as Redux or manage your files within this folder as per your preference.
Types Folder
Indeed, the nomenclature of this folder aligns with its intended purpose.
Within, I have housed all the TypeScript types that are employed throughout
the project.
And with that, we conclude this discussion. It’s worth emphasizing that this
particular “structure” is by no means obligatory. The arrangement of folders
is contingent upon the specific project and technology stack in use.
Example Project
And also here is a example project that i recently made with using this file
structure: 🔗 Lalasia
Thank you for reading, i hope that helps!
My GitHub: Link
My Website: Link
46 Followers
Nextjs 14 Offline Page with PWA Automate Your NextJS API Routes
Time for an exciting update! In this session, With Vercel Cron Jobs
we’ll explore the customization of the ‘offline’… Hey there, again. Today, i want to introduce
you Vercel Cron Jobs and how you can use it…
19 11
8 min read · Oct 10, 2023 4 min read · Oct 16, 2023
54 1 59 1
Lists
Haseeb Jenifar
The best way to fetch data in React Next.js 14: Server Actions
and Next.js Are you tired of slow, clunky data fetching and
In the world of web development, making mutations in your Next.js app? Enter server…
HTTP requests is a fundamental task.…
28 1 10
603 1 37 1