React Native File Structure Explained: What You Need to Know

When diving into React Native development, one of the first things you'll encounter is the project’s file structure. Understanding this structure is crucial for efficiently navigating your project, organizing code, and maintaining a scalable application. In this blog, we'll break down the essential components of a React Native file structure and explore best practices for managing your codebase.

1. Root Directory

The root directory is the top level of your project and typically contains files and folders that define your project and its configuration.

  • app/: This is where your application code resides. It contains all the source code, resources, and configurations specific to your app.

  • gradle/: Contains files related to the Gradle build system, including the wrapper files (gradle-wrapper.properties).

  • build/: This directory is where Gradle stores build outputs, such as APKs and intermediate files.

  • .gitignore: Specifies files and directories that should be ignored by Git.

  • build.gradle (Project-level): The top-level Gradle build file where you can add configuration options common to all sub-projects/modules.

  • settings.gradle: Specifies the modules that are part of the project. It allows you to include or exclude modules from the build.

  • gradlew & gradlew.bat: Shell scripts to run the Gradle wrapper, which ensures consistent Gradle version usage across different environments.

  • local.properties: Stores local environment properties, like the location of the Android SDK. This file should not be versioned.

2. The app/ Directory

This directory is the heart of your Android project, containing everything related to your application’s code and resources.

  • src/: Contains the main source code for your application, as well as code for different build variants (e.g., debug, release).

    • main/: The main source set, where most of your application code resides.

      • java/ or kotlin/: Contains the Java or Kotlin source files for your application.

      • res/: Contains all the resources used by your application, such as layouts, strings, drawables, etc.

        • layout/: XML layout files that define the UI of your application.

        • drawable/: Images and other drawable resources.

        • mipmap/: Launcher icons for your app in different resolutions.

        • values/: Resource files like strings, colors, dimensions, and styles.

        • menu/: XML files defining menus for your app.

        • xml/: Arbitrary XML files, such as preferences, network security configuration, etc.

      • AndroidManifest.xml: Declares the essential information about your app, such as activities, permissions, and services.

      • assets/: Raw files that your app can access directly, such as fonts, configuration files, or other assets.

      • aidl/: Interface Definition Language files, used to define the interface for interprocess communication.

    • test/: Contains unit tests that run on the JVM.

    • androidTest/: Contains instrumentation tests that run on an Android device or emulator.

  • build/: The build directory for the app module, containing outputs like APKs, intermediate build files, etc.

  • libs/: Contains any .jar files that your project is dependent on.

  • proguard-rules.pro: Configuration file for ProGuard, a tool that shrinks, optimizes, and obfuscates your code.

  • build.gradle (Module-level): The Gradle build file specific to the app module, where you declare dependencies, apply plugins, and configure the build process.

3. Gradle Scripts

Gradle is the build system used by Android Studio. It uses scripts to manage the build configuration.

  • build.gradle (Project-level): Contains configuration for the entire project, such as classpaths, repositories, and dependencies shared across all modules.

  • build.gradle (Module-level): Contains configuration for a specific module, such as the app module. You can define dependencies, plugins, and tasks here.

  • gradle-wrapper.properties: Contains the version of Gradle that is used to build the project. It ensures consistency across different environments.

4. External Libraries and Dependencies

  • dependencies/: Although not a separate directory, the dependencies block in your Gradle files will declare external libraries your project uses. These could be from Maven repositories, Google’s AndroidX libraries, or custom libraries.

5. Other Key Files

  • ProGuard Rules: Used for code obfuscation, shrinking, and optimization. Typically found in proguard-rules.pro.

  • README.md: A markdown file explaining the project, how to set it up, and any other relevant information for developers.

6. Best Practices for Structuring an Android Project

  • Organize Code by Feature: Consider using a feature-based organization within the java/ or kotlin/ directory, where each feature of the app has its own package.

  • Modularization: As your app grows, consider breaking it down into multiple modules. This makes the project more manageable, improves build times, and encourages reusability.

  • Version Control Best Practices: Use .gitignore effectively to avoid committing unnecessary files. Avoid committing local environment files like local.properties.


As you work on your Android projects, keeping this file structure in mind will allow you to develop more efficiently and maintain a cleaner, more organized codebase.

While following traditional Android project organization, emphasizes modularity, organization, and clarity. Understanding and following this structure helps ensure your project remains scalable, maintainable, and easy to navigate.
0
Subscribe to my newsletter

Read articles from Shubham Deshmukh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Deshmukh
Shubham Deshmukh

My career objective is to be a competent individual who can contribute significantly to an organization's growth and also get valuable exposure, that would help me enhance my skill sets and provide me with opportunities to grow and further develop my talents as an individual. Also will offer me a work-life balance.