# knut-capstone-design-team-1/wip-application-v2 architecture

> Architecture diagram of the GitHub repository knut-capstone-design-team-1/wip-application-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/knut-capstone-design-team-1/wip-application-v2
- Repository: https://github.com/knut-capstone-design-team-1/wip-application-v2

## Overview

##### Project Type and High-Level Purpose
- This is a mobile application (supporting both Android and iOS) built with React Native. The application focuses on scanning/searching for pills (medications) using pill images.
- The README highlights external API integrations (Google Cloud for image search, drug details; CloudFlare for resource storage) and a local database with encryption (Realm).

##### Main Components
a. Mobile Frontend (React Native UI)
- Components: All UI elements under the “src/components” directory (atoms, organisms, screens, etc.).
- Navigation: “src/navigation” – handling screen stacking and navigation flows.
- State and Hooks: “src/hooks”, “src/provider”, “src/selectors” to manage state, alerts, and queries.
- Utilities and Styling: “src/utils”, “src/style”, “src/constants” for data management, utility functions, and global styles.
b. API and Data Layer
- API Clients: “src/api/client” indicates a layer to handle HTTP requests (authentication, DB responses, etc.).
- Database Models & Queries: “src/api/db/models” for pill-related data and “src/api/db/query” to handle local data storage operations.
- Server Logic: “src/api/server.ts” possibly centralizes route definitions or handles middleware.
- Update Mechanism: “src/api/update.ts” to manage data updates.
c. External Services Integration
- Google Cloud: Several environment variables reference Google Cloud endpoints (for init-info, image search, drug details).
- CloudFlare: Environment setup to manage resource downloads from CloudFlare.
- Local Database: The use of a Realm encryption key implies secure local storage for offline use.
d. Native Platform Components
- Android-specific native code and build configurations under “android” (build.gradle files, native Java/ Kotlin code).
- iOS-specific native code and configurations under “ios” (Xcode project files, storyboard, Podfile).
e. Build and Infrastructure
- Configuration Files: Scripts for linting (.eslintrc.js, .prettierrc.js), testing (“__tests__”), and build scripts (npm run android:dev, android:prod, ios:dev, ios:prod).
- CI/CD: GitHub workflows for Android builds are defined under “.github/workflows”.

##### Relationships and Data Flow
- The primary data flow starts from the mobile frontend (React Native layers in “src”) where user actions on UI screens trigger API calls.
- The API client layer (src/api/client) communicates with external services (Google Cloud and CloudFlare) to retrieve images, search results, and drug details.
- The local database (Realm) handles storing relevant pill data. Data flows from the API to the local storage and then back to UI components.
- The native layers (Android and iOS directories) wrap the React Native app, ensuring platform-specific native integrations and build processes.
- Testing and CI/CD workflows maintain code quality and streamline app deployment.

##### Architectural Patterns and Technologies
- Separation of Concerns: The project is clearly divided into UI components, business logic (API clients, DB models, hooks), and native platform code.
- Modular Componentization: The “atoms”, “organisms”, and “screens” follow a structured component-based architecture.
- Data Abstraction: The use of separate API and DB directories abstracts the data layer from the presentation logic.
- Cross-Platform Development: React Native is used to maintain a single codebase for both iOS and Android while allowing native customizations.
- External Integration: Incorporates RESTful API calls to Google Cloud endpoints as well as secure data storage from CloudFlare services.

## Diagram (Mermaid)

```mermaid
flowchart TB

    %% Mobile Frontend Layer
    subgraph "Mobile Frontend (React Native)"
        M1["UI Components"]
        M2["Navigation"]
        M3["State & Hooks"]
        M4["Utilities & Styling"]
    end

    %% API and Data Layer
    subgraph "API and Data Layer"
        A1["API Clients"]
        A2["Database Models"]
        A3["Database Queries"]
        A4["Server/Route Logic"]
        A5["Update Mechanism"]
    end

    %% External Services Integration
    subgraph "External Services Integration"
        E1["Google Cloud Services"]
        E2["CloudFlare"]
        E3["Local DB (Realm)"]
    end

    %% Native Platform Wrappers
    subgraph "Native Platform Wrappers"
        N1["Android Native Code"]
        N2["iOS Native Code"]
        N3["iOS Podfile"]
    end

    %% Build and CI Infrastructure
    subgraph "Build and CI Infrastructure"
        B1["Configuration & Linting"]
        B2["CI/CD Workflows"]
    end

    %% Connections between layers
    %% Mobile Frontend to API Layer
    M1 -->|"triggers"| A1
    M2 -->|"navigates"| M1
    M3 -->|"updates"| M1
    M4 -->|"supports"| M1

    %% API Layer interactions with External Services
    A1 -->|"HTTP_request"| E1
    A1 -->|"HTTP_request"| E2
    E1 -->|"HTTP_response"| A1
    E2 -->|"HTTP_response"| A1

    %% API Layer interactions with Local DB
    A2 -->|"read/write"| E3
    A3 -->|"query"| E3
    A1 -->|"data_update"| M1

    %% Native Platform integration
    N1 --- M1
    N2 --- M1
    N3 --- N2

    %% Build and Infrastructure supporting layers
    B1 -->|"configures"| M1
    B1 -->|"configures"| A1
    B2 -->|"triggers"| B1

    %% Styling with classes
    class M1,M2,M3,M4 frontend
    class A1,A2,A3,A4,A5 backend
    class E1,E2,E3 external
    class N1,N2,N3 native
    class B1,B2 infra

    %% Click Events for Mobile Frontend
    click M1 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/components"
    click M2 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/navigation"
    click M3 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/hooks"
    click M4 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/utils"

    %% Click Events for API and Data Layer
    click A1 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/api/client"
    click A2 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/src/api/db/models"
    click A3 "https://github.com/knut-capstone-design-team-1/wip-application-v2/blob/main/src/api/db/query.ts"
    click A4 "https://github.com/knut-capstone-design-team-1/wip-application-v2/blob/main/src/api/server.ts"
    click A5 "https://github.com/knut-capstone-design-team-1/wip-application-v2/blob/main/src/api/update.ts"

    %% Click Events for Native Platform
    click N1 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/android/app/src/main/java/com/mbm/whatispill"
    click N2 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/ios/whatispill"
    click N3 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/ios/Podfile"

    %% Click Events for Build and CI Infrastructure
    click B1 "https://github.com/knut-capstone-design-team-1/wip-application-v2/blob/main/.eslintrc.js"
    click B2 "https://github.com/knut-capstone-design-team-1/wip-application-v2/tree/main/.github/workflows"

    %% Class Definitions with Colors
    classDef frontend fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
    classDef backend fill:#ECF0F1,stroke:#2C3E50,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef native fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef infra fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
