# astatochek/angular-fire-messenger architecture

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

- Interactive diagram: https://gitdiagram.com/astatochek/angular-fire-messenger
- Repository: https://github.com/astatochek/angular-fire-messenger

## Overview

##### Main Components

A. Frontend Layer (Angular):
- Present the following major components in a hierarchical structure:
- Core Components
- App Component (root)
- Navbar Component
- Authentication Components
- Login Component
- Register Component
- Feature Components
- Chats Component (parent)
- Chat Component (child)
- Message Component (child)
- Menu Item Component (child)
- Profile Component
- Search Component
- Avatar Component

B. Services Layer:
- AuthService
- ChatService
- SearchService

C. Models Layer:
- User
- Chat
- Message

D. Backend Services (Firebase):
- Firebase Authentication
- Firebase Hosting
- Firebase Realtime Database/Firestore
- Firebase Storage (for avatars/media)

**┌─────────────────────────────────────────────────────────┐**
- Client Browser                        │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Angular Frontend                      │
- ┬──────────────────┬────────────────────────┤
- Components │    Services      │        Models          │
- (UI Layer) │  (Logic Layer)   │    (Data Layer)       │
- ┴──────────────────┴────────────────────────┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Firebase Backend                      │
- ┬─────────────────┬────────────────────────┤
- Auth      │   Database      │        Hosting         │
- ┴─────────────────┴────────────────────────┘

##### Important Elements to Highlight

A. Authentication Flow:
- Interaction between Login/Register components and Firebase Auth
- How AuthService mediates this communication

B. Real-time Chat Flow:
- Demonstrate the real-time data flow from Firebase to Chat components
- How ChatService handles message synchronization

C. Data Flow:
- How data moves from Firebase through services to components
- Relationship between models and their corresponding services

##### Specific Implementation Notes

- Use of Angular's dependency injection system
- How the pipes (TruncatePipe) fit into the architecture
- Where environment configurations are used
- How the routing module manages navigation between components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Browser"]
        Browser[Web Browser]
    end

    subgraph Angular["Angular Frontend"]
        subgraph Components["Components Layer"]
            AppComponent["App Component"]:::component
            NavbarComponent["Navbar Component"]:::component
            
            subgraph Auth["Authentication Components"]
                LoginComponent["Login Component"]:::component
                RegisterComponent["Register Component"]:::component
            end
            
            subgraph Features["Feature Components"]
                ChatsComponent["Chats Component"]:::component
                ChatComponent["Chat Component"]:::component
                MessageComponent["Message Component"]:::component
                MenuItemComponent["Menu Item Component"]:::component
                ProfileComponent["Profile Component"]:::component
                SearchComponent["Search Component"]:::component
                AvatarComponent["Avatar Component"]:::component
            end
        end

        subgraph Services["Services Layer"]
            AuthService["Auth Service"]:::service
            ChatService["Chat Service"]:::service
            SearchService["Search Service"]:::service
        end

        subgraph Models["Models Layer"]
            UserModel["User Model"]:::model
            ChatModel["Chat Model"]:::model
            MessageModel["Message Model"]:::model
        end

        Router["Routing Module"]:::config
        Environment["Environment Config"]:::config
    end

    subgraph Firebase["Firebase Backend"]
        Auth["Firebase Auth"]:::firebase
        Database["Firebase Database"]:::firebase
        Storage["Firebase Storage"]:::firebase
        Hosting["Firebase Hosting"]:::firebase
    end

    subgraph Deployment["Deployment"]
        GithubActions["GitHub Actions"]:::deployment
    end

    %% Relationships
    Browser --> AppComponent
    AppComponent --> NavbarComponent
    AppComponent --> Router
    
    Router --> LoginComponent
    Router --> RegisterComponent
    Router --> ChatsComponent
    Router --> ProfileComponent
    Router --> SearchComponent
    
    ChatsComponent --> ChatComponent
    ChatsComponent --> MenuItemComponent
    ChatComponent --> MessageComponent
    ChatComponent --> AvatarComponent
    
    AuthService --> Auth
    ChatService --> Database
    SearchService --> Database
    
    LoginComponent --> AuthService
    RegisterComponent --> AuthService
    ChatsComponent --> ChatService
    SearchComponent --> SearchService
    
    ChatService --> ChatModel
    ChatService --> MessageModel
    AuthService --> UserModel
    
    GithubActions --> Hosting

    %% Click Events
    click AppComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/app.component.ts"
    click NavbarComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/navbar/navbar.component.ts"
    click LoginComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/login/login.component.ts"
    click RegisterComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/register/register.component.ts"
    click ChatsComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/chats/chats.component.ts"
    click ChatComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/chats/chat/chat.component.ts"
    click MessageComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/chats/message/message.component.ts"
    click MenuItemComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/chats/menu-item/menu-item.component.ts"
    click ProfileComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/profile/profile.component.ts"
    click SearchComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/search/search.component.ts"
    click AvatarComponent "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/components/avatar/avatar.component.ts"
    click AuthService "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/services/auth.service.ts"
    click ChatService "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/services/chat.service.ts"
    click SearchService "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/services/search.service.ts"
    click UserModel "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/models/user.ts"
    click ChatModel "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/models/chat.ts"
    click MessageModel "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/models/message.ts"
    click Router "https://github.com/astatochek/angular-fire-messenger/blob/main/src/app/app-routing.module.ts"
    click Environment "https://github.com/astatochek/angular-fire-messenger/blob/main/src/environments/environment.ts"
    click GithubActions "https://github.com/astatochek/angular-fire-messenger/blob/main/.github/workflows/firebase-hosting-merge.yml"
    click Hosting "https://github.com/astatochek/angular-fire-messenger/blob/main/firebase.json"

    %% Styles
    classDef component fill:#4A90E2,color:white
    classDef service fill:#9B59B6,color:white
    classDef model fill:#2ECC71,color:white
    classDef firebase fill:#FF7F50,color:white
    classDef config fill:#95A5A6,color:white
    classDef deployment fill:#E74C3C,color:white
```
