# ahmedyahyae/realtime-websocket-php-chat-application architecture

> Architecture diagram of the GitHub repository ahmedyahyae/realtime-websocket-php-chat-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedyahyae/realtime-websocket-php-chat-application
- Repository: https://github.com/ahmedyahyae/realtime-websocket-php-chat-application

## Overview

This is a PHP/Ratchet real-time chat application. Users register or log in, then use public group chat or one-to-one private chat; the WebSocket handler distributes live messages and presence while PHP models persist users and chat history in MySQL. The README also documents email verification, profile-image upload, AJAX interactions, read/unread counts, and online status. Some page and handler implementations were not sampled, so those capability branches are represented without asserting unshown call paths.

Main entry points: [`vendor-front/parsley/parsley/main.js`](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/main.js) (Parsley API), [`vendor-front/parsley/parsley/field.js`](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/field.js) (Parsley validation), [`src/Chat.php`](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/src/Chat.php) (Chat handler), [`database/Database_connection.php`](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/Database_connection.php) (Database connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_profile["Profile and upload<br/>[profile.php]"]
  node_actions["AJAX actions<br/>[action.php]"]
end

subgraph group_identity["Identity"]
  node_login["Login<br/>[index.php]"]
  node_registration["Registration<br/>[register.php]"]
  node_verification["Email verification<br/>[verify.php]"]
end

subgraph group_realtime["Realtime chat"]
  node_groupchat["Group chat<br/>[group_chat.php]"]
  node_privatechat["Private chat<br/>[private_chat.php]"]
  node_wsserver["WebSocket server<br/>[server.php]"]
  node_chathandler["Chat handler<br/>[Chat.php]"]
end

subgraph group_persistence["Persistence"]
  node_users["User model<br/>[ChatUserModel.php]"]
  node_groupmessages["Group message model"]
  node_privatemessages["Private message model"]
  node_dbconnection["Database connection"]
end

subgraph group_validation["Form validation"]
  node_parsley["Parsley validation<br/>[field.js]"]
  node_parsleymain["Parsley API<br/>[main.js]"]
  node_parsleyui["Validation UI<br/>[ui.js]"]
  node_parsleybase["Validation base<br/>[base.js]"]
  node_parsleyfactory["Instance factory<br/>[factory.js]"]
  node_parsleyform["Form validation<br/>[form.js]"]
  node_parsleyvalidator["Validator registry"]
  node_parsleydefaults["Validation defaults<br/>[defaults.js]"]
  node_parsleymultiple["Multiple fields<br/>[multiple.js]"]
end

node_user(("Chat user"))
node_mysql[("MySQL database")]
node_email["Email service"]

node_user -->|"logs in"| node_login
node_user -->|"registers"| node_registration
node_user -->|"joins"| node_groupchat
node_user -->|"chats privately"| node_privatechat
node_user -->|"edits profile"| node_profile
node_login -->|"looks up account"| node_users
node_registration -.->|"sends verification"| node_email
node_registration -.->|"verifies account"| node_verification
node_groupchat -->|"opens socket"| node_chathandler
node_privatechat -->|"opens socket"| node_chathandler
node_wsserver -->|"registers handler"| node_chathandler
node_groupchat -->|"loads history"| node_groupmessages
node_privatechat -->|"loads history"| node_privatemessages
node_chathandler -->|"tracks presence"| node_users
node_users -->|"opens connection"| node_dbconnection
node_groupmessages -->|"opens connection"| node_dbconnection
node_privatemessages -->|"opens connection"| node_dbconnection
node_dbconnection -->|"connects"| node_mysql
node_parsleymain -->|"creates instances"| node_parsleyfactory
node_parsleymain -->|"creates registry"| node_parsleyvalidator
node_parsleymain -->|"uses"| node_parsleyform
node_parsleymain -->|"uses"| node_parsley
node_parsleyfactory -->|"instantiates"| node_parsleyform
node_parsleyfactory -->|"instantiates"| node_parsley
node_parsley -->|"updates UI"| node_parsleyui
node_parsley -->|"checks constraints"| node_parsleyvalidator
node_parsley -->|"inherits behavior"| node_parsleybase
node_parsleyform -->|"uses"| node_parsleybase
node_parsleymain -->|"loads defaults"| node_parsleydefaults
node_parsleymain -->|"uses"| node_parsleymultiple

click node_login "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/index.php"
click node_registration "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/register.php"
click node_verification "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/verify.php"
click node_profile "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/profile.php"
click node_actions "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/action.php"
click node_groupchat "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/group_chat.php"
click node_privatechat "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/private_chat.php"
click node_wsserver "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/bin/server.php"
click node_chathandler "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/src/Chat.php"
click node_users "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/ChatUserModel.php"
click node_groupmessages "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/GroupChatMessageModel.php"
click node_privatemessages "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/PrivateChatMessageModel.php"
click node_dbconnection "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/Database_connection.php"
click node_parsley "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/field.js"
click node_parsleymain "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/main.js"
click node_parsleyui "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/ui.js"
click node_parsleybase "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/base.js"
click node_parsleyfactory "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/factory.js"
click node_parsleyform "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/form.js"
click node_parsleyvalidator "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/validator_registry.js"
click node_parsleydefaults "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/defaults.js"
click node_parsleymultiple "https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/multiple.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_profile,node_actions,node_user toneBlue
class node_login,node_registration,node_verification,node_mysql toneAmber
class node_groupchat,node_privatechat,node_wsserver,node_chathandler toneMint
class node_users,node_groupmessages,node_privatemessages,node_dbconnection toneRose
class node_parsley,node_parsleymain,node_parsleyui,node_parsleybase,node_parsleyfactory,node_parsleyform,node_parsleyvalidator,node_parsleydefaults,node_parsleymultiple,node_email toneIndigo
```

## Components

### Web app

- [Profile and upload](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/profile.php): `profile.php`
- [AJAX actions](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/action.php): `action.php`

### Identity

- [Login](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/index.php): `index.php`
- [Registration](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/register.php): `register.php`
- [Email verification](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/verify.php): `verify.php`

### Realtime chat

- [Group chat](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/group_chat.php): `group_chat.php`
- [Private chat](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/private_chat.php): `private_chat.php`
- [WebSocket server](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/bin/server.php): `bin/server.php`
- [Chat handler](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/src/Chat.php): `src/Chat.php`

### Persistence

- [User model](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/ChatUserModel.php): `database/ChatUserModel.php`
- [Group message model](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/GroupChatMessageModel.php): `database/GroupChatMessageModel.php`
- [Private message model](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/PrivateChatMessageModel.php): `database/PrivateChatMessageModel.php`
- [Database connection](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/database/Database_connection.php): `database/Database_connection.php`

### Form validation

- [Parsley validation](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/field.js): `vendor-front/parsley/parsley/field.js`
- [Parsley API](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/main.js): `vendor-front/parsley/parsley/main.js`
- [Validation UI](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/ui.js): `vendor-front/parsley/parsley/ui.js`
- [Validation base](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/base.js): `vendor-front/parsley/parsley/base.js`
- [Instance factory](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/factory.js): `vendor-front/parsley/parsley/factory.js`
- [Form validation](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/form.js): `vendor-front/parsley/parsley/form.js`
- [Validator registry](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/validator_registry.js): `vendor-front/parsley/parsley/validator_registry.js`
- [Validation defaults](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/defaults.js): `vendor-front/parsley/parsley/defaults.js`
- [Multiple fields](https://github.com/ahmedyahyae/realtime-websocket-php-chat-application/blob/main/vendor-front/parsley/parsley/multiple.js): `vendor-front/parsley/parsley/multiple.js`

### Other components

- **Chat user**
- **MySQL database**
- **Email service**

## Connections

- Chat user → Login: logs in
- Chat user → Registration: registers
- Chat user → Group chat: joins
- Chat user → Private chat: chats privately
- Chat user → Profile and upload: edits profile
- Login → User model: looks up account (evidence: `index.php`)
- Registration → Email service: sends verification
- Registration → Email verification: verifies account
- Group chat → Chat handler: opens socket (evidence: `src/Chat.php`)
- Private chat → Chat handler: opens socket (evidence: `src/Chat.php`)
- WebSocket server → Chat handler: registers handler (evidence: `bin/server.php`)
- Group chat → Group message model: loads history (evidence: `group_chat.php`)
- Private chat → Private message model: loads history (evidence: `private_chat.php`)
- Chat handler → User model: tracks presence (evidence: `src/Chat.php`)
- User model → Database connection: opens connection (evidence: `database/ChatUserModel.php`)
- Group message model → Database connection: opens connection (evidence: `database/GroupChatMessageModel.php`)
- Private message model → Database connection: opens connection (evidence: `database/PrivateChatMessageModel.php`)
- Database connection → MySQL database: connects (evidence: `database/Database_connection.php`)
- Parsley API → Instance factory: creates instances (evidence: `vendor-front/parsley/parsley/main.js`)
- Parsley API → Validator registry: creates registry (evidence: `vendor-front/parsley/parsley/main.js`)
- Parsley API → Form validation: uses (evidence: `vendor-front/parsley/parsley/main.js`)
- Parsley API → Parsley validation: uses (evidence: `vendor-front/parsley/parsley/main.js`)
- Instance factory → Form validation: instantiates (evidence: `vendor-front/parsley/parsley/factory.js`)
- Instance factory → Parsley validation: instantiates (evidence: `vendor-front/parsley/parsley/factory.js`)
- Parsley validation → Validation UI: updates UI (evidence: `vendor-front/parsley/parsley/field.js`)
- Parsley validation → Validator registry: checks constraints (evidence: `vendor-front/parsley/parsley/field.js`)
- Parsley validation → Validation base: inherits behavior (evidence: `vendor-front/parsley/parsley/main.js`)
- Form validation → Validation base: uses (evidence: `vendor-front/parsley/parsley/form.js`)
- Parsley API → Validation defaults: loads defaults (evidence: `vendor-front/parsley/parsley/main.js`)
- Parsley API → Multiple fields: uses (evidence: `vendor-front/parsley/parsley/main.js`)
