Skip to content

alakkaya/call-assistant-platform

Repository files navigation

AI Call Assistant Platform

Call Recording & Transcription Service

A robust, production-ready API service built with NestJS that enables users to record phone calls and automatically transcribe them using asynchronous background processing.


πŸ“‹ Table of Contents


🎯 Overview

This platform allows users to:

  1. Register and authenticate using JWT-based authentication with refresh token support
  2. Create and manage phone call records with metadata (title, duration, participants)
  3. Automatically trigger transcription when a call is created (asynchronous background processing)
  4. Track transcription status with real-time updates (pending β†’ processing β†’ completed / failed)
  5. Retrieve transcription results with error handling and retry mechanisms

The project simulates AI transcription with:

  • Random processing delays (2-10 seconds)
  • 5% random failure rate for testing retry logic
  • Mock transcription text generation
  • Exponential backoff retry strategy (3 attempts max)

✨ Features

Authentication & Authorization

  • βœ… User registration with unique nickname validation
  • βœ… JWT-based authentication (access + refresh tokens)
  • βœ… Secure password hashing with bcrypt
  • βœ… Token refresh endpoint
  • βœ… Protected routes with AuthGuard
  • βœ… Redis-based refresh token storage

Call Management

  • βœ… Create new call records
  • βœ… List calls with pagination, sorting, and filtering
  • βœ… Search calls by title or participants
  • βœ… Get call details by ID
  • βœ… Update call information
  • βœ… Delete calls (cascades to transcriptions)
  • βœ… User ownership validation

Transcription Service

  • βœ… Automatic transcription initiation on call creation
  • βœ… Asynchronous background processing with BullMQ
  • βœ… Status tracking: pending β†’ processing β†’ completed / failed
  • βœ… Retry mechanism with exponential backoff (3 attempts)
  • βœ… Error logging and handling
  • βœ… Mock AI transcription simulation
  • βœ… Queue job persistence and monitoring

API Documentation

  • βœ… Swagger/OpenAPI documentation (/api)
  • βœ… Interactive API testing interface
  • βœ… Complete request/response schemas
  • βœ… Error response documentation
  • βœ… Postman / Thunder collection (share link)

Postman/Thunder collection (import):


πŸ›  Tech Stack

Framework & Language

  • NestJS (v11.0.1) - Progressive Node.js framework with excellent TypeScript support, built-in dependency injection, and modular architecture
  • TypeScript (v5.7.3) - Type safety and improved developer experience

Database

  • MongoDB (via Mongoose v8.19.1) - NoSQL database chosen for:
    • Flexible schema for evolving call/transcription data structures
    • Excellent performance for document-based operations
    • Native support for complex queries and aggregations
    • Easy horizontal scaling

Caching & Queue

  • Redis (via ioredis v5.8.1) - Used for:
    • Refresh token storage (session management)
    • Future: Rate limiting and caching
  • BullMQ (v5.61.0) - Robust job queue for:
    • Asynchronous transcription processing
    • Retry mechanisms and job persistence
    • Background task monitoring

Authentication

  • JWT (@nestjs/jwt v11.0.0) - Stateless authentication
  • bcryptjs (v3.0.2) - Secure password hashing

API Documentation

  • Swagger (@nestjs/swagger v11.2.1) - Auto-generated API documentation

Validation

  • class-validator (v0.14.2) - DTO validation
  • class-transformer (v0.5.1) - Object transformation

DevOps

  • Docker & Docker Compose - Containerization for consistent environments
  • ESLint & Prettier - Code quality and formatting

πŸ— Architecture Diagram

Architecture Diagram


πŸ— Architecture Decisions

Why NestJS?

  • Modular Architecture: Clear separation of concerns with modules, services, and controllers
  • TypeScript-first: Full type safety and excellent IDE support
  • Dependency Injection: Easy testing and maintainable code
  • Ecosystem: Built-in support for Swagger, validation, and microservices
  • Production-ready: Battle-tested in enterprise applications

Why MongoDB?

  • Document Model: Natural fit for call records and transcription data
  • Flexibility: Easy to add new fields without migrations
  • Performance: Fast reads/writes for our use case
  • Scalability: Horizontal scaling support for future growth

Why BullMQ?

  • Reliability: Job persistence and fault tolerance
  • Retry Logic: Built-in exponential backoff
  • Monitoring: Redis-based queue dashboard support
  • Performance: Efficient job processing with worker pools

Why Redis?

  • Speed: In-memory storage for fast token validation
  • TTL Support: Auto-expiring refresh tokens
  • Queue Backend: Required for BullMQ
  • Future-proof: Ready for caching and rate limiting

Design Patterns Used

  • Repository Pattern: Data access abstraction
  • Service Layer Pattern: Business logic separation
  • DTO Pattern: Request/response validation and transformation
  • Guard Pattern: Authentication and authorization
  • Interceptor Pattern: Request/response transformation
  • Exception Filter Pattern: Centralized error handling

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • Docker & Docker Compose
  • Git

Installation

  1. Clone the repository

    git clone https://github.com/alakkaya/call-assistant-platform.git
    cd call-assistant-platform
  2. Create environment file

    cp .env.example .env
  3. Update .env with your configuration (optional - defaults work for Docker)

    PORT=3000
    MONGODB_URI=mongodb://mongo:27017/call-assistant-platform
    
    # JWT Secrets (CHANGE IN PRODUCTION!)
    JWT_SECRET_ACCESS=your_secure_access_secret_key_here
    JWT_SECRET_REFRESH=your_secure_refresh_secret_key_here
    JWT_EXPIRATION_ACCESS=1h
    JWT_EXPIRATION_REFRESH=7d
    
    # Redis
    REDIS_HOST=redis
    REDIS_PORT=6379
  4. Start with Docker Compose

    cd docker
    docker-compose up --build -d
  5. Verify services are running

    docker ps

    You should see:

    • call-assistant-platform-app (API server)
    • call-assistant-platform-mongo (MongoDB)
    • call-assistant-platform-redis (Redis)
  6. Access the application


πŸ“š API Endpoints

Authentication

Method Endpoint Description Auth Required
POST /auth/register Register new user ❌
POST /auth/login Login and get tokens ❌
POST /auth/logout Logout (invalidate refresh token) βœ…
POST /auth/refresh-token Refresh access token ❌
GET /auth/me Get current user info βœ…

Calls

Method Endpoint Description Auth Required
POST /calls Create new call (auto-starts transcription) βœ…
GET /calls List calls (with pagination, sorting, search) βœ…
GET /calls/:id Get call details βœ…
PUT /calls/:id Update call information βœ…
DELETE /calls/:id Delete call (cascades to transcription) βœ…

Transcription

Method Endpoint Description Auth Required
GET /calls/:callId/transcription Get transcription status/result βœ…

Example Request Flow

Detailed example requests were intentionally removed from the public README to keep documentation concise. Use the Swagger UI at /api for interactive testing and concrete request examples.


πŸ” Environment Variables

This project already includes a .env.example in the repository root. Copy it to .env and update values as needed. The .env.example covers the required variables (PORT, MONGODB_URI, JWT secrets and Redis settings).

Security note: Keep secrets out of version control and rotate JWT secrets in production.


🐳 Docker Setup

Starting the Application

# Navigate to docker directory
cd docker

# Build and start all services
docker-compose up --build -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Docker Services

The docker-compose.yml defines 3 services:

  1. call-assistant-platform-app (Node.js API)

    • Port: 3000:3000
    • Depends on: MongoDB, Redis
    • Volume mounts source code for hot-reload
  2. call-assistant-platform-mongo (MongoDB)

    • Port: 27016:27017 (external:internal)
    • Persistent data storage
  3. call-assistant-platform-redis (Redis)

    • Port: 6378:6379 (external:internal)
    • Used for queues and token storage

docker restart call-assistant-platform-app docker logs -f call-assistant-platform-app docker exec -it call-assistant-platform-app sh docker exec -it call-assistant-platform-mongo mongosh docker exec -it call-assistant-platform-redis redis-cli


πŸ’» Development

Local development steps are intentionally shortened in this README. Use the following quick commands for development and testing; more detailed guides live in the developer docs or project wiki.

# Install dependencies
npm install

# Start in development mode (requires MongoDB and Redis to be available)
npm run start:dev

# Build & run production
npm run build
npm run start:prod

# Lint & format
npm run lint
npm run format

# Testing
npm run test
npm run test:e2e
npm run test:cov

πŸ“ Project Structure

call-assistant-platform/
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ Dockerfile              # Node.js app container
β”‚   └── docker-compose.yml      # Multi-container setup
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/                   # Shared utilities and core functionality
β”‚   β”‚   β”œβ”€β”€ cache/              # Redis service and cache utilities
β”‚   β”‚   β”œβ”€β”€ decorator/          # Custom decorators (ApiResponse, ReqUser, etc.)
β”‚   β”‚   β”œβ”€β”€ enum/               # Shared enums (TranscriptionStatus)
β”‚   β”‚   β”œβ”€β”€ error/              # Custom exceptions and error codes
β”‚   β”‚   β”œβ”€β”€ filter/             # Global exception filter
β”‚   β”‚   β”œβ”€β”€ guard/              # Authentication guard
β”‚   β”‚   β”œβ”€β”€ helper/             # Utility functions (mongo, mask)
β”‚   β”‚   β”œβ”€β”€ interceptor/        # Response transformation interceptor
β”‚   β”‚   └── interface/          # TypeScript interfaces
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ auth/               # Authentication module
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/     # Login, register, refresh endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # Request/response DTOs
β”‚   β”‚   β”‚   └── service/        # JWT logic, token management
β”‚   β”‚   β”œβ”€β”€ calls/              # Call management module
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/     # CRUD endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # Call DTOs
β”‚   β”‚   β”‚   β”œβ”€β”€ model/          # Mongoose schema
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/     # Data access layer
β”‚   β”‚   β”‚   └── service/        # Business logic
β”‚   β”‚   β”œβ”€β”€ transcription/      # Transcription module
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/     # Get transcription endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # Transcription DTOs
β”‚   β”‚   β”‚   β”œβ”€β”€ model/          # Mongoose schema
β”‚   β”‚   β”‚   β”œβ”€β”€ processor/      # BullMQ job processor
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/     # Data access layer
β”‚   β”‚   β”‚   └── service/        # Queue management, status updates
β”‚   β”‚   β”œβ”€β”€ user/               # User module
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # User DTOs
β”‚   β”‚   β”‚   β”œβ”€β”€ model/          # Mongoose schema
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/     # Data access layer
β”‚   β”‚   β”‚   └── service/        # User operations
β”‚   β”‚   └── utils/
β”‚   β”‚       └── bullmq/         # BullMQ configuration module
β”‚   β”œβ”€β”€ app.module.ts           # Root application module
β”‚   └── main.ts                 # Application entry point
β”œβ”€β”€ test/                       # Test files
β”œβ”€β”€ .env.example                # Environment variables template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ nest-cli.json
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ tsconfig.json
└── tsconfig.build.json

πŸ“ TODO / Future Improvements

High Priority

  • Unit Tests: Add comprehensive test coverage for services and repositories
  • E2E Tests: Implement end-to-end API tests with supertest
  • CI/CD Pipeline: Set up GitHub Actions for automated testing and deployment
  • Logging: Implement structured logging (Winston/Pino) with log levels
  • Monitoring: Add health check endpoints and metrics (Prometheus)

Performance & Scalability

  • Event-Driven Architecture: Replace circular dependencies with event emitters (NestJS EventEmitter)
    • Decouple CallService β†’ TranscriptionService dependency
    • Use domain events: call.created, call.deleted, etc.
  • Database Indexing: Add indexes on frequently queried fields (userId, callId, status)
  • Caching Strategy: Cache frequently accessed data (user profiles, call summaries)
  • Rate Limiting: Implement API rate limiting to prevent abuse

Security Enhancements

  • Input Sanitization: Add MongoDB injection protection
  • CORS Configuration: Properly configure CORS for production
  • Helmet.js: Add security headers
  • API Versioning: Implement versioned API endpoints (/v1/calls)
  • Secrets Management: Integrate with AWS Secrets Manager or Vault
  • Audit Logs: Track sensitive operations (login, data modifications)

Features

  • Real AI Integration: Replace mock transcription with actual AI service (OpenAI Whisper, Google Speech-to-Text)
  • Audio File Upload: Support actual call recording file uploads (S3/MinIO storage)
  • Webhooks: Notify external systems when transcription completes
  • Search Improvements: Full-text search on transcription content (Elasticsearch)
  • Analytics Dashboard: User statistics, transcription success rates, average processing time
  • Call Tags/Categories: Add tagging system for better organization
  • Shared Calls: Allow users to share call transcriptions with others

Code Quality

  • SonarQube Integration: Static code analysis
  • Dependency Updates: Automated dependency update checks (Dependabot)
  • Performance Profiling: Add APM (Application Performance Monitoring)
  • Error Tracking: Integrate Sentry or similar error tracking service

πŸ“„ License

This project is MIT licensed.


🀝 Contributing

Contributions, issues, and feature requests are welcome!


πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Built with ❀️ using NestJS

About

A robust API service built with NestJS for call recording, transcription, and asynchronous processing. Features JWT authentication, Redis caching, MongoDB, and BullMQ for background tasks.

Topics

Resources

Stars

Watchers

Forks

Contributors