# eraldtorra/messageangular architecture

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

- Interactive diagram: https://gitdiagram.com/eraldtorra/messageangular
- Repository: https://github.com/eraldtorra/messageangular

## Overview

##### Project Type & Purpose
- Project Type: Frontend Single-Page Application (SPA)
- Purpose: Real-time messaging UI built in Angular 19.1.4, leveraging REST and WebSocket backends for login, message exchange, media sharing, read-receipts, etc.

##### Core Architectural Components
a. Browser & Angular App
- index.html → Loads Angular bundle
- main.ts → Bootstraps AppModule
b. Presentation Layer (Components & Pages)
- Pages: Home, Login, Channel-List, Chat
- Shared: Angular Material UI
c. Client-side Routing & Guards
- app.routes.ts → Defines SPA routes
- auth.guard.ts → Protects private pages
d. Services & State Management
- AuthService → Handles login/logout via REST
- WebsocketService → Manages socket.io/SignalR connections
- UsernameService → Tracks current user info
- (Optionally) NgRx store → Centralized application state
e. Models
- message.ts, token.ts → Type definitions for payloads
f. External Backends & Infrastructure
- RESTful API Server (e.g., MessageSpring backend)
- WebSocket Server (socket.io / SignalR endpoint)
- Database (behind backend)
g. Build & Deployment
- Angular CLI / angular.json → Build config
- dist/ → Production bundle for hosting

##### Relationships & Data Flows
- HTTP (REST) Calls:
- Login, fetch message history, search, file uploads → AuthService → REST API → Database
- WebSocket Connections:
- At startup (WebsocketService) → WebSocket Server → Push/pull real-time messages, typing indicators, read receipts
- State Updates:
- Incoming data → WebsocketService → NgRx store → Components subscribe & re-render
- User actions (send message) → Component → WebsocketService.emit() → Server
- Navigation & Guarding:
- User clicks “Chat” → Router navigates to /chat → auth.guard checks token → if valid, allow; else redirect to /login

##### Architectural Patterns & Principles
- Component-Driven UI: Reusable, isolated Angular components per page
- Dependency Injection: Services injected into components for separation of concerns
- Reactive Programming: RxJS Observables for async streams (HTTP & WebSocket)
- Module Separation: Potential Feature Modules (e.g., ChatModule, AuthModule)
- State Management: (NgRx) Single source of truth for message and user state

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["User's Browser"]:::ext
    Browser -->|"Loads"| index.html["index.html"]:::comp
    click index.html "https://github.com/eraldtorra/messageangular/blob/main/src/index.html"
    index.html -->|"Bootstraps"| main.ts["main.ts"]:::comp
    click main.ts "https://github.com/eraldtorra/messageangular/blob/main/src/main.ts"
    main.ts -->|"Initializes"| app.component.ts["app.component.ts"]:::comp
    click app.component.ts "https://github.com/eraldtorra/messageangular/blob/main/src/app/app.component.ts"
    app.component.ts --> app.component.html["app.component.html"]:::comp
    click app.component.html "https://github.com/eraldtorra/messageangular/blob/main/src/app/app.component.html"
    app.component.ts --> app.component.css["app.component.css"]:::comp
    click app.component.css "https://github.com/eraldtorra/messageangular/blob/main/src/app/app.component.css"

    subgraph "Angular SPA"
        subgraph "Presentation Layer"
            Home["Home Component"]:::comp
            click Home "https://github.com/eraldtorra/messageangular/blob/main/src/app/pages/home/home.component.ts"
            Login["Login Component"]:::comp
            click Login "https://github.com/eraldtorra/messageangular/blob/main/src/app/pages/login/login.component.ts"
            ChannelList["Channel-List Component"]:::comp
            click ChannelList "https://github.com/eraldtorra/messageangular/blob/main/src/app/pages/channel-list/channel-list.component.ts"
            Chat["Chat Component"]:::comp
            click Chat "https://github.com/eraldtorra/messageangular/blob/main/src/app/pages/chat/chat.component.ts"
        end

        subgraph "Routing & Guards"
            Routes["App Routes"]:::svc
            click Routes "https://github.com/eraldtorra/messageangular/blob/main/src/app/app.routes.ts"
            Guard["Auth Guard"]:::svc
            click Guard "https://github.com/eraldtorra/messageangular/blob/main/src/app/guards/auth.guard.ts"
        end

        subgraph "Services & State"
            AuthService["AuthService"]:::svc
            click AuthService "https://github.com/eraldtorra/messageangular/blob/main/src/app/services/AuthService.service.ts"
            WebsocketService["WebsocketService"]:::svc
            click WebsocketService "https://github.com/eraldtorra/messageangular/blob/main/src/app/services/websocket.service.ts"
            UsernameService["UsernameService"]:::svc
            click UsernameService "https://github.com/eraldtorra/messageangular/blob/main/src/app/services/username.service.ts"
            Store["NgRx Store"]:::svc
        end

        subgraph "Configuration"
            AppConfig["App Config"]:::comp
            click AppConfig "https://github.com/eraldtorra/messageangular/blob/main/src/app/app.config.ts"
        end
    end

    subgraph "External Backends"
        RESTAPI["REST API Server"]:::ext
        WSServer["WebSocket Server"]:::ext
        Database["Database"]:::ext
    end

    subgraph "Build & Deployment"
        AngularJSON["angular.json"]:::comp
        click AngularJSON "https://github.com/eraldtorra/messageangular/blob/main/angular.json"
        PackageJSON["package.json"]:::comp
        click PackageJSON "https://github.com/eraldtorra/messageangular/blob/main/package.json"
        PackageLock["package-lock.json"]:::comp
        click PackageLock "https://github.com/eraldtorra/messageangular/blob/main/package-lock.json"
        TSConfig["tsconfig.json"]:::comp
        click TSConfig "https://github.com/eraldtorra/messageangular/blob/main/tsconfig.json"
        TSApp["tsconfig.app.json"]:::comp
        click TSApp "https://github.com/eraldtorra/messageangular/blob/main/tsconfig.app.json"
        TSSpec["tsconfig.spec.json"]:::comp
        click TSSpec "https://github.com/eraldtorra/messageangular/blob/main/tsconfig.spec.json"
        Dist["dist/"]:::comp
    end

    %% Navigation & Guarding
    Home -->|"navigate /chat"| Routes
    Routes --> Guard
    Guard -->|"token valid"| Chat
    Guard -->|"token invalid"| Login

    %% Auth Flow
    Login -->|"login()"| AuthService
    AuthService -->|"HTTP (REST)"| RESTAPI
    RESTAPI -->|"token"| AuthService
    AuthService -->|"store token"| Store

    %% Channels & Messages
    ChannelList -->|"GET /channels"| RESTAPI
    RESTAPI -->|"channels data"| Store
    Store -->|"channels"| ChannelList

    Chat -->|"GET /messages"| RESTAPI
    RESTAPI -->|"messages data"| Store
    Store -->|"messages"| Chat

    Chat -->|"sendMessage()"| WebsocketService
    WebsocketService -->|"WS"| WSServer
    WSServer -->|"push message"| WebsocketService
    WebsocketService -->|"update"| Store
    Store -->|"update UI"| Chat

    %% State Subscriptions
    Store --> Home
    Store --> ChannelList
    Store --> Chat

    %% Build Pipeline
    main.ts --> AngularJSON
    AngularJSON -->|"build"| Dist

    classDef comp fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef svc fill:#FFFF99,stroke:#000,stroke-width:1px
    classDef ext fill:#90EE90,stroke:#000,stroke-width:1px
```
