# resticdog/phicomm-n1-controller architecture

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

- Interactive diagram: https://gitdiagram.com/resticdog/phicomm-n1-controller
- Repository: https://github.com/resticdog/phicomm-n1-controller

## Overview

##### Main Components
- App Entry & Configuration:
- App.tsx (application entry point)
- app.json, babel.config.js, and eas.json (provide configuration for Expo and EAS builds)
- Presentation/UI Layer:
- Screens (located in the “screens” directory): AppListScreen, ControlScreen, NotFoundScreen, SettingsScreen.
- Components (in “components”): UI elements such as ControlButton, ControlPanel, EditScreenInfo, RemoteStatus, StyledText, and theme helpers in Themed.tsx.
- Navigation Layer:
- The “navigation” directory contains route configuration (LinkingConfiguration.ts) and the index.tsx that sets up navigation between screens.
- Business Logic & State Management:
- Hooks (in “hooks”): Custom hooks like useCachedResources and useColorScheme help manage resources and theming.
- Data/API Layer:
- The “api” directory houses API utilities (e.g., phicomm.ts) which likely handle remote calls to control or query the N1 device.
- Utilities (in “utils”): Include db.js for local data handling, request.ts for network calls, and additional helper functions.
- Assets:
- The “assets” directory holds fonts and images (including the screenshot used in the README).

##### Relationships and Data Flow
- User Interaction → UI: Users interact with the screens/components (e.g., pressing a ControlButton on the ControlScreen).
- UI → Navigation: The navigation layer (configured in the “navigation” directory) handles movement between different screens based on user input.
- UI/Business Logic → API Layer: On actions such as launching an app or fetching a program list, UI components or hooks call functions in “api/phicomm.ts” to interact with external devices/services.
- Data Persistence & Utilities: The “utils” folder shows functions for handling database interactions or network requests, which serve both as facilitators for API calls and local state management.
- Theming/Styling: The “constants” and “assets” directories feed information to UI components to maintain a consistent look (with planned dark mode support).

##### Architectural Patterns and Design Principles
- Component-Based Architecture: Leveraging React Native’s component structure, where reusable UI components and screens build up the interface.
- Separation of Concerns: The project clearly distinguishes between configuration files, presentation logic (screens and components), navigation, data handling (API and utils), and styling (constants and assets).
- Declarative UI: Use of JSX in screens and components signals adherence to a declarative programming model typical in modern React development.

##### Relevant Technologies and Frameworks
- Expo/React Native: Provides the foundation for the mobile application.
- TypeScript: Evident from .tsx files and tsconfig.json, offering type-safety throughout the app.
- Expo’s asset management and app configuration (e.g., app.json, eas.json).
- GitHub Actions (see .github/workflows/build.yaml) for continuous integration.

- Branch into two major paths:
- One for the UI: showing Screens, Components, and Navigation.
- The other for the Backend Logic: including API interactions (phicomm.ts), utilities, and hooks.
- How the constants and assets are shared and utilized across the UI components.
- Optionally, if future enhancements like dark mode or mdns IP discovery are to be integrated, you may annotate those areas for future extension.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "App Entry & Config"
        A1["App.tsx"]:::entry
        A2["app.json"]:::entry
        A3["babel.config.js"]:::entry
        A4["eas.json"]:::entry
    end

    subgraph "Presentation/UI Layer"
        subgraph "Screens"
            S1["AppListScreen"]:::screens
            S2["ControlScreen"]:::screens
            S3["NotFoundScreen"]:::screens
            S4["SettingsScreen"]:::screens
        end
        subgraph "Components"
            C1["ControlButton"]:::components
            C2["ControlPanel"]:::components
            C3["EditScreenInfo"]:::components
            C4["RemoteStatus"]:::components
            C5["StyledText"]:::components
            C6["Themed"]:::components
        end
        subgraph "Navigation"
            N1["LinkingConfiguration"]:::nav
            N2["Navigation Index"]:::nav
        end
    end

    subgraph "Business Logic & State Management"
        subgraph "Hooks"
            H1["useCachedResources"]:::hooks
            H2["useColorScheme"]:::hooks
        end
        subgraph "Constants"
            CT1["Colors"]:::constants
            CT2["Layout"]:::constants
            CT3["Constants Index"]:::constants
        end
    end

    subgraph "Data/API Layer"
        API["phicomm"]:::api
        subgraph "Utilities"
            U1["db"]:::util
            U2["request"]:::util
            U3["Utils Index"]:::util
        end
    end

    subgraph "Assets & Styling Resources"
        Asset1["Fonts"]:::assets
        Asset2["Images"]:::assets
        Asset3["Screenshots"]:::assets
    end

    %% Connections between layers
    A1 -->|"launches"| S1
    A1 -->|"launches"| S2
    A1 -->|"launches"| S3
    A1 -->|"launches"| S4

    S1 -->|"navigates"| N1
    S2 -->|"triggers"| C1
    C1 -->|"calls"| API
    API -->|"uses"| U2

    S2 -->|"initializes"| H1
    H1 -->|"providesResources"| S2

    CT1 -->|"themes"| C6
    Asset1 -->|"suppliesFontsTo"| C5
    Asset2 -->|"suppliesImagesTo"| C4

    S4 -->|"accessesSettings"| CT3

    %% Styling classes
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef screens fill:#ccf,stroke:#333,stroke-width:1px;
    classDef components fill:#cfc,stroke:#333,stroke-width:1px;
    classDef nav fill:#fc9,stroke:#333,stroke-width:1px;
    classDef hooks fill:#cff,stroke:#333,stroke-width:1px;
    classDef constants fill:#ffc,stroke:#333,stroke-width:1px;
    classDef api fill:#f66,stroke:#333,stroke-width:1px;
    classDef util fill:#6f6,stroke:#333,stroke-width:1px;
    classDef assets fill:#ddd,stroke:#333,stroke-width:1px;

    %% Click Events for App Entry & Config
    click A1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/App.tsx"
    click A2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/app.json"
    click A3 "https://github.com/resticdog/phicomm-n1-controller/blob/master/babel.config.js"
    click A4 "https://github.com/resticdog/phicomm-n1-controller/blob/master/eas.json"

    %% Click Events for Screens
    click S1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/screens/AppListScreen.tsx"
    click S2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/screens/ControlScreen.tsx"
    click S3 "https://github.com/resticdog/phicomm-n1-controller/blob/master/screens/NotFoundScreen.tsx"
    click S4 "https://github.com/resticdog/phicomm-n1-controller/blob/master/screens/SettingsScreen.tsx"

    %% Click Events for Components
    click C1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/ControlButton.tsx"
    click C2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/ControlPanel.tsx"
    click C3 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/EditScreenInfo.tsx"
    click C4 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/RemoteStatus.tsx"
    click C5 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/StyledText.tsx"
    click C6 "https://github.com/resticdog/phicomm-n1-controller/blob/master/components/Themed.tsx"

    %% Click Events for Navigation
    click N1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/navigation/LinkingConfiguration.ts"
    click N2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/navigation/index.tsx"

    %% Click Events for Hooks
    click H1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/hooks/useCachedResources.ts"
    click H2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/hooks/useColorScheme.ts"

    %% Click Events for Constants
    click CT1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/constants/Colors.ts"
    click CT2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/constants/Layout.ts"
    click CT3 "https://github.com/resticdog/phicomm-n1-controller/blob/master/constants/index.ts"

    %% Click Event for API Service
    click API "https://github.com/resticdog/phicomm-n1-controller/blob/master/api/phicomm.ts"

    %% Click Events for Utilities
    click U1 "https://github.com/resticdog/phicomm-n1-controller/blob/master/utils/db.ts"
    click U2 "https://github.com/resticdog/phicomm-n1-controller/blob/master/utils/request.ts"
    click U3 "https://github.com/resticdog/phicomm-n1-controller/blob/master/utils/index.ts"

    %% Click Events for Assets
    click Asset1 "https://github.com/resticdog/phicomm-n1-controller/tree/master/assets/fonts"
    click Asset2 "https://github.com/resticdog/phicomm-n1-controller/tree/master/assets/images"
    click Asset3 "https://github.com/resticdog/phicomm-n1-controller/tree/master/screenshots"
```
