8000 GitHub - msaini28r/Comet-Chat-Messaging-App · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Friend-only messaging app

Full-stack app from the PRD: discover users, friend requests (with real-time delivery), and CometChat messaging only between accepted friends. The UI separates Users, Friend requests, and Conversations (CometChat React UI Kit).

Project structure

Path Role
server/ Express API, Prisma + SQLite, Socket.io for live friend-request events, CometChat REST for users/friends/auth tokens
client/ Vite + React + React Router; CometChat UI Kit for the chat surface

Key decisions

  1. Backend as source of truth – Friend relationships and request state live in SQLite (Friendship, FriendRequest). The API refuses inconsistent actions (duplicate requests, accepting others’ requests, etc.).
  2. CometChat alignment – On register, a CometChat user is created with the same UID as our User.id. On accept, the server calls CometChat Add Friends both ways with addToConversations: true so 1:1 threads match product friends.
  3. Auth – JWT for the app API; CometChat auth tokens are minted on the server (GET /api/chat/cometchat-token) so the client can call CometChatUIKit.loginWithAuthToken without embedding the REST API key in the browser.
  4. Extra enforcement – GET /api/chat/can-chat/:otherUserId returns 403 unless a Friendship row exists. The conversations screen uses this before loading a user thread so the UI cannot skip the rule.
  5. Messaging edge case – CometChat’s SDK still allows targeting a UID if someone tampers with the client. For production, add CometChat webhooks / moderation to reject sends when your API says the pair is not friends. This repo enforces friendship in your domain and syncs friends into CometChat.

Prerequisites

  • Node 18+ (global fetch on the server)
  • A CometChat app: App ID, Region, Auth Key (client), REST API Key (server)

Run locally

1. API server

cd server
cp .env.example .env
# Edit .env: JWT_SECRET, COMETCHAT_APP_ID, COMETCHAT_REGION, COMETCHAT_REST_API_KEY
npm install
npx prisma db push
npm run dev

Default API: http://localhost:4000

2. Web client

cd client
cp .env.example .env
# Match VITE_API_URL; set VITE_COMETCHAT_APP_ID, VITE_COMETCHAT_REGION, VITE_COMETCHAT_AUTH_KEY (dashboard Auth Key)
npm install
npm run dev

Default UI: http://localhost:5173

3. Smoke test

  1. Register two users (each gets a CometChat user).
  2. As user A, open Users and send a request to user B.
  3. As user B, open Friend requests — the row should appear immediately (Socket.io).
  4. Accept — both sides should show as friends; Open chat / Conversations should allow messaging via the UI Kit.

API overview

  • POST /api/auth/register / POST /api/auth/login — JWT + user profile
  • GET /api/users — discovery list with relation (none | request_sent | request_received | friends)
  • POST /api/friends/requests — send request; emits friend-request:new to recipient
  • GET /api/friends/requests/incoming — pending inbox
  • POST /api/friends/requests/:id/accept | reject — accept syncs CometChat friends
  • GET /api/chat/cometchat-token — auth token for UI Kit login
  • GET /api/chat/can-chat/:otherUserId — friendship check

Socket.io connects with auth: { token: "<JWT>" }; events: friend-request:new, friend-request:accepted.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0