# pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile architecture

> Architecture diagram of the GitHub repository pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile, 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/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile
- Repository: https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile

## Overview

##### Main Components

- Mobile App UI (Presentation Layer):
- The "app" folder contains the routing and screens. Notice the separation between app routes (mostly in the "(app)" folder under different tabs like account, categories, orders, products, checkout, etc.) and authentication screens (in the "(auth)" folder).
- The assets and animations directories support UI elements such as loading animations and image assets.

- API Integration Layer:
- The "apis" directory hosts modules like auth, cart, product, etc. These serve as the interface between the mobile client and the backend services that provide e-commerce functionalities and user data management.

- State Management & Business Logic:
- The "context" folder provides global state management for authentication and the shopping cart, ensuring that information flows correctly between components and screens.
- Custom hooks in the "hooks" folder (such as useThemeColor, useColorScheme, and useDebounce) encapsulate business logic and device-specific interactions.

- Utility & Type Safety:
- The "utils" folder (e.g., for HTTP requests and price conversion) contains helper functions.
- The "type" folder defines TypeScript types for entities like address, brand, cart, category, order, product, etc., ensuring type safety across the application.

- Testing & Quality Assurance:
- The "__tests__" folder mirrors the component structure and contains tests (mostly component tests for UI elements) ensuring code reliability and expected behavior.

##### Relationships and Interactions

- The UI/Presentation layer interacts with:
- Reusable UI components (from the "components" directory).
- Navigation and routing (files in the "app" folder for switching between different application states like auth, product view, cart, etc.).
- Global state management (via context files handling authentication and the cart).

- The API Integration Layer:

- State Management and Business Logic:
- Connects the UI with data sources. The contexts feed data to the screens and components, while hooks and utilities streamline common functionalities.

- Testing Layer:
- Although not part of the runtime system, note that tests (in "__tests__") verify functionality for the UI components, ensuring that the design is robust.

##### Architectural Patterns and Technologies Used

- Component-Based Design:
- The application follows a modular structure, where each UI element (button, card, header, etc.) can be seen as an individual component that may be composed together.

- Separation of Concerns:
- Clear delineation between presentation (UI and routing), business logic (context and hooks), and data communication (APIs and utilities).

- Mobile-Specific Permissions:
- Special mention of READ_MEDIA_IMAGES in the README suggests that the design must account for mobile permissions and the module where users select an avatar, which is implemented in the components (e.g., in the avatar component) and possibly influenced by context and API handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        A["Main App Routes"]:::presentation
        B["Auth Routes"]:::presentation
        subgraph "Reusable UI Components"
            C1["Avatar"]:::component
            C2["Button"]:::component
            C3["Other UI Components"]:::component
        end
        D["Assets & Animations"]:::assets
    end

    %% API Integration Layer
    subgraph "API Integration Layer"
        E["Auth API"]:::api
        F["Product API"]:::api
        G["Cart API"]:::api
    end

    %% State Management & Business Logic
    subgraph "State Management"
        H["Auth Context"]:::state
        I["Cart Context"]:::state
        subgraph "Custom Hooks"
            J1["useThemeColor"]:::hook
            J2["useColorScheme"]:::hook
            J3["useDebounce"]:::hook
        end
    end

    %% Utilities & Type Safety
    subgraph "Utilities & Type Safety"
        K["Utility Functions"]:::utility
        L["Type Definitions"]:::utility
    end

    %% Testing & QA
    subgraph "Testing & QA"
        M["Test Suite"]:::testing
    end

    %% Connections within Presentation Layer
    A -->|"routes_to"| C1
    A -->|"routes_to"| C2
    A -->|"routes_to"| C3
    B -->|"routes_to"| C1
    B -->|"routes_to"| C2
    B -->|"routes_to"| C3

    D -->|"supplies_assets"| C1
    D -->|"supplies_assets"| C2
    D -->|"supplies_assets"| C3

    %% UI triggering state updates
    A -->|"updates_state"| H
    A -->|"updates_state"| I
    B -->|"updates_state"| H
    B -->|"updates_state"| I

    %% UI Components invoke API calls
    C1 -->|"triggers_API"| E
    C2 -->|"triggers_API"| F
    C3 -->|"triggers_API"| G

    %% UI Components leveraging hooks
    C1 -->|"uses_hook"| J1
    C2 -->|"uses_hook"| J2
    C3 -->|"uses_hook"| J3

    %% API responses updating state
    E -->|"state_update"| H
    F -->|"state_update"| I
    G -->|"state_update"| I

    %% Hooks supporting state management
    J1 -->|"supports"| H
    J2 -->|"supports"| I
    J3 -->|"supports"| H

    %% Utilities assisting UI components
    K -->|"assists"| C1
    K -->|"assists"| C2
    K -->|"assists"| C3
    L -->|"ensures_type"| K

    %% Testing verifying UI components
    M -->|"tests"| C1
    M -->|"tests"| C2
    M -->|"tests"| C3

    %% Click Events for Presentation Layer
    click A "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/app/(app)"
    click B "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/app/(auth)"
    click C1 "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/components/avatar/Avatar.tsx"
    click C2 "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/components/button/Button.tsx"
    click D "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/assets"

    %% Click Events for API Integration Layer
    click E "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/apis/auth.ts"
    click F "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/apis/product.ts"
    click G "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/apis/cart.ts"

    %% Click Events for State Management
    click H "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/context/auth.tsx"
    click I "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/context/cart.tsx"
    click J1 "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/hooks/useThemeColor.ts"
    click J2 "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/hooks/useColorScheme.ts"
    click J3 "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/blob/main/hooks/useDebounce.ts"

    %% Click Events for Utilities & Type Safety
    click K "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/utils"
    click L "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/type"

    %% Click Event for Testing
    click M "https://github.com/pbl6-khoa-hoc-lap-trinh-online/pbl6-mobile/tree/main/__tests__"

    %% Styles
    classDef presentation fill:#fceabb,stroke:#e09500,stroke-width:2px;
    classDef component fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef assets fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef api fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef state fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef hook fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utility fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef testing fill:#f5c6cb,stroke:#721c24,stroke-width:2px;
```
