Back to Documentation

API Reference

Detailed API documentation for all services

Using Services

All services are available as importable modules

src/controllers/post.controller.ts
import { authService } from '../modules/auth/service';
import { userService } from '../modules/users/service';
import { cacheService } from '../modules/cache/service';

// Using services in your controller
class PostController {
  async getPosts(req, res) {
    // Check cache first
    const cached = await cacheService.get('posts:latest');
    if (cached) {
      return res.json(cached);
    }

    // Fetch from database
    const posts = await prisma.post.findMany({
      where: { published: true },
      include: { author: true }
    });

    // Cache the result for 5 minutes
    await cacheService.set('posts:latest', posts, 5 * 60);

    res.json(posts);
  }

  async createPost(req, res) {
    const { title, content } = req.body;
    const userId = req.user.id;

    // Create the post
    const post = await prisma.post.create({
      data: {
        title,
        content,
        authorId: userId
      }
    });

    // Invalidate cache
    await cacheService.invalidate('posts:latest');

    // Emit real-time update
    await wsService.broadcastToAll('post:new', post);

    res.status(201).json(post);
  }
}

Available Services

All services follow consistent patterns with TypeScript types

Core Services

AuthService

JWT authentication, token management, password hashing

login()register()logout()refresh()validate()

UserService

User CRUD operations, profile management

create()findById()findByEmail()update()delete()

ConfigService

Application configuration management

get()set()validate()reload()

LoggerService

Structured logging with Pino

info()warn()error()debug()child()

Security Services

RateLimitService

Rate limiting with multiple algorithms

check()consume()reset()getRemaining()

WebhookService

Outgoing webhooks with HMAC signatures

publish()retry()cancel()status()

MFAService

Two-factor authentication with TOTP

setup()verify()disable()backupCodes()

OAuthService

Social login providers

getAuthUrl()handleCallback()refreshToken()

Data Services

CacheService

Redis caching with TTL support

get()set()delete()invalidate()flush()

QueueService

Background job processing with BullMQ

addJob()process()schedule()cancel()status()

SearchService

Full-text search with Elasticsearch/Meilisearch

index()search()delete()update()

AnalyticsService

Prometheus metrics and event tracking

track()metric()gauge()histogram()

Communication Services

EmailService

SMTP email sending with templates

send()sendTemplate()verifyConnection()

NotificationService

Multi-channel notifications

send()sendBulk()sendPush()sendSMS()

WebSocketService

Real-time communication with Socket.io

broadcast()emitToUser()joinRoom()leaveRoom()

Integration Services

PaymentService

Stripe, PayPal, and mobile money

createPayment()confirmPayment()refund()webhook()

UploadService

File uploads to S3, Cloudinary, local

upload()delete()getUrl()getSignedUrl()

MediaService

Image and video processing

resize()compress()transcode()thumbnail()

FeatureFlagService

A/B testing and feature flags

isEnabled()getValue()toggle()trackVariant()

Utility Services

I18nService

Internationalization and localization

t()setLocale()getLocale()addTranslations()

VersioningService

API versioning support

getVersion()setVersion()getCompatible()

Middleware Reference

authMiddleware

Verify JWT tokens and attach user

rateLimitMiddleware

Apply rate limiting to routes

validationMiddleware

Validate request body/params/query

i18nMiddleware

Set locale from request headers

corsMiddleware

Handle Cross-Origin Resource Sharing

helmetMiddleware

Add security headers

compressionMiddleware

Compress responses

loggerMiddleware

Log all requests

Error Handling

HttpError class
// Throw HTTP errors
import { HttpError } from '../utils/errors';

class UserController {
  async getUser(req, res) {
    const { id } = req.params;

    const user = await userService.findById(id);
    if (!user) {
      throw new HttpError(404, 'User not found');
    }

    if (user.id !== req.user.id && req.user.role !== 'ADMIN') {
      throw new HttpError(403, 'Forbidden');
    }

    res.json(user);
  }
}

// Error response format
// {
//   "error": {
//     "code": "NOT_FOUND",
//     "message": "User not found",
//     "status": 404
//   }
// }

Ready to Start Building?