# thenyachhon/hamrochat architecture

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

- Interactive diagram: https://gitdiagram.com/thenyachhon/hamrochat
- Repository: https://github.com/thenyachhon/hamrochat

## Overview

##### Project type and purpose
- This is a full-stack, web-based real-time chat application (“HamroChat”) built with Node.js/Express on the backend, EJS for server-side views on the frontend, MongoDB via Mongoose for data storage, and Socket.io for live messaging. Users can register/login (Passport + bcrypt), manage contacts, and chat privately or in groups.

##### File structure
- Top-level
- app.js – main Express application and HTTP route definitions
- messages.js – Socket.io event handlers (real-time chat logic)
- models/
– database.js – Mongoose connection setup
– groups.js – Mongoose schema for group chats (there’s presumably a users.js schema as well)
- public/ – client-side JavaScript (client.js, group-client.js, validate.js, etc.), CSS, images
- views/ – EJS templates for all UI pages
- Procfile – deployment instruction (Heroku)
- package.json – dependencies (express, ejs, mongoose, passport, socket.io, dotenv, bcrypt, nanoid, moment)
- Architectural patterns
- MVC style: models/ for data, views/ for templates, app.js controllers for routes
- Real-time event-driven layer via Socket.io

##### README insights
- Stack: Node.js, Express, EJS, Mongoose, Passport, Socket.io

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Client Browser"]:::client
        subgraph "Static Assets (public/)"
            ClientJS["client.js"]:::client
            GroupClientJS["group-client.js"]:::client
            ColourBlind["colourBlind.js"]:::client
            Validate["validate.js"]:::client
            ForgotPass["forgotpass.js"]:::client
            CopyPaste["copypaste.js"]:::client
            Style["style.css"]:::client
        end
        subgraph "Views"
            ViewsMain["views/"]:::client
            ViewsPartials["views/partials/"]:::client
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        Express["Express HTTP Server & Routing"]:::server
        Auth["Authentication Middleware (Passport)"]:::server
        Socket["Socket.io Chat Engine"]:::server
        subgraph "Database Models"
            MongooseConn["Mongoose Connection Setup"]:::server
            GroupModel["Group Chat Schema"]:::server
        end
        subgraph "Configuration & Deployment"
            Config["Environment Config (dotenv)"]:::config
            Procfile["Procfile"]:::config
            Package["package.json"]:::config
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoDB["MongoDB Database"]:::db
    end

    %% Connections
    Browser -->|HTTP Requests| Express
    Express -->|passes through| Auth
    Express -->|renders| ViewsMain
    Express -->|renders| ViewsPartials
    Express -->|serves| ClientJS
    Express -->|serves| GroupClientJS
    Express -->|serves| ColourBlind
    Express -->|serves| Validate
    Express -->|serves| ForgotPass
    Express -->|serves| CopyPaste
    Express -->|serves| Style
    Browser -->|loads static| ClientJS
    Browser -->|loads static| GroupClientJS
    Browser -->|loads static| ColourBlind
    Browser -->|loads static| Validate
    Browser -->|loads static| ForgotPass
    Browser -->|loads static| CopyPaste
    Browser -->|loads static| Style
    Browser -->|loads UI| ViewsMain
    Browser -->|loads UI| ViewsPartials
    Browser -->|WebSocket| Socket
    Socket -->|handles events| MongoDB
    Express -->|connects| MongooseConn
    MongooseConn -->|uses schema| GroupModel
    MongooseConn -->|CRUD operations| MongoDB
    MongoDB -->|returns data| Express
    Config --> Express
    Procfile --> Express
    Package --> Express

    %% Click Events
    click Express "https://github.com/thenyachhon/hamrochat/blob/main/app.js"
    click Socket "https://github.com/thenyachhon/hamrochat/blob/main/messages.js"
    click MongooseConn "https://github.com/thenyachhon/hamrochat/blob/main/models/database.js"
    click GroupModel "https://github.com/thenyachhon/hamrochat/blob/main/models/groups.js"
    click ClientJS "https://github.com/thenyachhon/hamrochat/blob/main/public/client.js"
    click GroupClientJS "https://github.com/thenyachhon/hamrochat/blob/main/public/group-client.js"
    click ColourBlind "https://github.com/thenyachhon/hamrochat/blob/main/public/colourBlind.js"
    click Validate "https://github.com/thenyachhon/hamrochat/blob/main/public/validate.js"
    click ForgotPass "https://github.com/thenyachhon/hamrochat/blob/main/public/forgotpass.js"
    click CopyPaste "https://github.com/thenyachhon/hamrochat/blob/main/public/copypaste.js"
    click Style "https://github.com/thenyachhon/hamrochat/blob/main/public/style.css"
    click ViewsMain "https://github.com/thenyachhon/hamrochat/tree/main/views/"
    click ViewsPartials "https://github.com/thenyachhon/hamrochat/tree/main/views/partials/"
    click Procfile "https://github.com/thenyachhon/hamrochat/tree/main/Procfile"
    click Package "https://github.com/thenyachhon/hamrochat/blob/main/package.json"

    %% Styles
    classDef client fill:#e0f7e9,stroke:#1a7f37,stroke-width:1px,color:#1a7f37;
    classDef server fill:#d0e7ff,stroke:#2255a4,stroke-width:1px,color:#2255a4;
    classDef db fill:#ffe5b4,stroke:#cc7a00,stroke-width:1px,color:#cc7a00;
    classDef config fill:#f0f0f0,stroke:#888888,stroke-width:1px,color:#553;
```
