# caioliveira277/treefy-app architecture

> Architecture diagram of the GitHub repository caioliveira277/treefy-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caioliveira277/treefy-app
- Repository: https://github.com/caioliveira277/treefy-app

## Overview

##### Main Components
- Presentation Layer:
- Includes all UI elements, components, and views stored primarily in the “src/presentation” folder. This covers everything from components (buttons, inputs, layouts) to view-models and contexts.
- Routing: the “src/main/routes” files that handle navigation (both public and authenticated routes).
- Domain Layer:
- Located under “src/domain”, where the core business logic, models, and domain-specific use cases reside. This is the heart of the app’s business rules.
- Data Layer:
- Found in “src/data”. This layer handles data operations through data sources (e.g., article, user-plant, feedback) and use cases that implement remote requests.
- Contains protocols for HTTP clients and identity providers, suggesting that data communication is abstracted behind interfaces.
- Infrastructure Layer:
- Resides in “src/infra” which includes integrations like AWS (aws-cognito) and axios for HTTP requests.
- Main and Factories:
- “src/main” organizes app initialization, configuration, factories for services and use cases, and centralizes the instantiation of various modules.
- Assets and Configs:

##### How These Components Interact
- Data Flow:
- UI components (in the Presentation layer) trigger actions that are handled by view-models.
- The view-models call domain use cases (from the Domain layer) to process business logic.
- Domain use cases, in turn, interact with the Data layer’s use case implementations and data sources, which in turn use protocols (HTTP clients and identity providers) defined within the Data layer.
- External services (like AWS Cognito for authentication or third-party endpoints for articles) are accessed via the axios implementation inside the Infra layer.
- Factories:
- Factories in “src/main/factories” are responsible for creating and wiring together instances of use cases, services, and views, ensuring that dependencies are injected properly.
- Routing and Navigation:
- Routes defined in “src/main/routes” direct users through various screens (access, home, profile, etc.), linking the presentation layer with the underlying business logic.

##### Architectural Patterns and Design Principles
- Clean/Onion Architecture/Clean Architecture:
- The separation into Presentation, Domain, and Data layers is a classic example of clean architecture. Emphasize the dependency rules – for instance, the Presentation and Data layers depend on the Domain.
- Factories and Dependency Injection:
- The use of factories in “src/main/factories” for creating use case instances and views promotes modularity and testability.
- Component-Based UI:
- The heavy use of components and modularized views (each with its own folder under “src/presentation”) follows modern UI componentization best practices.

##### Relevant Technologies/Frameworks
- Expo and React Native are the backbone for the mobile front-end.
- Styled Components for theming and styling.
- TypeScript as the primary language.
- AWS Cognito integrated via the Infra layer for identity management.
- Axios is used for HTTP communication.
- Jest for unit testing in both the “src/presentation” and possibly other layers.

- Component Labels: Each layer (Presentation, Domain, Data, Infra), and within these, clearly label sub-components (e.g., “Authentication Use Case”, “Article Data Source”, “AWS Cognito Identity Provider”, “Home View”, “Navigation Routes”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["User Interaction"]:::user

    subgraph "Presentation Layer"
        direction TB
        P1["UI Components/Views/ViewModels/Contexts"]:::presentation
        P2["Routing & Navigation"]:::presentation
    end

    subgraph "Domain Layer"
        direction TB
        D["Domain Models & Use Cases"]:::domain
    end

    subgraph "Data Layer"
        direction TB
        DAT["Data Sources & Protocols"]:::data
    end

    subgraph "Infrastructure Layer"
        direction TB
        INF["AWS Cognito & Axios Integration"]:::infra
    end

    subgraph "Main & Factories"
        direction TB
        M["App Initialization/Factories"]:::main
    end

    UI --> P1
    UI --> P2
    P1 -->|"triggers"| D
    P2 -->|"navigatesTo"| D
    D -->|"invokes"| DAT
    DAT -->|"calls"| INF

    M -->|"initializes"| P1
    M -->|"initializes"| D
    M -->|"initializes"| DAT

    classDef user fill:#D6EAF8,stroke:#1F618D,stroke-width:2px;
    classDef presentation fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef domain fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef infra fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef main fill:#FAD7A0,stroke:#CA6F1E,stroke-width:2px;

    click P1 "https://github.com/caioliveira277/treefy-app/tree/main/src/presentation"
    click P2 "https://github.com/caioliveira277/treefy-app/tree/main/src/main/routes"
    click D "https://github.com/caioliveira277/treefy-app/tree/main/src/domain"
    click DAT "https://github.com/caioliveira277/treefy-app/tree/main/src/data"
    click INF "https://github.com/caioliveira277/treefy-app/tree/main/src/infra"
    click M "https://github.com/caioliveira277/treefy-app/tree/main/src/main/factories"
    click M "https://github.com/caioliveira277/treefy-app/blob/main/src/main/App.tsx"
```
