Skip to content

Directory Structure

Ken Jiang edited this page Aug 23, 2023 · 1 revision

Directory Structure

The repo follows a fairly standard structure for a Next.js app.

components/
lib/
pages/
    api/
public/
    fonts/
    imgs/
static/
styles/
    globals.css

components/

This is where all of the react components live. Components should have their own folders, e.g. components/Navbar/(NavbarItem.tsx, NavbarBadge.tsx., etc.). This was not enforced when the repo was started and should be refactored. Folders per component allows for grouping of subcomponents and allows for aliasing (naming things the same).

lib/

This contains any .ts utility files. Important ones are the Data Access Layer (DAL) files which separates data from the app. Any pure .ts file should be placed here, with the exception of API endpoints.

pages/

The Next.js page directory. Each file is a page on the website. Dynamic routes are placed in their own folder and denoted with square brackets, e.g. blogs/[id].tsx. This pattern follows the Next.js documentation almost word for word.

pages/api/

Instead of using express or axios or something similar, Next.js allows us to create routes with files. Any files placed in this folder will be considered an endpoint /api/FileName.

public/

Public assets such as images and fonts are placed in their respective folders here.

static/

Any static content files such as markdown documents should be placed here in their own directory

styles/

The only file that should be here is globals.css. This is a tailwind repo and thus most styling should be done using tailwind classes and custom classes in tailwind.config.js. Only place a selector here if you must.

Clone this wiki locally