# martiandreamer/chat_application_web architecture

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

- Interactive diagram: https://gitdiagram.com/martiandreamer/chat_application_web
- Repository: https://github.com/martiandreamer/chat_application_web

## Overview

##### Project Type and Purpose
- The file structure is very modular with distinct directories for UI components, services, directives, pipes, and routing modules. This modularization indicates a design focused on component reusability and clear separation of concerns.

##### Analyzing the File Structure
- Top-Level Directories and Files:
- Files like angular.json, package.json, README.md, and tsconfig files indicate a standard Angular project.
- src/ contains all the application code.
- Under src/app, there are several high-level folders:
- There are also directories like “login”, “registration”, and “confirmation” which handle user authentication and account confirmation flows.
- The “interceptor” folder includes an authentication interceptor, while “service” contains routing guards and authentication-related services.
- Directories “directive” and “pipe” include custom UI directives (such as auto-focus and draggable-component) and a date pipe.
- This structure suggests an MVC/MVVM-like separation, with components handling the view layer, services encapsulating business logic/communication, and additional layers for routing and authentication.

##### Key Components and Their Interactions
a. Main Components:
- Core Modules: The top-level AppModule and the specialized ChatAppModule within “src/app/chat-app”.
- UI Components: ChatBox (with nested conversation content components), Conversation List, Friend List (and its various items), Navbar, Avatar Click Menu, My Account, Login, Registration, and Confirmation components.
- Shared Directives and Pipes: Custom directives for UI behavior and a date pipe for formatting.
- Services and Interceptors: Conversation, Friend, Notification, Self, and WebSocket connection services; authentication service; auth guard service; and the authentication interceptor to manage HTTP requests.
- Model Definitions: User, Conversation, Friend, Login body, and Notification model types.
b. Relationships and Interactions:
- Routing: The various routing modules (app-routing.module.ts and chat-app-routing.module.ts) wire up navigation between components.
- Communication: UI components call their corresponding services for data (e.g., conversation service for chat messages, friend service for friend list changes), and these services, in turn, manage external API calls or WebSocket connections.
- Authentication: Login and registration components interact with authentication services and are protected by the auth guard service along with being intercepted by the authentication interceptor.
- Directives and Pipes: Custom directives are used to enhance UI interactions (like auto-focusing or making components draggable), and the date pipe formats dates for display within the chat.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Angular Core
    subgraph "Angular Core"
        AAM["Angular App Module"]:::routing
        AMR["App Routing Module"]:::routing
    end
    AAM --> AMR

    %% Chat Core
    subgraph "Chat Core"
        CAM["Chat Application Module"]:::routing
        CAR["Chat Application Routing"]:::routing
    end
    AMR --> CAM
    CAM --> CAR

    %% UI Components
    subgraph "UI Components"
        direction TB
        subgraph "Authentication UI"
            LC["Login Component"]:::auth
            RC["Registration Component"]:::auth
            CC["Confirmation Component"]:::auth
        end

        subgraph "Chat Application UI"
            direction TB
            CB["Chat Box Component"]:::chat
            subgraph "Chat Box Details"
                direction TB
                CCt["Conversation Content"]:::chat
                AF["Attachment Frame"]:::chat
                MF["Message Frame"]:::chat
                UI["User Input"]:::chat
            end
            CL["Conversation List"]:::chat
            subgraph "Conversation List Details"
                direction TB
                CI["Conversation Item"]:::chat
                MC["My Conversations"]:::chat
                NCFI["New Conversation Friend Item"]:::chat
                NCFL["New Conversation Friend List"]:::chat
            end
            FL["Friend List"]:::chat
            subgraph "Friend List Details"
                direction TB
                FI["Friend Item"]:::chat
                FSL["Friendship List"]:::chat
                FMR["From-Me Request"]:::chat
                RL["Request List"]:::chat
                SI["Search Item"]:::chat
                SL["Search List"]:::chat
                TMR["To-Me Request Item"]:::chat
            end
            AC["Avatar Click Menu"]:::chat
            NB["Navbar"]:::chat
            MA["My Account"]:::chat
            M["Modal"]:::chat
        end
    end

    %% Shared Directives & Pipes
    subgraph "Shared Directives & Pipes"
        AD["Auto-Focus Directive"]:::directive
        DD["Draggable Directive"]:::directive
        DP["Date Pipe"]:::directive
    end

    %% Services / Business Logic
    subgraph "Services / Business Logic"
        CS["Conversation Service"]:::service
        FS["Friend Service"]:::service
        NS["Notification Service"]:::service
        SS["Self Service"]:::service
        WS["WebSocket Service"]:::service
        AS["Authentication Service"]:::service
        AGS["Auth Guard Service"]:::service
        AI["Authentication Interceptor"]:::service
        MD["Models"]:::service
    end

    %% External APIs
    subgraph "External APIs"
        EXT["REST API/WebSocket Server"]:::external
    end

    %% Routing from Chat Application Routing to UI Components
    CAR --> LC
    CAR --> RC
    CAR --> CC
    CAR --> CB
    CAR --> CL
    CAR --> FL
    CAR --> AC
    CAR --> NB
    CAR --> MA
    CAR --> M

    %% UI Components to Services / Business Logic interactions
    LC -->|"authRequest"| AS
    RC -->|"registerRequest"| AS
    CC -->|"confirmAccount"| AS
    CB -->|"fetchMessages"| CS
    CB -->|"initWebSocket"| WS
    CL -->|"loadConversations"| CS
    FL -->|"loadFriends"| FS
    NB -->|"fetchNotifications"| NS
    NB -->|"fetchSelfInfo"| SS

    %% UI Components using Shared Directives & Pipes
    CB -.->|"uses"| AD
    CB -.->|"uses"| DD
    CL -.->|"formatsDates"| DP

    %% Services calling External APIs
    AS -->|"calls"| EXT
    CS -->|"calls"| EXT
    FS -->|"calls"| EXT
    WS -->|"calls"| EXT
    NS -->|"calls"| EXT
    SS -->|"calls"| EXT

    %% Auth Guard and Interceptor roles
    AGS ---|"protects"| LC
    AGS ---|"protects"| RC
    AGS ---|"protects"| CC
    AI ---|"intercepts"| AS

    %% Services using Models
    CS -.-> MD
    FS -.-> MD
    NS -.-> MD
    SS -.-> MD
    WS -.-> MD
    AS -.-> MD

    %% Styling Classes
    classDef routing fill:#F0F4C8,stroke:#7F8C8D,stroke-width:2px;
    classDef auth fill:#FFC0CB,stroke:#C2185B,stroke-width:2px;
    classDef chat fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef service fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef external fill:#FFECB3,stroke:#FF6F00,stroke-width:2px;
    classDef directive fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;

    %% Click Events
    click AAM "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/app.module.ts"
    click AMR "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/app-routing.module.ts"
    click CAM "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-app.module.ts"
    click CAR "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-app-routing.module.ts"
    click CB "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-box/chat-box.component.ts"
    click CCt "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-box/conversation-content/conversation-content.component.ts"
    click AF "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-box/conversation-content/attachment-frame/attachment-frame.component.ts"
    click MF "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-box/conversation-content/message-frame/message-frame.component.ts"
    click UI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/chat-box/user-input/user-input.component.ts"
    click CL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/conversation-list/conversation-list.component.ts"
    click CI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/conversation-list/conversation-item/conversation-item.component.ts"
    click MC "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/conversation-list/my-conversations/my-conversations.component.ts"
    click NCFI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/conversation-list/new-conversation-friend-item/new-conversation-friend-item.component.ts"
    click NCFL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/conversation-list/new-conversation-friend-list/new-conversation-friend-list.component.ts"
    click FL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/friend-list.component.ts"
    click FI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/friend-item/friend-item.component.ts"
    click FSL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/friendship-list/friendship-list.component.ts"
    click FMR "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/from-me-request/from-me-request.component.ts"
    click RL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/request-list/request-list.component.ts"
    click SI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/search-item/search-item.component.ts"
    click SL "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/search-list/search-list.component.ts"
    click TMR "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/friend-list/to-me-request-item/to-me-request-item.component.ts"
    click AC "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/avatar-click-menu/avatar-click-menu.component.ts"
    click NB "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/navbar/navbar.component.ts"
    click MA "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/my-account/my-account.component.ts"
    click M "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/modal/modal.component.ts"
    click LC "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/login/login.component.ts"
    click RC "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/registration/registration.component.ts"
    click CC "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/confirmation/confirmation.component.ts"
    click AD "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/directive/auto-focus.directive.ts"
    click DD "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/directive/draggable-component.directive.ts"
    click DP "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/pipe/date.pipe.ts"
    click CS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/service/conversation.service.ts"
    click FS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/service/friend.service.ts"
    click NS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/service/notification.service.ts"
    click SS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/service/self.service.ts"
    click WS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/chat-app/service/websocket-connect.service.ts"
    click AS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/service/authentication.service.ts"
    click AGS "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/service/auth-guard.service.ts"
    click AI "https://github.com/martiandreamer/chat_application_web/blob/main/src/app/interceptor/authentication.interceptor.ts"
    click MD "https://github.com/martiandreamer/chat_application_web/tree/main/src/app/chat-app/model/"
```
