Service Discovery
Service discovery in ZinTrust is currently a filesystem + in-memory registry model:
- Filesystem discovery is handled by
MicroserviceBootstrap. - Registered services live in an in-memory map owned by
MicroserviceManager.
There is no pluggable “discovery driver” API in the runtime today.
Filesystem Discovery (recommended for local/dev)
When microservices are enabled (MICROSERVICES=true), MicroserviceBootstrap discovers services by scanning a services directory for:
<servicesDir>/<domain>/<service>/service.config.json
By default, servicesDir is src/services.
Example structure
src/services/
ecommerce/
users/
service.config.json
orders/
service.config.jsonExample config
{
"name": "users",
"version": "1.0.0",
"port": 3001,
"healthCheck": "/health",
"dependencies": ["orders"]
}Bootstrapping discovery
import { MicroserviceBootstrap } from '@zintrust/core';
await MicroserviceBootstrap.getInstance().initialize();This discovers configs and registers them with MicroserviceManager.
In-Memory Registry (MicroserviceManager)
Once registered, services can be listed and called via the manager:
import { MicroserviceManager } from '@zintrust/core';
const manager = MicroserviceManager.getInstance();
// Returns the currently registered services (it does not scan the filesystem)
const services = await MicroserviceManager.discoverServices();
// Call a running service
await manager.startService('users');
const response = await manager.callService('users', '/health');Allow-List via SERVICES
If SERVICES is set (comma-separated), the framework treats it as an allow-list:
- Services not listed will be skipped during registration.
- If
SERVICESis unset/empty, all discovered services are eligible.
Health Checks
The manager can health-check registered services by requesting their configured health path:
import { MicroserviceManager } from '@zintrust/core';
const manager = MicroserviceManager.getInstance();
const healthy = await manager.checkServiceHealth('users');Health checks depend on your services:
- The endpoint must exist.
healthCheckinservice.config.jsonmust match the path your service exposes.
CLI
This repo includes helper commands for generating and inspecting microservices:
npm run microservices:generatenpm run microservices:discovernpm run microservices:statusnpm run microservices:health
Note: the CLI “discover” command reports what MicroserviceManager.discoverServices() returns (registered services), not filesystem scanning.