đ ī¸ Service
Nodeblocks backend is composed of modular services, each responsible for a specific piece of business logic and data.
Every service follows the same conventions so that integrating, extending or swapping them remains straightforward.
đ What is a Service?â
A service is a thin wrapper around one or more features (use-case bundles that contain routes, schemas and handlers).
At runtime the wrapper wires dependencies (e.g. a MongoDB collection) and exposes a typed interface you can call from code or automatically map to HTTP and WebSocket endpoints through the provided router utilities.
âââââââââââââââ
â Service â userService(db)
âââââââââââââââ¤
â Features ⡠createUserFeature
â ⡠getUserFeatures
â ⡠editUserFeatures
â ⡠...
âââââââââââââââ
Key take-aways:
- Pure functions â no global state, every dependency is passed explicitly (great for testing!).
- Composable â reuse/compose features between services or build your own.
- Database-agnostic â only a
Collection
interface is required; swap Mongo for a stub in tests.
đ Available Servicesâ
Service | NPM import | Responsibility | Docs |
---|---|---|---|
Authentication | authService | User authentication (register, login, logout, JWT tokens) | Docs Âģ |
User | userService | Manage application users (CRUD, lock/unlock) | Docs Âģ |
Organization | organizationService | Create & manage organizations/workspaces | Docs Âģ |
Product | productService | Complex product management inc. batch & copy ops | Docs Âģ |
Category | categoryService | Maintain product or content categories | Docs Âģ |
Attribute | attributeService | Manage key-value attributes and attribute groups | Docs Âģ |
Order | orderService | E-commerce order management with items and pricing | Docs Âģ |
Chat | chatService | Real-time messaging with channels, subscriptions, and messages | Docs Âģ |
âšī¸ All services have been tested with live API endpoints and include comprehensive Bruno test suites. More services will be added to the SDK over time. Feel free to open an issue or PR for suggestions!
đ§âđģ Consuming Services Programmaticallyâ
All services share the same signature: they are factory functions that take a database object with named collections, configuration, and optional drivers (mail/file storage/OAuth) and return an Express router.
import express from 'express';
import { MongoClient } from 'mongodb';
import { middlewares, services } from '@nodeblocks/backend-sdk';
const { nodeBlocksErrorMiddleware } = middlewares;
const { userService } = services;
const client = new MongoClient('mongodb://localhost:27017').db('dev');
express()
.use(
userService(
{
users: client.collection('users'),
identity: client.collection('identity'),
},
{
authSecrets: {
authEncSecret: 'your-encryption-secret',
authSignSecret: 'your-signing-secret',
},
},
{
// Optional drivers (when needed)
// mailService,
// fileStorageDriver,
// googleOAuthDriver,
}
)
)
.use(nodeBlocksErrorMiddleware())
.listen(8089, () => console.log('Server running'));
đ Design Principlesâ
âĸ Single responsibility â each service targets one domain entity.
âĸ Extensibility first â compose, override, or decorate features without forking the codebase.
âĄī¸ Nextâ
Start with the Authentication Service for user authentication, or explore other services based on your needs. For real-time functionality, check out the WebSocket Service Guide. All services follow the same patterns and conventions!