# carlossalasamper/react-native-clean-architecture architecture

> Architecture diagram of the GitHub repository carlossalasamper/react-native-clean-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/carlossalasamper/react-native-clean-architecture
- Repository: https://github.com/carlossalasamper/react-native-clean-architecture

## Overview

##### Project Type & Purpose
- This is a React Native mobile application scaffold with an emphasis on maintaining Clean Architecture principles.
- It leverages Expo for development (with different commands for web, Android, and iOS), and includes integration with external libraries such as Inversiland for dependency injection, MobX for state management, react-navigation for routing, and i18n for localization.
- The main goal of the project is to provide a well-structured, layered codebase with a clearly defined separation of concerns across Domain, Application, Infrastructure, and Presentation layers.

- Dependency Injection System (AppModule.ts): Acts as the root configuration for wiring together the various modules.
- Core Bounded Context ("core" directory):
- Domain Layer: Contains business rules, entities (see files in src/core/domain).
- Application Layer: Use cases (see src/core/application/UseCase.ts, etc.).
- Infrastructure Layer: Technical implementations such as the custom HttpClient.
- Presentation Layer: React Native code (components, hooks, navigation, i18n).
- Post Bounded Context ("post" directory):
- Domain Layer: PostEntity and post-related specifications.
- Application Layer: Use cases such as GetPostsUseCase and FindPostUseCase.
- Infrastructure Layer: Implementations like PostRepository.
- Presentation Layer: Screens, components, and state management stores for posts.
- Android (native project layer): Contains build configuration, native code setup, and resources.
- External Services & Libraries: Identify integrations for Expo, MobX, react-navigation, ESLint, Husky, CommitLint, etc.

##### Relationships & Interactions
- Directional data flow starting from the Presentation Layer, which handles the user interface (React Native screens, components, navigation) communicating with the Application Layer via use cases.
- The Application Layer (use cases and services) interacts with the Domain (business rules, entities) and Infrastructure (repository implementations, HTTP client).
- The Infrastructure Layer provides implementations of external integrations and technical details that serve both the Core and Post bounded contexts.
- The dependency injection container (AppModule.ts) ties together these somewhat independent modules by injecting the correct implementations into their respective consumers.
- The Android directory should be represented as the native platform-specific container for React Native, linking with resources and build configurations.

##### Architectural Patterns & Design Principles
- Clean Architecture/Onion Architecture: Illustrate the four layers (Domain, Application, Infrastructure, Presentation) ensuring that higher-level layers (Domain) are isolated from lower-level implementation details (Infrastructure).
- Bounded Contexts: Clearly separate “core” and “post” as different modules, each with its independent layers, yet integrated in the application via the dependency injection container.
- That core functionalities (e.g., localization, navigation, state management) are loosely coupled using libraries and custom hooks.

- To capture all essential architectural components and their interactions. Avoid oversimplification by listing each significant module rather than aggregating everything into one blob.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% DI Container
    DI["DI Container (AppModule)"]:::di

    %% External Integrations
    Expo["Expo"]:::external
    MobX["MobX"]:::external
    ReactNav["React-Navigation"]:::external
    I18n["Localization (i18n)"]:::external
    Inversiland["Inversiland"]:::external

    %% Core Bounded Context
    subgraph "Core Bounded Context"
        %% Domain Layer
        subgraph "Domain Layer"
            Core_Domain["Core Domain (Business Rules)"]:::domain
        end
        
        %% Application Layer
        subgraph "Application Layer"
            Core_App["Core Use Cases (Application)"]:::application
        end
        
        %% Infrastructure Layer
        subgraph "Infrastructure Layer"
            Core_Infra["Core Infrastructure (HttpClient)"]:::infrastructure
        end
        
        %% Presentation Layer
        subgraph "Presentation Layer"
            Core_Pres["Core Presentation (React Native UI, Hooks, i18n, Navigation)"]:::presentation
        end
    end

    %% Post Bounded Context
    subgraph "Post Bounded Context"
        %% Domain Layer
        subgraph "Domain Layer"
            Post_Domain["Post Domain (Entities & Specs)"]:::domain
        end
        
        %% Application Layer
        subgraph "Application Layer"
            Post_App["Post Use Cases (Application)"]:::application
        end
        
        %% Infrastructure Layer
        subgraph "Infrastructure Layer"
            Post_Infra["Post Infrastructure (PostRepository)"]:::infrastructure
        end
        
        %% Presentation Layer
        subgraph "Presentation Layer"
            Post_Pres["Post Presentation (Screens, Components, State Management)"]:::presentation
        end
    end

    %% Android Native Project
    Android["Android Native Project"]:::di

    %% Connections for Core Context
    Core_Pres -->|"triggers"| Core_App
    Core_App -->|"processes"| Core_Domain
    Core_App -->|"utilizes"| Core_Infra

    %% Connections for Post Context
    Post_Pres -->|"triggers"| Post_App
    Post_App -->|"processes"| Post_Domain
    Post_App -->|"utilizes"| Post_Infra

    %% DI Container wiring
    DI -->|"injects"| Core_App
    DI -->|"injects"| Core_Infra
    DI -->|"injects"| Post_App
    DI -->|"injects"| Post_Infra

    %% External Integrations with Presentation Layers
    Expo -->|"supports"| Core_Pres
    ReactNav -->|"configures"| Core_Pres
    I18n -->|"localizes"| Core_Pres
    MobX -->|"managesState"| Post_Pres

    %% Integration with Native Android
    Core_Pres -->|"buildsOn"| Android

    %% Inversiland integration with DI
    Inversiland -->|"configures"| DI

    %% Click Events
    click DI "https://github.com/carlossalasamper/react-native-clean-architecture/blob/master/src/AppModule.ts"
    click Core_Domain "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/domain"
    click Core_App "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/application"
    click Core_Infra "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/infrastructure"
    click Core_Pres "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/presentation"
    click Post_Domain "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/post/domain"
    click Post_App "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/post/application"
    click Post_Infra "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/post/infrastructure"
    click Post_Pres "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/post/presentation"
    click Android "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/android"
    click ReactNav "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/presentation/navigation"
    click I18n "https://github.com/carlossalasamper/react-native-clean-architecture/tree/master/src/core/presentation/i18n"

    %% Styles
    classDef domain fill:#FFEB3B,stroke:#000,stroke-width:1px;
    classDef application fill:#90CAF9,stroke:#000,stroke-width:1px;
    classDef infrastructure fill:#A5D6A7,stroke:#000,stroke-width:1px;
    classDef presentation fill:#FFCC80,stroke:#000,stroke-width:1px;
    classDef di fill:#B0BEC5,stroke:#000,stroke-width:1px;
    classDef external fill:#F48FB1,stroke:#000,stroke-width:1px;
```
