# mrboom192/drx architecture

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

- Interactive diagram: https://gitdiagram.com/mrboom192/drx
- Repository: https://github.com/mrboom192/drx

## Overview

##### Project type and purpose
- This is a full-stack mobile application built with Expo/React Native, focused on telehealth (doctor-patient chat, video calls, booking, and medical records).
- Key signals:
- “create-expo-app” starter in README
- file-based routing under src/app (“(call)”, “(chat)”, “tabs”, etc.)
- firebaseConfig.js + webRTCConfig.ts → real-time backend and peer-to-peer video.

##### File structure to extract architectural boundaries
- Top-level directories:
- src/app → screen definitions & routes (UI layer)
- src/components → reusable UI building blocks
- src/api → wrappers for server data (medicalRecords.tsx)
- src/config → service configuration (webrtcConfig, firebaseConfig)
- src/contexts + src/stores → state management (React Context + Zustand)
- src/hooks + src/utils → custom logic and helpers
- assets → static data/images/lottie
- Configuration files (babel.config.js, metro.config.js, tsconfig.json) confirm React Native / TypeScript environment.
- package.json lists dependencies: Expo, React Navigation (router), Zustand, Firebase SDKs, etc.

##### README for techn nical stack
- Expo managed workflow on iOS & Android
- File-based routing via Expo Router
- No in-house backend: uses Firebase for Auth, Firestore/Realtime DB, Storage
- WebRTC for video calls

##### Main components
a. Mobile App (Expo/React Native)
- UI Layer
– File-based Router → defines navigation tree & protected/public routes
– Screens (Chat, Call, Tabs, Modals, Login, Signup)
– Reusable Components (avatars, lists, headers, inputs)
- State & Context Layer
– React Contexts (AuthContext, SignupContext)
– Zustand Stores (appointments, chats, records, user)
– Hooks (useWebRTCCall, useUserPresence, etc.)
- Service / API Layer
– Firebase SDK
· Auth (email/password, token management)
· Firestore (chat messages, bookings, medical records)
· Storage (profile images, radiology images)
– REST/GraphQL (if any external APIs – e.g. src/api/medicalRecords.tsx)
– WebRTC Peer Connection
· STUN/TURN servers (configured in webrtcConfig.ts)
b. External Services
- Firebase Cloud
– Authentication
– Firestore / Real-time Database
– Cloud Storage
- STUN/TURN servers or signaling server for WebRTC
c. Asset Management
- Local static assets (doctorWave animation, flags)
- Dynamic assets loaded from Storage

##### Relationships & interactions
- User taps a UI component → Router dispatches to a Screen
- Screen reads/writes global state via Contexts / Zustand Stores
- Stores or Contexts call API Layer (Firebase SDK)
- For chat: Firestore streams data → update chat store → UI updates in real time
- For calls: useWebRTCCall hook uses webrtcConfig to establish P2P → media flows directly
- Images/radiology data fetched from Cloud Storage → displayed in UI
- Local assets loaded via Metro bundler

##### Architectural patterns & design principles
- File-based routing for navigation (similar to Next.js)
- Separation of concerns: UI vs. State vs. Services
- Hook + Context + Store composition for testable logic
- Modular components for reusability
- Real-time updates via Firebase subscriptions

##### Essential details to capture
- Authentication flow (login/signup) → AuthContext → Firebase Auth
- Routing structure: Protected vs. Public routes
- Core flows: Chat, Video Call, Booking, Medical Records
- State synchronization: local stores vs. real-time updates
- External dependencies: Firebase, STUN/TURN, any third-party SDKs

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile App Layers
    subgraph "Mobile App"
        subgraph "Presentation Layer"
            Router["File-based Router"]:::ui
            Login["Login Screen"]:::ui
            Signup["Signup Screen"]:::ui
            subgraph "Protected Routes"
                ChatLayout["Chat Layout"]:::ui
                ChatDetail["Chat Screen"]:::ui
                CallLayout["Call Layout"]:::ui
                CallDetail["Call Screen"]:::ui
                TabsLayout["Tabs Container"]:::ui
                MessagesTab["Messages Tab"]:::ui
                ProfileTab["Profile Tab"]:::ui
                MedicalRecordsTab["Medical Records Tab"]:::ui
                Modals["Modals"]:::ui
                DoctorLayout["Doctor Details"]:::ui
                Booking["Booking Screen"]:::ui
                Notifications["Notifications Screen"]:::ui
                Search["Search Screen"]:::ui
            end
            Components["Reusable UI Components"]:::ui
        end
        subgraph "State & Business Logic"
            AuthContext["AuthContext"]:::state
            SignupContext["SignupContext"]:::state
            AppointmentStore["Appointment Store"]:::state
            AuthInitStore["Auth Init Store"]:::state
            ChatStore["Chat Store"]:::state
            RecordStore["Medical Record Store"]:::state
            UserStore["User Store"]:::state
            subgraph "Hooks"
                WebRTCHook["useWebRTCCall"]:::state
                PresenceHook["useUserPresence"]:::state
                ImagePickerHook["useImagePicker"]:::state
                StorageStateHook["useStorageState"]:::state
                ThemeStylesHook["useThemeStyles"]:::state
            end
        end
    end

    %% API & Config
    subgraph "API & Config Layer"
        FirebaseSDK["Firebase SDK"]:::service
        MedicalRecordsAPI["MedicalRecords API"]:::service
        WebRTCConfig["WebRTC Config"]:::service
    end

    %% External Services
    subgraph "External Services"
        FirebaseAuth["Firebase Auth"]:::external
        Firestore["Firestore / Realtime DB"]:::external
        CloudStorage["Cloud Storage"]:::external
        STUNTURN["STUN/TURN Servers"]:::external
    end

    %% Assets
    subgraph "Assets"
        LocalImages["Local Images"]:::asset
        Lottie["Lottie Animations"]:::asset
    end

    %% Relationships
    Router -->|routes to| Login
    Router -->|routes to| Signup
    Router -->|routes to| ChatLayout
    Router -->|routes to| CallLayout
    Router -->|routes to| TabsLayout
    Router -->|routes to| Modals
    Router -->|routes to| DoctorLayout
    Router -->|routes to| Notifications
    Router -->|routes to| Search

    ChatLayout -->|renders| ChatDetail
    CallLayout -->|renders| CallDetail
    TabsLayout -->|contains| MessagesTab
    TabsLayout -->|contains| ProfileTab
    ProfileTab -->|has nested| MedicalRecordsTab

    Login -->|dispatch| AuthContext
    Signup -->|dispatch| SignupContext
    ChatDetail -->|uses| ChatStore
    CallDetail -->|uses| WebRTCHook
    Booking -->|uses| AppointmentStore
    ProfileTab -->|reads| RecordStore

    AuthContext -->|calls| FirebaseSDK
    SignupContext -->|calls| FirebaseSDK
    AppointmentStore -->|calls| FirebaseSDK
    ChatStore -->|subscribes| FirebaseSDK
    RecordStore -->|calls| MedicalRecordsAPI
    UserStore -->|calls| FirebaseSDK

    MedicalRecordsAPI -->|REST| Firestore
    FirebaseSDK -->|auth| FirebaseAuth
    FirebaseSDK -->|db| Firestore
    FirebaseSDK -->|storage| CloudStorage
    WebRTCConfig -->|configures| STUNTURN
    WebRTCHook -->|uses| WebRTCConfig

    LocalImages -->|loaded by| Components
    Lottie -->|loaded by| Components

    %% Click Events
    click Router "https://github.com/mrboom192/drx/blob/main/src/app/_layout.tsx"
    click Login "https://github.com/mrboom192/drx/blob/main/src/app/login.tsx"
    click Signup "https://github.com/mrboom192/drx/blob/main/src/app/signup.tsx"
    click ChatLayout "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(chat)/_layout.tsx"
    click ChatDetail "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(chat)/[chatId].tsx"
    click CallLayout "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(call)/_layout.tsx"
    click CallDetail "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(call)/[callId].tsx"
    click TabsLayout "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(tabs)/_layout.tsx"
    click MessagesTab "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(tabs)/messages/index.tsx"
    click ProfileTab "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(tabs)/profile/_layout.tsx"
    click MedicalRecordsTab "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(tabs)/profile/medical-record/_layout.tsx"
    click Modals "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/(modals)/_layout.tsx"
    click DoctorLayout "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/doctor/_layout.tsx"
    click Booking "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/doctor/booking.tsx"
    click Notifications "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/notifications.tsx"
    click Search "https://github.com/mrboom192/drx/blob/main/src/app/(protected)/search.tsx"
    click Components "https://github.com/mrboom192/drx/tree/main/src/components"
    click MedicalRecordsAPI "https://github.com/mrboom192/drx/blob/main/src/api/medicalRecords.tsx"
    click FirebaseSDK "https://github.com/mrboom192/drx/blob/main/firebaseConfig.js"
    click WebRTCConfig "https://github.com/mrboom192/drx/blob/main/src/config/webrtcConfig.ts"
    click AuthContext "https://github.com/mrboom192/drx/blob/main/src/contexts/AuthContext.tsx"
    click SignupContext "https://github.com/mrboom192/drx/blob/main/src/contexts/SignupContext.tsx"
    click AppointmentStore "https://github.com/mrboom192/drx/blob/main/src/stores/useAppointmentStore.tsx"
    click AuthInitStore "https://github.com/mrboom192/drx/blob/main/src/stores/useAuthInitStore.tsx"
    click ChatStore "https://github.com/mrboom192/drx/blob/main/src/stores/useChatStore.tsx"
    click RecordStore "https://github.com/mrboom192/drx/blob/main/src/stores/useRecordStore.tsx"
    click UserStore "https://github.com/mrboom192/drx/blob/main/src/stores/useUserStore.tsx"
    click WebRTCHook "https://github.com/mrboom192/drx/blob/main/src/hooks/useWebRTCCall.tsx"
    click PresenceHook "https://github.com/mrboom192/drx/blob/main/src/hooks/useUserPresence.ts"
    click ImagePickerHook "https://github.com/mrboom192/drx/blob/main/src/hooks/useImagePicker.ts"
    click StorageStateHook "https://github.com/mrboom192/drx/blob/main/src/hooks/useStorageState.ts"
    click ThemeStylesHook "https://github.com/mrboom192/drx/blob/main/src/hooks/useThemeStyles.tsx"

    %% Styles
    classDef ui fill:#e0f7fa,stroke:#006064,color:#006064
    classDef state fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
    classDef service fill:#fff3e0,stroke:#ef6c00,color:#ef6c00
    classDef external fill:#ffebee,stroke:#c62828,color:#c62828
    classDef asset fill:#f3e5f5,stroke:#6a1b9a,color:#6a1b9a
```
