• TypeScript 99.3%
  • JavaScript 0.5%
  • Dockerfile 0.2%
Find a file
Bart Ramakers 7b0185400c chore: merge 'renovate/rollup-rollup-linux-arm64-musl-4.x-lockfile' into 'develop'
chore(deps): update dependency @rollup/rollup-linux-arm64-musl to v4.54.0

See merge request logius/nldoc/worker/stations!513
2025-12-31 10:45:00 +01:00
.husky chore: rename helm folder 2024-09-03 10:22:30 +02:00
.vscode refactor: migrate to shared eslint config 2025-07-30 17:15:00 +02:00
__mocks__ chore: intermediate single exchange refactor 2025-10-08 17:33:22 +02:00
__test__ chore: tests 2025-11-10 14:25:02 +01:00
integration chore: integration 2025-10-14 18:36:09 +02:00
rabbitmq/etc feat: AMQP messaging 2023-07-24 11:05:05 +00:00
src chore: updated mocks to conform to node v24 (new Mock()) 2025-12-24 09:57:26 +01:00
.editorconfig chore: set .editorconfig 2025-04-22 01:08:07 +00:00
.gitignore feat: deleted chart tgz files from repo, added to gitignore 2024-06-11 18:24:12 +02:00
.gitlab-ci.yml chore(deps): update node.js to v24 2025-12-14 00:37:58 +00:00
.npmrc fix: update references (GitLab migration) 2025-04-07 13:12:55 +02:00
.nvmrc chore(deps): update node.js to v24 2025-12-14 00:37:58 +00:00
.prettierignore chore: initial commit 2023-06-29 16:27:07 +02:00
CHANGELOG.md chore(release): 13.0.1 2025-12-23 14:35:11 +00:00
CODEOWNERS chore: set CODEOWNERS 2025-04-22 00:26:25 +00:00
commitlint.config.cts feat: mermaid diagram 2024-04-09 15:59:46 +00:00
docker-compose.yaml chore(deps): update node.js to v24 2025-12-14 00:37:58 +00:00
Dockerfile chore(deps): update node.js to v24 2025-12-14 00:37:58 +00:00
esbuild.config.ts feat: purge data on document completion 2025-01-09 17:22:21 +01:00
eslint.config.mjs refactor: amqp manager 2025-09-26 00:56:29 +02:00
LICENSE chore: add correct license 2025-04-15 00:11:36 +02:00
package-lock.json Merge branch 'develop' into renovate/rollup-rollup-linux-arm64-musl-4.x-lockfile 2025-12-31 10:42:55 +01:00
package.json Merge branch 'develop' into renovate/node-24.x 2025-12-24 09:52:09 +01:00
prettier.config.mjs refactor: migrate to shared eslint config 2025-07-30 17:15:00 +02:00
README.md feat(postgres)!: add SSL/TLS configuration with self-signed certificate support 2025-12-23 12:17:09 +01:00
renovate.json chore: npm install twice 2025-11-05 14:08:39 +00:00
tsconfig.dist.json feat: use esbuild 2023-07-03 15:45:45 +02:00
tsconfig.json chore: remove rule 2025-07-30 17:18:54 +02:00
vitest.config.ts feat(NLD-775): implement S3 store 2025-03-28 00:06:03 +01:00

NLdoc Stations

pipeline status coverage report Latest Release

A TypeScript framework for building document processing stations within the NLdoc pipeline. Stations are modular processing units that handle documents, pages, and attributes through AMQP message queuing, enabling scalable and orchestrated document processing workflows.

Overview

NLdoc Stations provides the core infrastructure for creating processing stations that:

  • Process documents through configurable input/output pipelines
  • Coordinate with workers for delegated processing tasks
  • Handle message queuing via RabbitMQ/AMQP
  • Enable distributed document processing workflows

Features

  • Modular Architecture: Build custom processing stations with configurable input/output types
  • Message Queue Integration: RabbitMQ/AMQP support for reliable message processing
  • Worker Coordination: Delegate processing tasks to external workers
  • State Management: Track processing state across distributed components
  • Docker Ready: Containerized deployment with Docker Compose support
  • TypeScript: Full type safety and modern ES modules

Station Types

The framework supports various station configurations for different processing stages:

  • Document Stations: Process entire documents (mimetype detection, metadata extraction)
  • Page Stations: Handle individual document pages (content extraction, region detection)
  • Aggregation Stations: Aggregate child-item processing results (e.g., wait for all pages before processing)
  • Attribute Stations: Manage document and page attributes
  • Output Stations: Generate final processing outputs

Station types are configured via the STATION_CONFIGURATION environment variable. See StationConfiguration for the complete schema.

Getting Started

Local Installation

  1. Clone the repository:

    git clone https://gitlab.com/logius/nldoc/worker/stations.git
    cd stations
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    
  1. Ensure Docker and Docker Compose are installed (Installation Guide)

  2. Start the services:

    docker compose up
    
  3. Access the management interfaces:

    • RabbitMQ Console: http://localhost:15672/ (guest/guest)
    • PostgreSQL: localhost:5432 (postgres/postgres)
  4. Run integration tests:

    npm run test
    
  5. Stop services:

    docker compose down
    

Running Directly

To run a station directly:

npm run start:station

Or in development mode:

npm run dev

Configuration

Stations are configured via environment variables and JSON configuration. For complete configuration options, see the Environment Configuration Schema.

Key environment variables include:

# Station Configuration (JSON)
STATION_CONFIGURATION='{
  "input": {"type": "document"},
  "workerResult": "fileWorkerResult",
  "output": {"type": "output", "attribute": {"type": "file", "name": "source"}}
}'

# General Configuration
ENVIRONMENT=development
npm_package_version=9.5.1

# AMQP Configuration
AMQP_HOST=localhost
AMQP_PORT=5672
AMQP_USER=guest
AMQP_PASS=guest
## Maximum size in bytes for result stream segments before splitting
AMQP_RESULTS_STREAM_MAX_SEGMENT_SIZE=1000000

# PostgreSQL Configuration
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=nldoc
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
## PostgreSQL schema (namespace for tables). Use to isolate data between environments or tenants
POSTGRES_SCHEMA=public
## SSL/TLS connection mode: (default=verify-full)
## - disable: Disable SSL connection
## - require: Require SSL connection
## - allow: Use SSL if available
## - prefer: Prefer SSL but allow non-SSL
## - verify-full: Require SSL with full certificate verification
POSTGRES_SSL=verify-full
## Path to CA certificate file for validating self-signed certificates.
## Only used when POSTGRES_SSL=verify-full.
POSTGRES_SSL_CA_PATH=/path/to/server-ca.crt
## Maximum number of connections in the pool
POSTGRES_POOL_SIZE=20

Architecture

AMQP Message Queue

The AMQP module provides a centralized manager-based architecture for message queue operations:

  • AmqpManager: Core orchestrator managing connections, channels, exchanges, queues, and message flow
  • MessageProcessor: Handles incoming message processing with validation and error handling
  • MessageValidator: Validates message structure and content before processing
  • MessageRetryHandler: Manages message requeuing and retry logic with exponential backoff
  • ExchangeConfigRegistry: Maps station input/output types to exchange configurations
  • ConnectionConfig: Builds connection URLs from environment variables

The manager establishes exchanges for each document type (documents, PDF, images, etc.), binds queues based on topic patterns, and coordinates worker communication through dedicated job/result exchanges.

Worker Coordination

Stations can delegate processing tasks to external workers through a worker management system:

  • WorkerRegistry: Tracks available worker instances and their capabilities
  • WorkerManager: Coordinates job distribution and worker health monitoring
  • JobPublisher: Publishes jobs to worker exchanges

Workers communicate via dedicated AMQP exchanges for jobs, results, and health status, enabling horizontal scaling of processing tasks.

State Management

The state management layer handles document and page processing state:

  • StateManager: Manages source object state, attributes, and worker job tracking
  • SourceObjectManager: Provides storage abstraction
  • LockMonitor: Implements distributed locking using proper-lockfile for concurrent processing safety

State is persisted to ensure fault tolerance and processing resumability across station restarts.

Development

Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm run test - Run tests with coverage
  • npm run lint - Run ESLint
  • npm run format - Format code with Prettier
  • npm run check - Type check without emitting files

Testing and Development

  1. Install dependencies and run tests:

    npm install
    npm run test
    
  2. Run integration tests (requires Docker Compose services):

    docker compose up -d postgresql rabbitmq
    npx tsx integration/test-worker-attribute.ts
    

Deployment

Docker Images

Pre-built Docker images are available in our container registry.

Run the latest version:

docker run --rm registry.gitlab.com/logius/nldoc/worker/stations:latest

Documentation

An Example Architecture

flowchart TB
    Document{Document} ===> station-document-mimetype[station-document-mimetype]
    station-document-mimetype ===> |mimetype| Document
    Document ===> |mimetype| station-document-metadata[station-document-metadata]
    station-document-metadata ===> Document
    Document ===> |mimetype, pageCount| station-document-pages[station-document-pages]
    station-document-pages ===> Page{Page}
    Page ===> |interpretedContent, regions| station-page-content[station-page-content]
    station-page-content ===> |content| Page
    Page ===> |content| station-pdf-aggregation-documentcontent[station-pdf-aggregation-documentcontent]
    station-pdf-aggregation-documentcontent ===> |content| Document
    Document ===> |content| station-document-output[station-document-output]
    station-document-output ===> Output{Output}

Note: The station-pdf-aggregation-documentcontent station uses the aggregation pattern (type: 'pdf' with aggregation config) to wait for all page content before processing.

License

This project is licensed under the European Union Public License 1.2 - see LICENSE for details.