Skip to content

AI Hub Package

Overview

The @delta/aiHub package is a Node.js service that provides AI processing capabilities for the Delta platform. It serves as the central hub for AI-related operations, handling requests from the app and other services.

Purpose

  • AI processing and inference
  • Integration with external AI services
  • Request queuing and processing
  • Scalable AI workload management

Technology Stack

  • Runtime: Node.js with TypeScript
  • Framework: Express.js for HTTP server
  • Testing: Jest with comprehensive test coverage
  • Containerization: Docker support
  • Logging: Integration with @delta/common logger
  • AWS Integration: SQS for message queuing

Key Components

Main Service

  • Location: src/index.ts
  • Purpose: Main entry point for the AI Hub service
  • Features:
  • Service initialization
  • Request handling
  • Error management

Logger Integration

  • Location: src/lib/logger.ts
  • Purpose: AI Hub-specific logging functionality
  • Features:
  • Extends common logger with service-specific context
  • Performance monitoring
  • Request/response logging

Development

Local Development

# Install dependencies
yarn install

# Start development server with debugging
yarn run dev

# Start with Docker
docker build -t delta-aihub .
docker run -p 3000:3000 delta-aihub

Environment Setup

Copy .env.local.example to .env.local and configure:

  • AI service API keys
  • Database connections
  • Service endpoints
  • Logging configuration
  • AWS SQS configuration

Testing

Unit Tests

# Run tests
yarn test

# Run tests in watch mode
yarn run test:watch

# Run tests with coverage
yarn run test:coverage

Test Configuration

  • Jest Config: jest.config.js
  • Test Setup: jest.setup.js
  • Test Files: *.test.ts files alongside source code

Docker Support

Dockerfile

The package includes a Dockerfile for containerized deployment:

  • Multi-stage build for optimization
  • Production-ready configuration
  • Health checks and monitoring

Docker Ignore

.dockerignore file excludes unnecessary files from the Docker build context.

Build and Deployment

Production Build

# Build TypeScript
yarn run build

# Start production server
yarn start

Container Deployment

# Build container
docker build -t delta-aihub .

# Run container
docker run -d -p 3000:3000 --env-file .env delta-aihub

Configuration

  • tsconfig.json - TypeScript configuration
  • package.json - Dependencies and scripts
  • Dockerfile - Container configuration
  • .env.local.example - Environment variables template

Dependencies

Runtime Dependencies

  • Express.js for HTTP server
  • AWS SDK for SQS integration
  • Alova for HTTP requests (lightweight request library)
  • Dotenv for environment configuration

Development Dependencies

  • Jest for testing
  • TypeScript and ts-node for development
  • Nodemon for development server

Internal Dependencies

  • @delta/common - Shared utilities and logging

Integration Points

  • App: Receives processing requests from the web application
  • SQS: Integration with AWS SQS for queue processing
  • Database: Data persistence and retrieval
  • External AI Services: Integration with third-party AI providers

Monitoring and Logging

  • Comprehensive logging through @delta/common
  • Performance metrics collection
  • Error tracking and alerting
  • Health check endpoints

Scalability

  • Designed for horizontal scaling
  • Queue-based processing for high throughput
  • Container-ready for orchestration platforms
  • Stateless design for load balancing

API Endpoints

The service provides RESTful API endpoints for:

  • AI processing requests
  • Health checks
  • Status monitoring
  • Queue management

Error Handling

  • Graceful error handling and recovery
  • Retry mechanisms for failed requests
  • Circuit breaker patterns for external services
  • Comprehensive error logging

Performance

  • Optimized for high-throughput processing
  • Asynchronous request handling
  • Connection pooling for external services
  • Memory and CPU monitoring