# gaonuk/nopti architecture

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

- Interactive diagram: https://gitdiagram.com/gaonuk/nopti
- Repository: https://github.com/gaonuk/nopti

## Overview

##### Project type and purpose
- This is a cross-platform mobile (iOS, Android) and web application built with Expo and React Native, using the Expo Router’s file-based routing.
- It includes a client UI layer, local assets, shared components/hooks, API endpoints under `api/`, and backend business logic implemented as serverless functions in `functions/`.
- The app’s primary feature set appears to center on conversational or content services (chat, media, ranking, JSON updates).

##### File structure
Top-level directories and meaning:
- app/ – Frontend screens and routing (tabs like conversation, explore, media).
- components/ – Reusable UI building blocks (ThemedText/View, ParallaxScrollView).
- hooks/ – Custom React hooks encapsulating data-fetching and theming logic (useChatService, useUserContent).
- api/ – File-based API route(s) (contentService.tsx) exposed by Expo Router.
- functions/ – Independent serverless functions (generateResponse.ts, rankContent.ts, updateJson.ts) that power core backend operations.
- assets/ – Static resources (fonts, images, binary tokenizer model).
- ios/, babel.config.js, metro.config.js, eas.json – Build and deployment configuration for Expo/EAS and the Metro bundler.

##### README for additional insights
- No mention of a separate database—likely JSON files or external LLM APIs invoked by serverless functions.

a. Main components:
1. Client (Mobile & Web):
– Expo App & Expo Go / Standalone build
– UI Screens & Navigation (app/(tabs)/…)
– Shared Components & Hooks
– Local Asset Store (fonts, images, tokenizer.bin)
2. API Layer:
– Expo Router API Endpoint (api/contentService.tsx)
3. Backend Functions:
– Serverless Functions (functions/generateResponse, rankContent, updateJson)
4. External Services / Data Stores:
– Optional JSON store (if updateJson writes to a file or cloud storage)
– External LLM or ranking API (e.g. OpenAI, custom ML)

b. Relationships & interactions:
1. User interacts with the UI (e.g. submits a chat prompt).
2. UI hook (useChatService) sends HTTP request to API Layer (`/api/contentService`).
3. API layer orchestrates calls to serverless functions in sequence:
- generateResponse → calls external LLM service
- rankContent → orders or filters responses
- updateJson → persists conversation updates
4. API returns enriched content back to the client.
5. Client updates its state and renders the result.

c. Architectural patterns & principles:
- File-based routing (Expo Router) for both views and API endpoints.
- Separation of concerns: UI layer vs data layer vs business logic.
- Serverless microservices for on-demand scalability.
- React hooks to encapsulate data-fetching and theming.
- Asset bundling via Metro and Expo’s asset pipeline.

d. Key technologies & libraries:
- Expo & React Native for cross-platform UI
- Expo Router for file-based routing (screens & API)
- Serverless functions (Node/TypeScript)
- Custom hooks (useChatService, useUserContent)
- Metro bundler & EAS for building and deployment

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Client (Mobile & Web)"
    subgraph "UI Screens & Navigation"
      conv["conversation.tsx"]
      exp["explore.tsx"]
      inter["interaction.tsx"]
      media["media.tsx"]
      indexTS["index.tsx"]
      layoutRoot["_layout.tsx"]
      layoutTabs["_layout.tsx"]
      notFound["+not-found.tsx"]
    end
    subgraph "Shared UI Components"
      coll["Collapsible.tsx"]
      extLink["ExternalLink.tsx"]
      haptic["HapticTab.tsx"]
      hello["HelloWave.tsx"]
      parallax["ParallaxScrollView.tsx"]
      themedText["ThemedText.tsx"]
      themedView["ThemedView.tsx"]
      iconSym["IconSymbol.tsx"]
      iconSymIOS["IconSymbol.ios.tsx"]
      tabBg["TabBarBackground.tsx"]
      tabBgIOS["TabBarBackground.ios.tsx"]
    end
    subgraph "Custom Hooks"
      chatService["useChatService.ts"]
      userContent["useUserContent.ts"]
      colorScheme["useColorScheme.ts"]
      colorSchemeWeb["useColorScheme.web.ts"]
      themeColor["useThemeColor.ts"]
    end
    subgraph "Local Assets"
      fonts["fonts/"]
      images["images/"]
      tokenizer["tokenizer.bin"]
    end
  end

  subgraph "API Layer"
    apiCS["contentService.tsx"]
  end

  subgraph "Serverless Functions"
    genResp["generateResponse.ts"]
    rankCont["rankContent.ts"]
    updJson["updateJson.ts"]
  end

  subgraph "External Services / Data Store"
    llm["External LLM API"]
    jsonStore["JSON Store"]
  end

  conv -->|"uses"| chatService
  chatService -->|"POST /api/contentService"| apiCS
  apiCS -->|"invoke"| genResp
  genResp -->|"LLM call"| llm
  llm -->|"response"| rankCont
  rankCont -->|"rank"| updJson
  updJson -->|"Write JSON"| jsonStore
  jsonStore -->|"read/write"| apiCS
  apiCS -->|"returns data"| chatService
  chatService -->|"update UI"| conv

  click conv "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/conversation.tsx"
  click exp "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/explore.tsx"
  click inter "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/interaction.tsx"
  click media "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/media.tsx"
  click indexTS "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/index.tsx"
  click layoutRoot "https://github.com/gaonuk/nopti/blob/main/app/_layout.tsx"
  click layoutTabs "https://github.com/gaonuk/nopti/blob/main/app/(tabs)/_layout.tsx"
  click notFound "https://github.com/gaonuk/nopti/blob/main/app/+not-found.tsx"
  click coll "https://github.com/gaonuk/nopti/blob/main/components/Collapsible.tsx"
  click extLink "https://github.com/gaonuk/nopti/blob/main/components/ExternalLink.tsx"
  click haptic "https://github.com/gaonuk/nopti/blob/main/components/HapticTab.tsx"
  click hello "https://github.com/gaonuk/nopti/blob/main/components/HelloWave.tsx"
  click parallax "https://github.com/gaonuk/nopti/blob/main/components/ParallaxScrollView.tsx"
  click themedText "https://github.com/gaonuk/nopti/blob/main/components/ThemedText.tsx"
  click themedView "https://github.com/gaonuk/nopti/blob/main/components/ThemedView.tsx"
  click iconSym "https://github.com/gaonuk/nopti/blob/main/components/ui/IconSymbol.tsx"
  click iconSymIOS "https://github.com/gaonuk/nopti/blob/main/components/ui/IconSymbol.ios.tsx"
  click tabBg "https://github.com/gaonuk/nopti/blob/main/components/ui/TabBarBackground.tsx"
  click tabBgIOS "https://github.com/gaonuk/nopti/blob/main/components/ui/TabBarBackground.ios.tsx"
  click chatService "https://github.com/gaonuk/nopti/blob/main/hooks/useChatService.ts"
  click userContent "https://github.com/gaonuk/nopti/blob/main/hooks/useUserContent.ts"
  click colorScheme "https://github.com/gaonuk/nopti/blob/main/hooks/useColorScheme.ts"
  click colorSchemeWeb "https://github.com/gaonuk/nopti/blob/main/hooks/useColorScheme.web.ts"
  click themeColor "https://github.com/gaonuk/nopti/blob/main/hooks/useThemeColor.ts"
  click fonts "https://github.com/gaonuk/nopti/tree/main/assets/fonts/"
  click images "https://github.com/gaonuk/nopti/tree/main/assets/images/"
  click tokenizer "https://github.com/gaonuk/nopti/blob/main/assets/images/tokenizer.bin"
  click apiCS "https://github.com/gaonuk/nopti/blob/main/api/contentService.tsx"
  click genResp "https://github.com/gaonuk/nopti/blob/main/functions/generateResponse.ts"
  click rankCont "https://github.com/gaonuk/nopti/blob/main/functions/rankContent.ts"
  click updJson "https://github.com/gaonuk/nopti/blob/main/functions/updateJson.ts"

  classDef client fill:#D0E8FF,stroke:#333
  classDef api fill:#D0FFD8,stroke:#333
  classDef functions fill:#FFE0B2,stroke:#333
  classDef external fill:#E1D5E7,stroke:#333

  class conv,exp,inter,media,indexTS,layoutRoot,layoutTabs,notFound,coll,extLink,haptic,hello,parallax,themedText,themedView,iconSym,iconSymIOS,tabBg,tabBgIOS,chatService,userContent,colorScheme,colorSchemeWeb,themeColor,fonts,images,tokenizer client
  class apiCS api
  class genResp,rankCont,updJson functions
  class llm,jsonStore external
```
