Lesson 79 of 60 – React Native TypeScript Project Structure
100%

React Native TypeScript Project Structure

A well-organized project structure makes a React Native application easier to understand, develop, test, and maintain. As an application becomes larger, keeping screens, components, navigation, API services, types, context, Redux, and utilities in separate folders becomes useful.

In this lesson, we will learn how to organize a React Native project using TypeScript and understand the purpose of the most common folders and files.

Note: There is no single folder structure that every React Native project must follow. The structure should match the size and requirements of your application.

1. Why Project Structure Matters

A project structure defines how files and folders are organized.

A good structure helps developers:

  • Find files quickly.
  • Separate different responsibilities.
  • Reuse components.
  • Maintain large applications.
  • Work efficiently in teams.

2. Basic React Native TypeScript Structure

MyApp/
    src/
        components/
        screens/
        navigation/
        types/
        services/
        hooks/
        utils/
        context/
        store/
    App.tsx
    package.json
    tsconfig.json

The src folder can contain most application source code.

3. The src Folder

The src folder is commonly used to store application source files.

src/
    components/
    screens/
    navigation/
    services/
    types/

Keeping application code inside src makes the root project directory cleaner.

4. Components Folder

The components folder contains reusable UI components.

components/
    AppButton.tsx
    AppInput.tsx
    UserCard.tsx
    LoadingView.tsx

Components can be reused across multiple screens.

5. Creating a Typed Button Component

import React from "react";

import {
    Button
} from "react-native";

interface AppButtonProps {
    title: string;
    onPress: () => void;
}

export default function AppButton(
    {
        title,
        onPress
    }: AppButtonProps
): React.JSX.Element {

    return (
        <Button
            title={title}
            onPress={onPress}
        />
    );
}

6. Screens Folder

The screens folder contains complete application screens.

screens/
    HomeScreen.tsx
    LoginScreen.tsx
    ProfileScreen.tsx
    SettingsScreen.tsx
    ProductScreen.tsx

A screen usually combines several components to create a complete page.

7. Creating a Typed Screen

import React from "react";

import {
    View,
    Text
} from "react-native";

export default function HomeScreen():
    React.JSX.Element {

    return (
        <View>
            <Text>
                Welcome to My App
            </Text>
        </View>
    );
}

8. Navigation Folder

The navigation folder can contain navigators and navigation type definitions.

navigation/
    AppNavigator.tsx
    types.ts

Keeping navigation code separate makes it easier to manage application screens and route types.

9. Navigation Types

export type RootStackParamList = {

    Home: undefined;

    Profile: {
        userId: number;
    };

    Settings: undefined;

};

This type defines the parameters expected by each navigation route.

10. Types Folder

The types folder can contain reusable TypeScript interfaces, type aliases, and other shared types.

types/
    user.ts
    product.ts
    api.ts
    navigation.ts

11. User Type File

export interface User {
    id: number;
    name: string;
    email: string;
}

The interface can then be imported into different files.

import {
    User
} from "../types/user";

12. Services Folder

The services folder can contain API and external service functions.

services/
    api.ts
    userService.ts
    authService.ts
    productService.ts

This keeps network-related code separate from UI components.

13. Typed API Service

import axios from "axios";

import {
    User
} from "../types/user";

export const getUsers =
    async (): Promise<User[]> => {

    const response =
        await axios.get<User[]>(
            "/users"
        );

    return response.data;
};

14. Hooks Folder

The hooks folder can contain reusable custom React hooks.

hooks/
    useAuth.ts
    useUsers.ts
    useTheme.ts

Custom hooks can contain reusable state and application logic.

15. Typed Custom Hook

import {
    useState
} from "react";

export function useCounter():
    [
        number,
        () => void
    ] {

    const [count, setCount] =
        useState<number>(0);

    const increment = (): void => {

        setCount(
            previous =>
                previous + 1
        );

    };

    return [
        count,
        increment
    ];
}

16. Utils Folder

The utils folder can contain reusable helper functions.

utils/
    validation.ts
    formatDate.ts
    storage.ts
    constants.ts

Utility functions should generally perform focused reusable tasks.

17. Constants Folder

Constants that are shared across the application can be placed in a constants file or folder.

export const API_URL =
    "https://example.com/api";

export const APP_NAME =
    "Student App";

18. Context Folder

If the application uses Context API, context files can be grouped together.

context/
    UserContext.tsx
    ThemeContext.tsx
    AuthContext.tsx

Each context can have its own TypeScript interfaces and Provider.

19. Redux Store Folder

Applications using Redux Toolkit can organize Redux code inside a store or app folder.

store/
    store.ts
    hooks.ts

Feature-specific Redux slices can be kept separately.

20. Redux Feature Structure

features/
    user/
        userSlice.ts
        userTypes.ts

    product/
        productSlice.ts
        productTypes.ts

    cart/
        cartSlice.ts
        cartTypes.ts

Feature-based organization keeps related state, actions, and types together.

21. Assets Folder

Images, icons, fonts, and other static files can be organized inside an assets folder.

assets/
    images/
    icons/
    fonts/

Keeping assets separate helps maintain a clean source directory.

22. Environment and Configuration Files

Configuration may include API URLs, application settings, and build configuration.

config/
    api.ts
    app.ts

Sensitive information should not be placed directly into source code or committed to a public repository.

23. tsconfig.json

The tsconfig.json file contains TypeScript compiler configuration.

It can define compiler options, included files, strictness settings, module configuration, and other TypeScript behavior.

{
    "compilerOptions": {
        "strict": true
    }
}

24. Naming Conventions

Consistent file names make a project easier to understand.

  • HomeScreen.tsx for screens.
  • UserCard.tsx for components.
  • userService.ts for services.
  • useAuth.ts for custom hooks.
  • UserContext.tsx for context.
  • userSlice.ts for Redux slices.

25. Feature-Based Structure

Another approach is to organize files by application feature instead of only by technical type.

features/
    auth/
        LoginScreen.tsx
        authService.ts
        authTypes.ts

    users/
        UserListScreen.tsx
        UserCard.tsx
        userService.ts
        userTypes.ts

    products/
        ProductScreen.tsx
        productService.ts
        productTypes.ts

26. Scalable Project Structure

MyApp/
    src/

        components/
        screens/
        navigation/

        features/
            auth/
            users/
            products/

        services/
        hooks/
        types/
        utils/
        context/
        store/

    assets/

    App.tsx
    package.json
    tsconfig.json

This type of structure can work well as an application grows.

27. Importing Files Correctly

import {
    User
} from "../types/user";

import AppButton
    from "../components/AppButton";

import {
    getUsers
} from "../services/userService";

Relative imports should point to the correct file location.

28. Complete Example Structure

StudentApp/
│
├── src/
│   │
│   ├── components/
│   │   ├── AppButton.tsx
│   │   ├── AppInput.tsx
│   │   └── UserCard.tsx
│   │
│   ├── screens/
│   │   ├── HomeScreen.tsx
│   │   ├── LoginScreen.tsx
│   │   └── ProfileScreen.tsx
│   │
│   ├── navigation/
│   │   ├── AppNavigator.tsx
│   │   └── types.ts
│   │
│   ├── services/
│   │   ├── api.ts
│   │   └── userService.ts
│   │
│   ├── types/
│   │   └── user.ts
│   │
│   ├── hooks/
│   │   └── useAuth.ts
│   │
│   ├── context/
│   │   └── AuthContext.tsx
│   │
│   ├── store/
│   │   ├── store.ts
│   │   └── hooks.ts
│   │
│   └── utils/
│       └── validation.ts
│
├── assets/
│   ├── images/
│   └── icons/
│
├── App.tsx
├── package.json
└── tsconfig.json

29. Common Project Structure Mistakes

  • Putting every file in one folder.
  • Creating very large components.
  • Mixing API code directly into every screen.
  • Duplicating the same interfaces in many files.
  • Using unclear file names.
  • Creating unnecessary folders for very small projects.
  • Keeping unrelated application logic together.

30. Summary

A good React Native TypeScript project structure separates different responsibilities such as components, screens, navigation, services, types, hooks, context, Redux, utilities, and assets.

For small applications, a simple structure may be enough. As the application grows, feature-based organization can make the project easier to maintain.

You should now understand the purpose of the major project folders, TypeScript files, reusable components, API services, navigation types, Context API, Redux Toolkit, and scalable project organization.

📌 Key Points

  • Use folders to separate different responsibilities.
  • Keep reusable UI components inside components.
  • Keep application screens inside screens.
  • Keep navigation and route types organized.
  • Use types for reusable TypeScript types.
  • Keep API logic inside services.
  • Use hooks for reusable custom hooks.
  • Use context for Context API files.
  • Use store or app for Redux Toolkit setup.
  • Choose a structure that matches the size of your application.

🧠 Quick Quiz

Question: Which folder is commonly used for reusable React Native UI components?