# gustavodesousalima/chatwebsocket architecture

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

- Interactive diagram: https://gitdiagram.com/gustavodesousalima/chatwebsocket
- Repository: https://github.com/gustavodesousalima/chatwebsocket

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application whose sole purpose is to demonstrate and test real-time chat using the WebSocket protocol (via Socket.IO).
- The backend is a Node.js server (Express + Socket.IO) that serves static assets and brokering real-time messages. The frontend is a static HTML/CSS/JS client.

##### File structure
- Top-level:
- backend/
– index.js (entry point)
– package.json / package-lock.json (dependency manifest)
- frontend/
– index.html, acess.html, script.js, styles.css, assets/
- No database directory: chat state is maintained in memory.
- No microservices—single Node.js process.
- Deployment config (not in repo) uses AWS EC2 + Nginx + Certbot + PM2 (mentioned in README).

##### README for additional insights
- Confirms Express serves static files and Socket.IO handles WebSocket connections with fallback.
- Deployment stack on EC2:
- Nginx→reverse proxy & SSL (Certbot)
- PM2→ensures Node.js process stays up
- Node.js 18+ runtime

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        Browser["Web Browser"]:::frontend
        subgraph "Static Frontend Files"
            HTML["index.html"]:::frontend
            ACCESS["acess.html"]:::frontend
            SCRIPT["script.js"]:::frontend
            STYLE["styles.css"]:::frontend
            ASSETS["assets/"]:::frontend
        end
    end

    %% Infrastructure Layer
    subgraph "AWS EC2 Instance"
        NGINX["Nginx (Reverse Proxy, SSL Termination)"]:::infra
        CERTBOT["Certbot (SSL Renewal)"]:::infra
        PM2["PM2 (Process Manager)"]:::infra
        subgraph "Node.js Application"
            NodeApp["Express.js + Socket.IO (Node.js App)"]:::backend
            PKG1["package.json"]:::backend
            PKG2["package-lock.json"]:::backend
        end
    end

    %% HTTP Static Asset Flow
    Browser -->|"GET /index.html"| NGINX
    NGINX -->|"proxy HTTP GET"| NodeApp
    NodeApp -->|"serve index.html, CSS, JS"| Browser
    NodeApp -->|"read static files"| HTML
    NodeApp -->|"read static files"| ACCESS
    NodeApp -->|"read static files"| SCRIPT
    NodeApp -->|"read static files"| STYLE
    NodeApp -->|"read assets"| ASSETS

    %% WebSocket Chat Flow
    Browser -->|"WebSocket handshake"| NGINX
    NGINX -->|"proxy WebSocket"| NodeApp
    Browser ---|"chat message event"| NodeApp
    NodeApp ---|"broadcast message"| Browser

    %% Process & SSL Management
    PM2 -->|"manages process"| NodeApp
    CERTBOT -->|"renew SSL"| NGINX

    %% Clickable mappings
    click HTML "https://github.com/gustavodesousalima/chatwebsocket/blob/main/frontend/index.html"
    click ACCESS "https://github.com/gustavodesousalima/chatwebsocket/blob/main/frontend/acess.html"
    click SCRIPT "https://github.com/gustavodesousalima/chatwebsocket/blob/main/frontend/script.js"
    click STYLE "https://github.com/gustavodesousalima/chatwebsocket/blob/main/frontend/styles.css"
    click ASSETS "https://github.com/gustavodesousalima/chatwebsocket/tree/main/frontend/assets/"
    click NodeApp "https://github.com/gustavodesousalima/chatwebsocket/blob/main/backend/index.js"
    click PKG1 "https://github.com/gustavodesousalima/chatwebsocket/blob/main/backend/package.json"
    click PKG2 "https://github.com/gustavodesousalima/chatwebsocket/blob/main/backend/package-lock.json"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,stroke-width:1px;
    classDef backend fill:#DFFFE0,stroke:#22863A,stroke-width:1px;
    classDef infra fill:#FFF5B1,stroke:#D69E2E,stroke-width:1px;
```
