# wizardingmuggle/chatapp architecture

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

- Interactive diagram: https://gitdiagram.com/wizardingmuggle/chatapp
- Repository: https://github.com/wizardingmuggle/chatapp

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application (“ChatApp”).
- The client is a React single-page application; the server is a Node/Express API; messages/users are persisted in a database; social sign-in uses Firebase.

##### File structure
- Top-level:
- client/ – React front end
- server/ – Express back end
- client/src/components, pages, utils → standard React component-based UI and helper modules (APIRoutes, FirebaseConfig).
- server/controllers, models, routes → MVC-style Express structure.
- No build scripts beyond package.json; no Docker/k8s files, so deployment is likely a Node host + static assets.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        subgraph "Components"
            ChatContainer["ChatContainer.jsx"]:::frontend
            ChatInput["ChatInput.jsx"]:::frontend
            Contacts["Contacts.jsx"]:::frontend
            Logout["Logout.jsx"]:::frontend
            SocialLoginButtons["SocialLoginButtons.jsx"]:::frontend
            Welcome["Welcome.jsx"]:::frontend
        end
        subgraph "Pages"
            ChatPage["Chat.jsx"]:::frontend
            LoginPage["Login.jsx"]:::frontend
            RegisterPage["Register.jsx"]:::frontend
            SetAvatarPage["SetAvatar.jsx"]:::frontend
            SetUsernamePage["SetUsername.jsx"]:::frontend
        end
        subgraph "Utils"
            APIRoutes["APIRoutes.js"]:::frontend
            FirebaseConfig["FirebaseConfig.js"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        subgraph "Routes"
            AuthRoutes["auth.js"]:::backend
            MsgRoutes["messages.js"]:::backend
        end
        subgraph "Controllers"
            UserController["userController.js"]:::backend
            MessageController["messageController.js"]:::backend
        end
        subgraph "Models"
            UserModel["userModel.js"]:::backend
            MessageModel["messageModel.js"]:::backend
        end
        WebSocketServer["WebSocket Server\n(Socket.io)"]:::backend
        DB["MongoDB\n(via Mongoose)"]:::backend
    end

    %% External Services
    Firebase["Firebase Auth"]:::external

    %% Connections
    ChatContainer -->|uses| APIRoutes
    ChatInput -->|uses| APIRoutes
    Contacts -->|uses| APIRoutes
    Logout -->|uses| APIRoutes
    SocialLoginButtons -->|uses| FirebaseConfig
    Welcome -->|uses| APIRoutes

    ChatPage -->|HTTP/HTTPS| APIRoutes
    LoginPage -->|HTTP/HTTPS| APIRoutes
    RegisterPage -->|HTTP/HTTPS| APIRoutes
    SetAvatarPage -->|HTTP/HTTPS| APIRoutes
    SetUsernamePage -->|HTTP/HTTPS| APIRoutes

    APIRoutes -->|POST /auth/*| AuthRoutes
    APIRoutes -->|GET/POST /messages/*| MsgRoutes

    AuthRoutes -->|calls| UserController
    MsgRoutes -->|calls| MessageController

    UserController -->|CRUD| UserModel
    MessageController -->|CRUD| MessageModel

    UserModel -->|reads/writes| DB
    MessageModel -->|reads/writes| DB

    ChatPage <-->|WebSocket| WebSocketServer
    WebSocketServer -->|emits| MessageController

    ChatPage <-->|OAuth Token| Firebase
    Firebase -->|JWT Validation| AuthRoutes

    %% Click Events
    click ChatContainer "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/ChatContainer.jsx"
    click ChatInput "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/ChatInput.jsx"
    click Contacts "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/Contacts.jsx"
    click Logout "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/Logout.jsx"
    click SocialLoginButtons "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/SocialLoginButtons.jsx"
    click Welcome "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/components/Welcome.jsx"
    click ChatPage "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/pages/Chat.jsx"
    click LoginPage "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/pages/Login.jsx"
    click RegisterPage "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/pages/Register.jsx"
    click SetAvatarPage "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/pages/SetAvatar.jsx"
    click SetUsernamePage "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/pages/SetUsername.jsx"
    click APIRoutes "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/utils/APIRoutes.js"
    click FirebaseConfig "https://github.com/wizardingmuggle/chatapp/blob/main/client/src/utils/FirebaseConfig.js"
    click AuthRoutes "https://github.com/wizardingmuggle/chatapp/blob/main/server/routes/auth.js"
    click MsgRoutes "https://github.com/wizardingmuggle/chatapp/blob/main/server/routes/messages.js"
    click UserController "https://github.com/wizardingmuggle/chatapp/blob/main/server/controllers/userController.js"
    click MessageController "https://github.com/wizardingmuggle/chatapp/blob/main/server/controllers/messageController.js"
    click UserModel "https://github.com/wizardingmuggle/chatapp/blob/main/server/models/userModel.js"
    click MessageModel "https://github.com/wizardingmuggle/chatapp/blob/main/server/models/messageModel.js"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#21618C,stroke-width:1px
    classDef backend fill:#D5F5E3,stroke:#1D8348,stroke-width:1px
    classDef external fill:#FCF3CF,stroke:#B9770E,stroke-width:1px
```
