# rpc1418/messengerclone architecture

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

- Interactive diagram: https://gitdiagram.com/rpc1418/messengerclone
- Repository: https://github.com/rpc1418/messengerclone

## Overview

MessengerClone is a SwiftUI messaging app whose main workflow is Firebase-backed sign-in, loading the authenticated profile, browsing chats or contacts, and exchanging messages. The graph shows the documented contacts-sync and settings capabilities alongside chat and authentication. Edges are limited to relationships visible in excerpts, the SOURCE INDEX, or README; unsampled feature links are omitted where their callers cannot be verified.

Main entry points: [`MessengerClone/Core/Services/ChatService.swift`](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/ChatService.swift) (Chat service), [`MessengerClone/ViewModels/Auth/AuthViewModel.swift`](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Auth/AuthViewModel.swift) (Authentication state), [`MessengerClone/Core/Services/FirestoreService.swift`](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/FirestoreService.swift) (User profile service), [`MessengerClone/App/ContentView.swift`](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/App/ContentView.swift) (Navigation host)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and navigation"]
  node_user["App user<br/>[AppUser.swift]"]
  node_root["App root<br/>[RootView.swift]"]
  node_content["Navigation host<br/>[ContentView.swift]"]
  node_router["Route state<br/>[AppRouter.swift]"]
end

subgraph group_auth["Authentication"]
  node_authui["Sign-in and registration<br/>[LoginView.swift]"]
  node_authvm["Authentication state"]
  node_authservice["Firebase authentication<br/>[AuthService.swift]"]
  node_profiledata["User profile service"]
end

subgraph group_messaging["Messaging"]
  node_chatmodel["Chat model<br/>[Chat.swift]"]
  node_message["Message model<br/>[Message.swift]"]
  node_home["Chat list UI"]
  node_homevm["Chat list state"]
  node_chatui["Conversation UI<br/>[ChatView.swift]"]
  node_chatvm["Conversation state"]
  node_chatservice["Chat service<br/>[ChatService.swift]"]
end

subgraph group_contacts["Contacts and storage"]
  node_contactsui["People and contacts<br/>[PeopleView.swift]"]
  node_contactvm["Contact sync"]
  node_localdb[("Registered contacts")]
end

subgraph group_profile["Profile and settings"]
  node_settingsui["Profile and settings<br/>[ProfileView.swift]"]
  node_settingsvm["Settings state"]
  node_theme["Theme preference<br/>[ThemeManager.swift]"]
end

node_firebaseauth{{"Firebase Auth"}}
node_firestore[("Firebase Firestore")]

node_content -->|"shows"| node_root
node_content -->|"binds routes"| node_router
node_content -->|"routes to"| node_authui
node_root -->|"uses"| node_authvm
node_root -->|"uses"| node_router
node_authui -->|"invokes"| node_authvm
node_authui -->|"navigates via"| node_router
node_authvm -->|"calls"| node_authservice
node_authvm -->|"loads profile"| node_profiledata
node_authservice -.->|"authenticates with"| node_firebaseauth
node_profiledata -->|"reads and writes"| node_firestore
node_profiledata -->|"decodes"| node_user
node_home -->|"uses"| node_homevm
node_homevm -->|"calls"| node_chatservice
node_chatui -->|"uses"| node_chatvm
node_chatui -->|"sends messages"| node_chatservice
node_chatvm -->|"listens and fetches"| node_chatservice
node_chatservice -->|"reads and writes"| node_firestore
node_chatservice -->|"constructs"| node_chatmodel
node_chatservice -->|"constructs"| node_message
node_contactsui -.->|"uses"| node_contactvm
node_contactvm -->|"persists contacts"| node_localdb
node_contactvm -->|"resolves users"| node_profiledata
node_localdb -->|"stores fields from"| node_user
node_settingsui -->|"uses"| node_settingsvm
node_settingsui -->|"binds preference"| node_theme
node_settingsvm -->|"reads user state"| node_authvm

click node_user "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/AppUser.swift"
click node_chatmodel "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/Chat.swift"
click node_message "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/Message.swift"
click node_root "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/RootView.swift"
click node_content "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/App/ContentView.swift"
click node_router "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/AppRouter.swift"
click node_authui "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Auth/Registration/LoginView.swift"
click node_authvm "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Auth/AuthViewModel.swift"
click node_authservice "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/AuthService.swift"
click node_profiledata "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/FirestoreService.swift"
click node_home "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Home/HomeChatsView.swift"
click node_homevm "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Home/HomeChatsViewModel.swift"
click node_chatui "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Chat/ChatView.swift"
click node_chatvm "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Chat/ChatViewModel.swift"
click node_chatservice "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/ChatService.swift"
click node_contactsui "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/People/PeopleView.swift"
click node_contactvm "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/People/ContactViewModel.swift"
click node_localdb "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/LocalStorage/PersistenceController.swift"
click node_settingsui "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/ProfileAndSettings/ProfileView.swift"
click node_settingsvm "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/ProfileAndSettings/SettingsViewModel.swift"
click node_theme "https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/AppTheme/ThemeManager.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user,node_root,node_content,node_router toneBlue
class node_authui,node_authvm,node_authservice,node_profiledata,node_firestore toneAmber
class node_chatmodel,node_message,node_home,node_homevm,node_chatui,node_chatvm,node_chatservice toneMint
class node_contactsui,node_contactvm,node_localdb toneRose
class node_settingsui,node_settingsvm,node_theme,node_firebaseauth toneIndigo
```

## Components

### App and navigation

- [App user](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/AppUser.swift): `MessengerClone/Model/AppUser.swift`
- [App root](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/RootView.swift): `MessengerClone/Views/RootView.swift`
- [Navigation host](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/App/ContentView.swift): `MessengerClone/App/ContentView.swift`
- [Route state](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/AppRouter.swift): `MessengerClone/Core/AppRouter.swift`

### Authentication

- [Sign-in and registration](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Auth/Registration/LoginView.swift): `MessengerClone/Views/Auth/Registration/LoginView.swift`
- [Authentication state](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Auth/AuthViewModel.swift): `MessengerClone/ViewModels/Auth/AuthViewModel.swift`
- [Firebase authentication](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/AuthService.swift): `MessengerClone/Core/Services/AuthService.swift`
- [User profile service](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/FirestoreService.swift): `MessengerClone/Core/Services/FirestoreService.swift`

### Messaging

- [Chat model](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/Chat.swift): `MessengerClone/Model/Chat.swift`
- [Message model](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Model/Message.swift): `MessengerClone/Model/Message.swift`
- [Chat list UI](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Home/HomeChatsView.swift): `MessengerClone/Views/Home/HomeChatsView.swift`
- [Chat list state](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Home/HomeChatsViewModel.swift): `MessengerClone/ViewModels/Home/HomeChatsViewModel.swift`
- [Conversation UI](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/Chat/ChatView.swift): `MessengerClone/Views/Chat/ChatView.swift`
- [Conversation state](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/Chat/ChatViewModel.swift): `MessengerClone/ViewModels/Chat/ChatViewModel.swift`
- [Chat service](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/Services/ChatService.swift): `MessengerClone/Core/Services/ChatService.swift`

### Contacts and storage

- [People and contacts](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/People/PeopleView.swift): `MessengerClone/Views/People/PeopleView.swift`
- [Contact sync](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/People/ContactViewModel.swift): `MessengerClone/ViewModels/People/ContactViewModel.swift`
- [Registered contacts](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Core/LocalStorage/PersistenceController.swift): `MessengerClone/Core/LocalStorage/PersistenceController.swift`

### Profile and settings

- [Profile and settings](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/Views/ProfileAndSettings/ProfileView.swift): `MessengerClone/Views/ProfileAndSettings/ProfileView.swift`
- [Settings state](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/ViewModels/ProfileAndSettings/SettingsViewModel.swift): `MessengerClone/ViewModels/ProfileAndSettings/SettingsViewModel.swift`
- [Theme preference](https://github.com/rpc1418/messengerclone/blob/main/MessengerClone/AppTheme/ThemeManager.swift): `MessengerClone/AppTheme/ThemeManager.swift`

### Other components

- **Firebase Auth**
- **Firebase Firestore**

## Connections

- Navigation host → App root: shows (evidence: `MessengerClone/App/ContentView.swift`)
- Navigation host → Route state: binds routes (evidence: `MessengerClone/App/ContentView.swift`)
- Navigation host → Sign-in and registration: routes to (evidence: `MessengerClone/App/ContentView.swift`)
- App root → Authentication state: uses (evidence: `MessengerClone/Views/RootView.swift`)
- App root → Route state: uses (evidence: `MessengerClone/Views/RootView.swift`)
- Sign-in and registration → Authentication state: invokes (evidence: `MessengerClone/Views/Auth/Registration/LoginView.swift`)
- Sign-in and registration → Route state: navigates via (evidence: `MessengerClone/Views/Auth/Registration/LoginView.swift`)
- Authentication state → Firebase authentication: calls (evidence: `MessengerClone/ViewModels/Auth/AuthViewModel.swift`)
- Authentication state → User profile service: loads profile (evidence: `MessengerClone/ViewModels/Auth/AuthViewModel.swift`)
- Firebase authentication → Firebase Auth: authenticates with
- User profile service → Firebase Firestore: reads and writes (evidence: `MessengerClone/Core/Services/FirestoreService.swift`)
- User profile service → App user: decodes (evidence: `MessengerClone/Core/Services/FirestoreService.swift`)
- Chat list UI → Chat list state: uses (evidence: `MessengerClone/Views/Home/HomeChatsView.swift`)
- Chat list state → Chat service: calls (evidence: `MessengerClone/ViewModels/Home/HomeChatsViewModel.swift`)
- Conversation UI → Conversation state: uses (evidence: `MessengerClone/Views/Chat/ChatView.swift`)
- Conversation UI → Chat service: sends messages (evidence: `MessengerClone/Views/Chat/ChatView.swift`)
- Conversation state → Chat service: listens and fetches (evidence: `MessengerClone/ViewModels/Chat/ChatViewModel.swift`)
- Chat service → Firebase Firestore: reads and writes (evidence: `MessengerClone/Core/Services/ChatService.swift`)
- Chat service → Chat model: constructs (evidence: `MessengerClone/Core/Services/ChatService.swift`)
- Chat service → Message model: constructs (evidence: `MessengerClone/Core/Services/ChatService.swift`)
- People and contacts → Contact sync: uses
- Contact sync → Registered contacts: persists contacts (evidence: `MessengerClone/ViewModels/People/ContactViewModel.swift`)
- Contact sync → User profile service: resolves users (evidence: `MessengerClone/ViewModels/People/ContactViewModel.swift`)
- Registered contacts → App user: stores fields from (evidence: `MessengerClone/Core/LocalStorage/PersistenceController.swift`)
- Profile and settings → Settings state: uses (evidence: `MessengerClone/Views/ProfileAndSettings/ProfileView.swift`)
- Profile and settings → Theme preference: binds preference (evidence: `MessengerClone/Views/ProfileAndSettings/ProfileView.swift`)
- Settings state → Authentication state: reads user state (evidence: `MessengerClone/ViewModels/ProfileAndSettings/SettingsViewModel.swift`)
