Backend Package
The Backend package provides a central sync server for ID PASS DataCollect, enabling multi-client synchronization, user management, and integration with external systems.
Built with Node.js, Express.js, and PostgreSQL, the Backend serves as the central hub for:
- Multi-client data synchronization
- User authentication and authorization
- Multi-tenant configuration management
- External system integration
Key Featuresβ
- ποΈ PostgreSQL Storage: Reliable, ACID-compliant data persistence
- π Multi-Client Sync: Coordinate data across multiple DataCollect clients
- π₯ User Management: Authentication, authorization, and role-based access
- π’ Multi-Tenant: Support multiple organizations with isolated configurations
- π External Integration: Connect with OpenSPP, OpenFn, and custom systems
- π Security: JWT authentication with configurable session management
Architectureβ
Core Componentsβ
Sync Serverβ
Handles bidirectional synchronization between clients and server:
- Event Processing: Applies events from clients to server state
- Conflict Resolution: Manages concurrent updates with version control
- Pagination: Efficient data transfer with configurable batch sizes
User Managementβ
Complete authentication and authorization system:
- JWT Authentication: Secure token-based authentication with OAuth provider support
- OAuth Integration: Support for Auth0, Keycloak, and custom OAuth providers
- Role-Based Access: Admin and user roles with different permissions
- Multi-Provider Auth: Configure multiple authentication providers per tenant
- Initial Setup: Automatic admin user creation on first run
Multi-Tenant Supportβ
Isolated environments for different organizations:
- App Configurations: Custom forms and entity definitions per tenant
- Authentication Configs: Per-tenant OAuth provider configurations
- Data Isolation: Complete separation of tenant data
- External Sync Config: Per-tenant integration settings
Quick Startβ
Installationβ
cd backend
npm install
Environment Setupβ
Create a .env file:
# Database Configuration
POSTGRES=postgresql://admin:admin@localhost:5432/postgres
POSTGRES_TEST=postgresql://admin:admin@localhost:5432/test
# Authentication
ADMIN_EMAIL=admin@hdm.example
ADMIN_PASSWORD=your-secure-password
JWT_SECRET=your-jwt-secret
# Server Configuration
PORT=3000
Developmentβ
npm run dev
Productionβ
npm run build
npm start
Configurationβ
App Configuration Filesβ
Define tenant-specific settings using JSON configuration:
{
"id": "organization-1",
"name": "Organization Name",
"description": "Organization description",
"version": "1.0.0",
"authConfigs": [
{
"type": "auth0",
"fields": {
"domain": "your-domain.auth0.com",
"clientId": "your-client-id",
"audience": "your-api-audience",
"scope": "openid profile email"
}
},
{
"type": "keycloak",
"fields": {
"url": "https://keycloak.example.com",
"realm": "your-realm",
"clientId": "your-client-id",
"scope": "openid profile email"
}
}
],
"entityForms": [
{
"name": "household",
"title": "Household Registration",
"formio": { /* FormIO JSON schema */ }
}
],
"entityData": [
{
"name": "household",
"data": [ /* Initial data */ ]
}
],
"externalSync": {
"type": "openspp",
"auth": "basic",
"url": "https://openspp.example.com",
"credentials": {
"username": "sync-user",
"password": "sync-password"
}
}
}
API Documentationβ
The Backend provides a comprehensive REST API with full OpenAPI 3.0 documentation:
π Complete API Referenceβ
Detailed documentation of all endpoints, request/response schemas, and examples.
π Interactive API Documentationβ
Live Swagger UI for testing endpoints directly (available when server is running).
π OpenAPI Specificationβ
Complete OpenAPI 3.0 YAML specification for client generation and tooling.
Quick API Overviewβ
Authentication & Users
POST /api/users/login- User authenticationGET /api/users- User management (Admin only)GET /api/users/me- Current user info
Data Synchronization
GET /api/sync/pull- Pull events from serverPOST /api/sync/push- Push events to serverPOST /api/sync/external- External system sync
App Configuration
GET /api/apps- List configurations (supportspage,pageSize,sortBy,sortOrder, andsearchquery params; includes entity counts)POST /api/apps- Upload configurationDELETE /api/apps/{id}- Delete configuration
Data Management
GET /api/potential-duplicates- List duplicatesPOST /api/potential-duplicates/resolve- Resolve duplicates
External System Integrationβ
Available Adaptersβ
OpenSPP Adapterβ
Integration with OpenSPP social protection platform :
- Push household and individual registrations from DataCollect into OpenSPP
- Requires Odoo credential configuration per tenant
- Pull support and advanced enrollment workflows are planned; treat current integration as beta
OpenFn Adapterβ
Integration with OpenFn workflow automation:
- Event-driven data transformation
- Custom workflow triggers
- Multi-system orchestration
Mock Sync Serverβ
Development and testing adapter:
- Simulates external system behavior
- Configurable response patterns
- Testing synchronization logic
Custom Adapter Developmentβ
Create custom adapters by implementing the ExternalSyncAdapter interface:
interface ExternalSyncAdapter {
async pushData(entities: EntityDoc[]): Promise<void>;
async pullData(): Promise<EntityDoc[]>;
async authenticate(credentials: ExternalSyncCredentials): Promise<boolean>;
}
Deploymentβ
Docker Deploymentβ
Complete Docker setup with PostgreSQL
Environment Configurationβ
Detailed configuration options
Monitoring and Maintenanceβ
Health Checksβ
GET /health- Server health status- `