Skip to content

NotFound-Team/CoreChain-Notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CoreChain-Notification

Notification service for CoreChain HRM system using Firebase Cloud Messaging (FCM) and Kafka.

πŸ“‹ Overview

This is a Golang-based notification service that:

  • Consumes Kafka messages from the NestJS backend
  • Sends push notifications via Firebase Cloud Messaging (FCM)
  • Stores notification history in PostgreSQL
  • Supports multiple notification types (tasks, messages, calls)

Current Flow: Task created on server (NestJS) β†’ Kafka β†’ Notification service (Golang) β†’ FCM β†’ Mobile app

πŸ—οΈ Architecture

Built with Clean Architecture principles:

  • cmd/server/ - Application entry point
  • internal/domain/ - Business entities and interfaces
  • internal/application/ - Business logic (services & DTOs)
  • internal/infrastructure/ - External integrations (Kafka, FCM, PostgreSQL)
  • internal/delivery/ - Message handlers
  • pkg/ - Public/shared code

πŸš€ Quick Start

Prerequisites

  • Go 1.21+
  • Docker & Docker Compose
  • PostgreSQL 15
  • Kafka (or use Docker Compose setup)

Setup

  1. Clone and setup

    cd CoreChain-Notification
    cp .env.example .env
    # Edit .env with your configuration
  2. Install dependencies

    make deps
  3. Start with Docker Compose (includes PostgreSQL, Kafka, and service)

    make docker-up
  4. Or run locally

    # Make sure PostgreSQL and Kafka are running
    make run

πŸ“ Configuration

Configure via environment variables (see .env.example):

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=notification_user
DB_PASSWORD=notification_pass
DB_NAME=notification_db

# Kafka
KAFKA_BROKERS=localhost:9092
KAFKA_GROUP_ID=notification-service-group
KAFKA_TOPIC_TASK_CREATED=task.created

# FCM
FCM_CREDENTIALS_PATH=./google-services.json
FCM_PROJECT_ID=corechain-e1321

πŸ”§ Available Commands

make help           # Show all available commands
make deps           # Download dependencies
make build          # Build the application
make run            # Run locally
make test           # Run tests
make docker-up      # Start with Docker Compose
make docker-down    # Stop Docker services
make docker-logs    # View logs

πŸ“¦ Project Structure

CoreChain-Notification/
β”œβ”€β”€ cmd/server/              # Main application
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ config/             # Configuration management
β”‚   β”œβ”€β”€ domain/             # Domain models & interfaces
β”‚   β”œβ”€β”€ application/        # Services & DTOs
β”‚   β”œβ”€β”€ infrastructure/     # Kafka, FCM, PostgreSQL
β”‚   β”œβ”€β”€ delivery/           # Message handlers
β”‚   └── utils/              # Logger, errors, validators
β”œβ”€β”€ deployments/
β”‚   └── docker/             # Dockerfile & docker-compose
└── configs/                # Config files

πŸ”” Supported Notifications

βœ… Implemented

  • Task Created - Notifies when a new task is assigned

🚧 Planned

  • Task Updated - Notifies when a task is modified
  • New Message - Notifies on incoming messages
  • Incoming Call - Notifies on incoming calls

πŸ› οΈ Development

Adding New Notification Type

  1. Add constant in pkg/constants/notification_types.go
  2. Create DTO in internal/application/dto/
  3. Add template in internal/infrastructure/fcm/templates.go
  4. Create handler in internal/delivery/kafka/
  5. Register handler in cmd/server/main.go

Testing

# Run all tests
make test

# Run with coverage
make test-coverage

🐳 Docker

Build Image

make docker-build

Docker Compose Services

  • postgres - PostgreSQL database (port 5432)
  • kafka - Apache Kafka (port 9092)
  • zookeeper - Kafka dependency (port 2181)
  • notification-service - This service (port 8080)

πŸ“Š Database Schema

Notifications Table

Stores all notification records with delivery status tracking.

User FCM Tokens Table

Tracks device tokens for each user.

See deployments/docker/migrations/001_init.sql for full schema.

🀝 Integration with NestJS

The NestJS backend should publish messages to Kafka in this format:

{
  "event_type": "task.created",
  "timestamp": "2025-12-26T07:29:50Z",
  "data": {
    "_id": "task-id",
    "title": "Task title",
    "assignedTo": "user-id",
    ...
  },
  "metadata": {
    "assignedToUser": {
      "_id": "user-id",
      "fcmToken": "device-token",
      "name": "User Name"
    }
  }
}

πŸ“„ License

MIT License

About

Notification for CoreChain by using Firebase Cloud Messaging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors