Get startedProject Structure

Project Structure

Runway follows a typical Next.js project structure with some custom organization. Here's an overview of the main directories and files:


Top-level Structure

At the root of the project, you'll find these key elements:

Folder/FileDescription
src/Contains all the application source code
public/Stores static assets to be served directly
.env.localHolds local environment variables
package.jsonLists project dependencies and scripts

The src folder contains all of our application code, while public is for static assets. The .env.local file stores all our local environment variables (API keys, etc.).


Warning!

Never commit your .env.local file to version control. It contains sensitive information like API keys and should be kept private.



src Folder Structure

Inside the src folder, we organize our code into several directories:

PathDescription
appContains the Next.js 13+ App Router structure
componentsHouses React components organized by atomic design
contextsStores React context providers for global state management
libsContains shared libraries and utilities (e.g., Stripe, Mailgun)
utilsHolds utility functions used across the application

This structure allows for a modular approach to development, separating concerns and making it easier to find and maintain different parts of the application.

Check out the Components documentation for more information on the atomic design methodology.


Info

The src folder is optional in Next.js, but it's a good practice for keeping your project root clean and organized.



app Directory Structure

The app directory is the heart of our Next.js application, structured as follows:

PathDescription
(auth)Contains routes that require user authentication
(noauth)Houses public routes accessible without authentication
actionsStores server actions for handling form submissions and data mutations
apiContains API routes for backend functionality
authHolds authentication-related files and logic
libStores library files specific to the app directory

This structure leverages Next.js 13's app router, allowing for easy organization of authenticated and public routes.

Tip!

Use route groups (folders starting with parentheses) to organize your routes without affecting the URL structure.


(noauth) Directory

The (noauth) directory contains our public-facing pages:

PathDescription
docsDocumentation pages for users and developers
loginThe user login page
policiesLegal pages such as privacy policy and terms of service
sign-upThe user registration page

(auth) Directory

The (auth) directory contains our authenticated pages, add as many as needed.


Info

Runway automatically redirects users to the login page if they try to access an authenticated route without being logged in.



components Directory

We use the atomic design methodology to organize our React components:

PathDescription
atomsBasic building blocks like buttons, inputs, and labels
moleculesSlightly more complex components composed of atoms
organismsLarge, complex components often composed of molecules and atoms

This structure promotes reusability and maintainability of our UI components.


Tip!

When creating new components, consider their reusability. If a component is used in multiple places, it might belong in the atoms or molecules directory.



Configuration Files

Key configuration files in our project:

PathDescription
src/config.jsCentral configuration file for application-wide settings
src/middleware.jsNext.js middleware for route protection and redirects

These files are crucial for managing application behavior and security.




app Routing Conventions

We follow Next.js routing conventions in our app directory:

FileDescription
layout.js .jsx .tsxDefines the layout for a route segment
page.js .jsx .tsxRepresents a UI that is unique to a route
loading.js .jsx .tsxCreates loading UI for a segment
not-found.js .jsx .tsxCreates not found UI for a segment
error.js .jsx .tsxDefines error UI for a segment
route.js .tsCreates API endpoints

These conventions allow for intuitive and powerful routing capabilities within our Next.js application.

Tip!

Use loading.js to create seamless loading experiences for your users. It's automatically used by Next.js for route segments.

Warning!

Be cautious when using route.js in the same directory as page.js. They can conflict and lead to unexpected behavior.


This structure allows for a clear separation of concerns, making it easier to navigate and maintain the project as it grows. For more detailed information on specific parts of the project, refer to the related documentation pages.