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).
| 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 |
- 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.). - 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 withaddToConversations: trueso 1:1 threads match product friends. - Auth – JWT for the app API; CometChat auth tokens are minted on the server (
GET /api/chat/cometchat-token) so the client can callCometChatUIKit.loginWithAuthTokenwithout embedding the REST API key in the browser. - Extra enforcement –
GET /api/chat/can-chat/:otherUserIdreturns 403 unless aFriendshiprow exists. The conversations screen uses this before loading a user thread so the UI cannot skip the rule. - 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.
- Node 18+ (global
fetchon the server) - A CometChat app: App ID, Region, Auth Key (client), REST API Key (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 devDefault API: http://localhost:4000
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 devDefault UI: http://localhost:5173
- Register two users (each gets a CometChat user).
- As user A, open Users and send a request to user B.
- As user B, open Friend requests — the row should appear immediately (Socket.io).
- Accept — both sides should show as friends; Open chat / Conversations should allow messaging via the UI Kit.
POST /api/auth/register/POST /api/auth/login— JWT + user profileGET /api/users— discovery list withrelation(none|request_sent|request_received|friends)POST /api/friends/requests— send request; emitsfriend-request:newto recipientGET /api/friends/requests/incoming— pending inboxPOST /api/friends/requests/:id/accept|reject— accept syncs CometChat friendsGET /api/chat/cometchat-token— auth token for UI Kit loginGET /api/chat/can-chat/:otherUserId— friendship check
Socket.io connects with auth: { token: "<JWT>" }; events: friend-request:new, friend-request:accepted.