{"id":35535693,"url":"https://github.com/shahdarshil123/chat-app","last_synced_at":"2026-01-13T22:58:28.429Z","repository":{"id":331059115,"uuid":"1123903767","full_name":"shahdarshil123/chat-app","owner":"shahdarshil123","description":"A full-stack real-time chat application with a Node.js backend, React frontend, PostgreSQL database, Redis, and Docker-based infrastructure","archived":false,"fork":false,"pushed_at":"2026-01-10T19:56:52.000Z","size":590,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-11T05:16:38.443Z","etag":null,"topics":["chat-application","docker","express","full-stack-application","nodejs","postgresql","prisma","react","redis","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shahdarshil123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-27T22:05:00.000Z","updated_at":"2026-01-11T01:08:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/shahdarshil123/chat-app","commit_stats":null,"previous_names":["shahdarshil123/chat-app"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/shahdarshil123/chat-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahdarshil123%2Fchat-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahdarshil123%2Fchat-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahdarshil123%2Fchat-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahdarshil123%2Fchat-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahdarshil123","download_url":"https://codeload.github.com/shahdarshil123/chat-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahdarshil123%2Fchat-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28399508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chat-application","docker","express","full-stack-application","nodejs","postgresql","prisma","react","redis","websocket"],"created_at":"2026-01-04T03:19:20.480Z","updated_at":"2026-01-13T22:58:28.422Z","avatar_url":"https://github.com/shahdarshil123.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Real-Time Chat Messaging Application\n\nA full-stack, real-time chat application designed with **reliability, offline support, scalability, and clean API layering** in mind.\n\nThis document includes a **navigable table of contents** for easier understanding of the architecture and implementation.\n\n---\n\n## 📚 Table of Contents\n\n1. [Overview](#overview)  \n2. [Features](#features)  \n3. [Architecture Diagram](#architecture-diagram)\n4. [Repository Structure](#repository-structure)  \n5. [Core Domain Concepts](#core-domain-concepts)  \n   - [Users](#users)  \n   - [Conversations](#conversations)  \n   - [Messages](#messages)  \n6. [Message Flow](#message-flow)  \n7. [Redis Integration](#redis-integration)  \n   - [Session Management](#session-management)  \n   - [Online User Tracking](#online-user-tracking)  \n8. [Offline Messaging with IndexedDB](#offline-messaging-with-indexeddb)  \n9. [Message Ordering \u0026 Reliability](#message-ordering--reliability)  \n10. [Reconnection \u0026 Recovery](#reconnection--recovery)  \n11. [Technology Stack](#technology-stack)  \n12. [Docker \u0026 Development Workflow](#docker--development-workflow)  \n13. [Core Docker Compose Commands](#core-docker-compose-commands)\n---\n\n## Overview\n\nThis chat system supports **one-to-one conversations**, **real-time updates**, **offline-first messaging**, and **session persistence across server restarts**.  \n\n\n---\n\n## Features\n\n- One-to-one private conversations  \n- Real-time message delivery via Socket.IO  \n- PostgreSQL-backed message persistence  \n- Redis-backed session management  \n- Online/offline user presence tracking  \n- IndexedDB-based offline message outbox  \n- Guaranteed message ordering  \n- Optimistic UI updates  \n\n---\n\n## Architecture Diagram\n\n![Architecture-Diagram](./architecture-diagram.png)\n\n---\n\n## Repository Structure\n\n```\nClient (React)\n  ├─ IndexedDB (offline outbox)\n  ├─ Optimistic UI state\n  └─ Socket.IO client\n\nServer (Node.js / Express)\n  ├─ REST APIs\n  ├─ Socket.IO server\n  ├─ Redis (sessions + presence)\n  └─ PostgreSQL (messages)\n\nRedis\n  ├─ Session storage\n  └─ Online user tracking\n```\n\n---\n\n## Core Domain Concepts\n\n### Users\n\n- Identified by unique user IDs  \n- Authentication handled via Express sessions  \n- Sessions stored in Redis for durability  \n- Supports multiple sockets per user  \n\n---\n\n### Conversations\n\nA conversation represents a logical chat thread between two users.\n\nStored metadata:\n- Participant user IDs  \n- Creation timestamp  \n- Last message preview  \n\n---\n\n### Messages\n\nMessages are immutable records stored in PostgreSQL.\n\nFields:\n```\nid\nconversation_id\nsender_id\ncontent\ncreated_at\n```\n\nThe database is the **single source of truth**.\n\n---\n\n## Message Flow\n\n1. User sends a message (optimistic UI update)  \n2. Message is persisted to PostgreSQL  \n3. Server checks Redis for recipient sockets  \n4. Message delivered via Socket.IO if online  \n5. Message recovered via HTTP if offline  \n\n---\n\n## Redis Integration\n\nRedis acts as an **in-memory coordination layer**, not a primary datastore.\n\n### Session Management\n\n- Sessions stored using `connect-redis`\n- Session cookie maps to Redis key `sess:\u003csessionId\u003e`\n- Sessions survive server restarts\n\n### Online User Tracking\n\nRedis key design:\n```\nonline:user:{userId} → Set(socketIds)\n```\n\n- Socket connect → add socketId  \n- Socket disconnect → remove socketId  \n- Empty set → user offline  \n\n---\n\n## Offline Messaging with IndexedDB\n\nIndexedDB is used as a **client-side outbox**.\n\nSchema:\n```\noutbox:\n  - id\n  - conversationId\n  - content\n  - createdAt\n```\n\nBehavior:\n- Failed send → stored locally  \n- UI shows pending state  \n- Messages flushed in order on reconnect  \n\n---\n\n## Message Ordering \u0026 Reliability\n\n- All message sends go through a serialized send queue  \n- Prevents race conditions and reordering  \n- Offline messages are replayed before new messages  \n\n---\n\n## Reconnection \u0026 Recovery\n\nOn reconnect:\n1. Socket reconnects  \n2. Offline outbox is flushed  \n3. Active conversation messages are reloaded via HTTP  \n4. UI state is rehydrated  \n\nSockets deliver **real-time deltas**; HTTP restores **truth**.\n\n---\n\n## Technology Stack\n\n### Frontend\n- React (Vite)\n- IndexedDB\n- Socket.IO client\n\n### Backend\n- Node.js\n- Express\n- Socket.IO\n\n### Data Layer\n- PostgreSQL\n- Prisma ORM\n- Redis\n\n---\n\n## Docker \u0026 Development Workflow\n\nServices:\n- `client` – React frontend  \n- `server` – API + Socket.IO  \n- `db` – PostgreSQL  \n- `redis` – Sessions \u0026 presence  \n\nCommon commands:\n```bash\ndocker compose up --build\ndocker compose exec server npx prisma migrate deploy\ndocker compose exec server npx prisma db seed\ndocker compose exec server npx prisma studio --port 5555\ndocker compose down -v\n\nor\n\nensure the .env file exists in ./server and ./client then run:\n\ndocker network create chat-net\ndocker network ls\n\ndocker run -d --name postgres --network chat-net -e POSTGRES_USER=chat_user -e POSTGRES_PASSWORD=chat_pass -e POSTGRES_DB=chat_app postgres:15\n\ndocker run -d --name chat_redis --network chat-net redis:7\n\ndocker run -d --name chat-server --network chat-net -p 4000:4000 -e DATABASE_URL=postgresql://chat_user:chat_pass@postgres:5432/chat_app -e REDIS_URL=redis://chat_redis:6379 darshilshah0208/chat-app-server:\u003cversion\u003e\n\ndocker run -d --name chat-client --network chat-net -p 5173:5173 -e VITE_API_URL=http://chat-server:4000 darshilshah0208/chat-app-client:\u003cversion\u003e\n\ndocker exec -it chat-server npx prisma migrate deploy\n\ndocker exec -it chat-server npx prisma db seed\n\n```\n---\n\n##  Core Docker Compose Commands\n\n### Start all services\n```bash\ndocker compose up -d\n```\nStarts client, server, database, and runs migrations automatically (via dependencies).\n\n---\n\n### Build images and start services\n```bash\ndocker compose up --build -d\n```\nUse this after:\n- dependency changes\n- Dockerfile changes\n- switching branches\n\n---\n\n### Stop all services\n```bash\ndocker compose down\n```\nStops containers but **keeps database data**.\n\n---\n\n### Stop services and remove volumes ( destructive)\n```bash\ndocker compose down -v\n```\nDeletes **all volumes**, including Postgres data.\nUse only if you want a completely fresh environment.\n\n---\n\n### View container status\n```bash\ndocker compose ps\n```\n\n\n---\n\n##  Bash Scripts (Recommended Workflow)\n\nAll scripts live in the `scripts/` directory.\n\n\u003e **On Windows (Git Bash):** always run scripts using\n```bash\nbash scripts/\u003cscript-name\u003e.sh\n```\n\n---\n\n### 1️⃣ `dev.sh` – Start dev environment\n```bash\nbash scripts/dev.sh\n```\n\nWhat it does:\n- Starts all Docker services\n- Prepares the app for local development\n\nUse when:\n- starting work for the day\n- after a clean pull\n\n---\n\n### 2️⃣ `reset-db.sh` – Reset database (TRUNCATE-based)\n```bash\nbash scripts/reset-db.sh\n```\n\nWhat it does:\n- Truncates all application tables\n- Resets IDs\n- Re-runs Prisma seed\n\nWhy this exists:\n- Windows-safe\n- No Docker volume issues\n- Deterministic (no duplicate data)\n\n **Deletes all data but keeps schema**\n\n\n\n## Common Dev Flows\n\n### Fresh start (recommended)\n```bash\nbash scripts/dev.sh\nbash scripts/reset-db.sh\n```\n\n---\n\n### Database-only reset\n```bash\nbash scripts/reset-db.sh\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahdarshil123%2Fchat-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahdarshil123%2Fchat-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahdarshil123%2Fchat-app/lists"}