API Reference
Detailed API documentation for all services
Using Services
All services are available as importable modules
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
UserService
User CRUD operations, profile management
ConfigService
Application configuration management
LoggerService
Structured logging with Pino
Security Services
RateLimitService
Rate limiting with multiple algorithms
WebhookService
Outgoing webhooks with HMAC signatures
MFAService
Two-factor authentication with TOTP
OAuthService
Social login providers
Data Services
CacheService
Redis caching with TTL support
QueueService
Background job processing with BullMQ
SearchService
Full-text search with Elasticsearch/Meilisearch
AnalyticsService
Prometheus metrics and event tracking
Communication Services
EmailService
SMTP email sending with templates
NotificationService
Multi-channel notifications
WebSocketService
Real-time communication with Socket.io
Integration Services
PaymentService
Stripe, PayPal, and mobile money
UploadService
File uploads to S3, Cloudinary, local
MediaService
Image and video processing
FeatureFlagService
A/B testing and feature flags
Utility Services
I18nService
Internationalization and localization
VersioningService
API versioning support
Middleware Reference
authMiddlewareVerify JWT tokens and attach user
rateLimitMiddlewareApply rate limiting to routes
validationMiddlewareValidate request body/params/query
i18nMiddlewareSet locale from request headers
corsMiddlewareHandle Cross-Origin Resource Sharing
helmetMiddlewareAdd security headers
compressionMiddlewareCompress responses
loggerMiddlewareLog all requests
Error Handling
// 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
// }
// }