LogoEurekaCodes
Technology

[Backend] eureka-chats-api

Serverless real-time chat microservice with WebSocket integration. serverless backend API service for real-time chat applications.

eureka-chats-api

Serverless real-time chat microservice with WebSocket integration.

Summary

  • serverless backend API service for real-time chat applications.
  • This project is a sample chat boilerplate based on AWS Lambda and Node.js.
  • Key features include WebSocket-based real-time messaging through integration with the eureka-sockets-api microservice, chat room management, and user session handling.
  • Note: To use this project, you must first deploy the eureka-sockets-api microservice to the cloud.

Getting Started

  • Pre requirements (or installations) before starting.
    1. aws-cli with api-key
    1. git
    1. nodejs22
    1. (optional) httpie
    1. (optional) wscat
    • Fork(or clone), develop and deploy the serverless api.
# clone the code.
$ git clone https://github.com/lemoncloud-io/eureka-sockets-api.git

# STEP.1 install the dependecies.
$ npm ci

# STEP.2 run the server locally.
$ npm run express

# STEP.3 make request and develop locally.
$ http :8832/hello

# STEP.4 deploy into your AWS cloud (`AWS-Key` is required).
$ npm run deploy

# (example) try to connect to a WebSocket
$ wscat -c wss://a5jxmksfa2.execute-api.ap-northeast-2.amazonaws.com/dev

# STEP.5 check the deploy info
$ npm run info

# STEP.6 remove(or uninstall)
$ npm run remove

Architecture and Modeling

Infrastructure Components

[backend] eureka-chats-api image

Data Modeling

[backend] eureka-chats-api image

Chat Flow Architecture

Module Structure

src/
├── cores/                  # Common architecture
│   ├── abstract-controllers.ts  # CRUD controller base
│   ├── abstract-services.ts     # Service layer base
│   └── types.ts                 # Common types
├── modules/                # Business modules
│   ├── chats/             # Chat service (core module)
│   │   ├── api-chats.ts   # Chat API controller
│   │   ├── api-rooms.ts   # Chat room API controller
│   │   ├── model.ts       # Chat data model
│   │   ├── service.ts     # Chat business logic
│   │   ├── proxy.ts       # Chat data access
│   │   ├── transformer.ts # Data transformation
│   │   ├── types.ts       # Chat type definitions
│   │   └── views.ts       # Chat view models
│   ├── callback/          # External callback handling
│   │   ├── api-callback.ts
│   │   ├── model.ts
│   │   ├── service.ts
│   │   └── ...
│   ├── mock/              # Test mock data
│   │   ├── api-mocks.ts
│   │   ├── api-tests.ts
│   │   └── ...
│   └── search/            # Search functionality
│       ├── api-search.ts
│       ├── model.ts
│       └── service.ts
├── service/               # Core services
│   ├── backend-service.ts # Main service
│   ├── backend-proxy.ts   # Data access layer
│   └── backend-model.ts   # Data models
└── api/                   # API endpoints
    ├── hello-api.ts       # Health check
    └── crons-api.ts       # Scheduled tasks

Key Features

Chat Service Support

  • Chat Room Management (Rooms)
- `GET /rooms` - List chat rooms
- `GET /rooms/{id}` - Get room details
- `POST /rooms/0` - Create new chat room
- `PUT /rooms/{id}` - Update room information
- `DELETE /rooms/{id}` - Delete chat room
  • Chat Messages (Chats)
- `GET /chats` - List messages (with pagination)
- `GET /chats/{id}` - Get message details
- `POST /chats/0/start-chat` - Join chat room
- `POST /chats/0/chat` - Send message
- `POST /chats/{nodeId}/leave-chat` - Leave chat room

Usage Examples

# Create chat room
POST /rooms/0
{
  "name": "ChatRoom 1",
  "isPrivate": false
}

# Join chat room
POST /chats/0/start-chat
{
  "roomId": "room123",
  "name": "guest",
  "connectionId": "QXaagd6MIE0CFtw="
}

# Send new message
POST /chats/0/chat
{
  "roomId": "room123",
  "nodeId": "node123",
  "message": "hello world"
}

# Leave chat room
POST /chats/<node-id>/leave-chat

LICENSE

MIT

VERSION INFO

Version History

VersionDescription
0.25.818implements chat-service.
0.25.808optimized lemon-core@4.0.6 initially.