Skip to content

BeeeFriends/Notification-Service-BeeFriends-BE

Repository files navigation

BeeFriends Notification Service

In-app notification, notification settings, device token, and Firebase Cloud Messaging service for BeeFriends.


Features

  • Notification Inbox - stores and returns user notifications
  • Read State - mark one notification or all notifications as read
  • Settings - per-user notification preferences
  • Device Tokens - register FCM tokens and toggle foreground/background delivery state
  • Chat Notifications - listens to new chat message events and creates notifications for recipients
  • Match Notifications - listens to new match events and creates notifications for both users
  • Push Delivery - sends FCM notifications with sender name and optional sender photo image

Tech Stack

Layer Stack
Runtime Node.js, NestJS, TypeScript
Database PostgreSQL, Prisma
Push Firebase Admin Messaging
Pub/Sub Redis Streams
Contracts @beefriends/shared-kernel

API

Environment Base URL
Production Gateway https://beefriends-be.drian.my.id/v1/notifications
Local http://localhost:3002/v1/notifications

Swagger docs:

http://localhost:3002/v1/notifications/docs

Main routes:

Route Purpose
GET /notifications?userId=:id List notifications for a user
POST /notifications Create a notification
PATCH /notifications/:id/read Mark a notification as read
PATCH /notifications/read-all Mark all user notifications as read
GET /notifications/settings/:userId Get notification settings
PATCH /notifications/settings/:userId Update notification settings
POST /notifications/device-tokens Register a device token
PATCH /notifications/device-tokens/state Update whether a token should receive push

With the default API_PREFIX=v1, the full local path is /v1/notifications/....


Architecture

Match Chat Service
  -> Redis Streams
    -> Notification Service
      -> PostgreSQL
      -> Firebase Cloud Messaging
      -> BeeFriends Mobile

The mobile app disables push delivery for its active token while the app is foregrounded, so the user does not receive duplicate push notifications while already using the app.


Environment Variables

PORT=3002
SERVICE_NAME=beefriends-notification-service
API_PREFIX=v1
API_DOCS_PATH=v1/notifications/docs

NOTIFICATION_DATABASE_URL=
DATABASE_URL=
REDIS_URL=
USER_SERVICE_URL=http://localhost:3001
PUBSUB_POLL_INTERVAL_MS=5000
CHAT_MESSAGE_ENCRYPTION_KEY=

FIREBASE_PROJECT_ID=
FIREBASE_CLIENT_EMAIL=
FIREBASE_PRIVATE_KEY=

NOTIFICATION_DATABASE_URL is preferred. DATABASE_URL is accepted as a fallback by Prisma. Set the same CHAT_MESSAGE_ENCRYPTION_KEY as Match Chat if chat notification previews should show decrypted text.


Getting Started

npm install
npm run prisma:generate
npm run prisma:push
npm run start:dev

Scripts

Command Description
npm run start:dev Start service in watch mode
npm run build Generate Prisma client and compile NestJS app
npm run start:prod Run compiled app
npm run lint Run ESLint with fixes
npm run test Run unit tests
npm run prisma:generate Generate Prisma client
npm run prisma:migrate Run local Prisma migration
npm run prisma:push Push schema to database
npm run prisma:studio Open Prisma Studio

About

BeeFriends Backend Application 🤖

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors