Lesson 11 of 60 – React Native Project Structure
18%

React Native Project Structure

Understanding the project structure is important before developing large React Native mobile applications. A React Native project contains source code, configuration files, assets, dependencies and, depending on the workflow, native Android and iOS project files.

Note: The exact files and folders depend on whether you use Expo or the React Native Community CLI and which project template you select. In this lesson, we will focus on the common structure of an Expo-based React Native project and also understand where native files appear.

1. What is Project Structure?

Project structure means the way files and folders are organized inside an application.

A good structure makes it easier to find components, screens, assets, services and configuration files.

React Native Project
        ↓
Files + Folders
        ↓
Organized Application

2. Basic Expo Project Structure

my-first-app/
├── app/
├── assets/
├── node_modules/
├── package.json
├── app.json
└── ...

This is a simplified structure. The exact files depend on the Expo template and version used to create the project.

3. The app Folder

In Expo projects using file-based routing, the app directory can contain the application's routes and screens.

app/
├── index.tsx
├── about.tsx
└── profile.tsx

Each route file can represent a screen or route in the application.

4. index File

In a file-based routing project, an index file commonly represents the default route for a directory.

app/
└── index.tsx

For example, the index route can be used as the initial screen of an application.

5. Screen Files

Application screens can be organized into route files or separate screen components.

app/
├── index.tsx
├── login.tsx
├── profile.tsx
└── settings.tsx

This can represent screens such as Home, Login, Profile and Settings.

6. The assets Folder

The assets folder is commonly used for static resources such as images, icons and fonts.

assets/
├── images/
├── icons/
└── fonts/

Keeping static resources organized makes them easier to manage.

7. Images in assets

Images such as logos, profile pictures and application graphics can be stored inside the assets directory.

assets/
└── images/
    ├── logo.png
    ├── banner.png
    └── profile.png

A local image can then be loaded by the React Native Image component.

8. Using a Local Image

import {
    Image
} from "react-native";

<Image
    source={require("./assets/images/logo.png")}
    style={{
        width: 100,
        height: 100
    }}
/>

The exact relative path depends on the location of the component file.

9. node_modules Folder

The node_modules directory contains packages installed for the project.

node_modules/
    ↓
Installed Packages
    ↓
Application Dependencies

You normally should not edit files inside node_modules manually.

10. package.json

The package.json file is one of the most important files in a JavaScript or React Native project.

It can contain:

  • Project name
  • Project version
  • Scripts
  • Dependencies
  • Development dependencies
  • Project metadata

11. Dependencies

Dependencies are packages required by the application.

{
    "dependencies": {
        "react": "...",
        "react-native": "..."
    }
}

The exact versions depend on the project.

12. package-lock.json

npm projects can contain a package-lock.json file.

It records detailed dependency information used by npm to reproduce the project's installed dependency tree.

Tip: Do not manually edit the lock file unless you understand the effect of the changes.

13. app.json

Expo projects can use app.json for application configuration.

{
    "expo": {
        "name": "My App",
        "slug": "my-app"
    }
}

Configuration can include application information and platform-related settings.

14. app.config.js or app.config.ts

Expo projects can also use JavaScript or TypeScript configuration files when dynamic configuration is needed.

app.config.js

This allows configuration to be generated using JavaScript logic.

15. Components Folder

As an application grows, reusable UI components can be placed in a components folder.

components/
├── Header.js
├── Button.js
├── Card.js
└── StudentCard.js

Components can then be imported into screens.

16. Screens Folder

In projects that do not use route files as the main screen organization, a screens folder can contain screen components.

screens/
├── HomeScreen.js
├── LoginScreen.js
├── ProfileScreen.js
└── SettingsScreen.js

The exact structure depends on the navigation approach used by the project.

17. Services Folder

A services folder can contain reusable code for communicating with backend APIs.

services/
├── api.js
├── authService.js
└── studentService.js

This keeps API-related code separate from UI components.

18. Hooks Folder

Custom React Hooks can be organized in a hooks folder.

hooks/
├── useAuth.js
├── useFetch.js
└── useStudents.js

Custom Hooks help reuse stateful logic between components.

19. Context Folder

Context providers can be organized into a context folder.

context/
├── AuthContext.js
├── ThemeContext.js
└── AppContext.js

This can help organize shared application state.

20. Utils Folder

A utils folder can contain reusable helper functions.

utils/
├── validation.js
├── formatDate.js
└── constants.js

Utility functions should generally perform small reusable tasks.

21. Styles Folder

Larger applications may organize reusable style definitions in a styles folder.

styles/
├── colors.js
├── spacing.js
└── typography.js

This can help maintain consistent design across the application.

22. Constants Folder

Application-wide constant values can be stored separately.

constants/
├── colors.js
├── routes.js
└── config.js

For example, route names or reusable configuration values can be defined in one place.

23. Native Android Folder

React Native Community CLI projects normally contain an android directory.

MyApp/
└── android/

This directory contains the native Android project and its configuration.

Expo projects can also generate or use native directories when a native development workflow requires them.

24. Native iOS Folder

React Native Community CLI projects normally contain an ios directory.

MyApp/
└── ios/

This directory contains the native iOS project and its configuration.

Native iOS development requires macOS and Apple's development tools.

25. Metro Configuration

React Native uses Metro as its JavaScript bundler.

A project may contain a metro.config.js file when custom Metro configuration is required.

metro.config.js

Most beginners do not need to modify this file.

26. Babel Configuration

React Native projects can use Babel for transforming JavaScript and related source code.

Depending on the project template, you may see a file such as:

babel.config.js

The exact configuration depends on the project and tooling.

27. Recommended Large Project Structure

my-app/
├── app/
├── assets/
│   ├── images/
│   ├── icons/
│   └── fonts/
│
├── components/
├── screens/
├── services/
├── hooks/
├── context/
├── utils/
├── styles/
├── constants/
│
├── package.json
├── app.json
└── ...

This is an example organizational structure. You should adapt it to the requirements of your application rather than creating every folder from the beginning.

28. How Files Work Together

Screen
   ↓
Components
   ↓
Hooks / Context
   ↓
Services
   ↓
Backend API
   ↓
Database

For example, a Student screen can use a StudentCard component, call a custom Hook, use an API service and display the returned data.

29. Example Student App Structure

student-app/
├── app/
│   ├── index.tsx
│   ├── login.tsx
│   ├── students.tsx
│   └── profile.tsx
│
├── components/
│   ├── StudentCard.tsx
│   └── Header.tsx
│
├── services/
│   └── studentService.ts
│
├── hooks/
│   └── useStudents.ts
│
├── assets/
│   └── images/
│
├── package.json
└── app.json

This structure separates screens, reusable components, API logic, Hooks and assets.

30. Complete Project Structure Workflow

A well-organized React Native project can follow this general relationship:

Application
     ↓
Routes / Screens
     ↓
Reusable Components
     ↓
Hooks / Context
     ↓
Services / API
     ↓
Utilities
     ↓
Assets / Styles
     ↓
Configuration
     ↓
React Native Runtime
     ↓
Android / iOS

The most important rule is to keep related code organized and make each part of the application easy to locate and maintain.

📌 Key Points

  • The project structure organizes the files and folders of the application.
  • The app directory can contain routes in file-based Expo projects.
  • The assets directory can contain images, icons and fonts.
  • node_modules contains installed packages.
  • package.json contains project scripts and dependencies.
  • app.json can contain Expo application configuration.
  • Components can be organized in a components folder.
  • API logic can be organized in a services folder.
  • Custom Hooks can be organized in a hooks folder.
  • Community CLI projects normally contain native android and ios directories.
  • Large projects should use a structure that makes code easy to find and maintain.

🧠 Quick Quiz

Question: Which file normally contains project dependencies and scripts in a React Native project?