Overview
The jre-notion-workers system is built on a clean, layered architecture that separates pure business logic from I/O operations. This design ensures testability, maintainability, and predictable behavior.Core Design Principles
Every component in the system adheres to these fundamental principles:Single Responsibility
One worker (tool) does one thing. Each worker has a clear, focused purpose.
Pure Logic Core
Parsing, formatting, and validation are I/O-free and unit-testable.
Thin I/O Shell
Notion API calls are isolated in worker
execute functions or shared helpers.Typed Contracts
Every worker has explicit
*Input and *Output types in src/shared/types.ts.Fail Fast Philosophy: Validate all inputs at the start of
execute. Return { success: false, error } instead of throwing exceptions.Layered Structure
The system is organized into four distinct layers, each with a specific responsibility:Layer Responsibilities
Entry Layer (src/index.ts)
Entry Layer (src/index.ts)
The entry point registers all tools with the Notion Worker runtime:This layer defines tool schemas and maps inputs to worker functions.
Workers Layer (src/workers/)
Workers Layer (src/workers/)
Workers orchestrate the entire operation:
- Validate input - Check required fields and allowed values
- Call shared logic - Use pure functions for transformations
- Execute Notion API calls - Read or write data via the client
- Return typed output - Structured success or error responses
Shared Layer (src/shared/)
Shared Layer (src/shared/)
Types Layer (src/shared/types.ts)
Types Layer (src/shared/types.ts)
Data Flow
Data flows unidirectionally through the system:Validation
Worker checks required fields and allowed values (e.g.,
VALID_AGENT_NAMES) and returns an error object if invalid.Notion Read (if needed)
For operations like
check-upstream-status or create-handoff-marker, the worker queries databases or blocks via the Notion client.Pure Logic
Shared modules parse status lines, build titles, build blocks, compute dates - all without I/O.
Notion Write (if needed)
Worker creates or updates pages/blocks (
write-agent-digest, create-handoff-marker).Worker Responsibilities
Each worker has a defined scope:| Worker | Reads from Notion | Writes to Notion | Shared Modules Used |
|---|---|---|---|
write-agent-digest | — | Docs or Home Docs | agent-config, status-parser, date-utils, block-builder |
check-upstream-status | Docs, Home Docs | — | agent-config, status-parser, date-utils |
create-handoff-marker | Docs (optional) | Tasks (optional) | agent-config, date-utils |
See the Workers Reference for detailed documentation on each worker’s inputs, outputs, and behavior.
Idempotency and Guards
write-agent-digest
write-agent-digest
Creates one page per call. Idempotency is the caller’s responsibility - typically one digest per agent per run.
check-upstream-status
check-upstream-status
Read-only operation. Inherently idempotent.
create-handoff-marker
create-handoff-marker
Implements two safety mechanisms:Circuit Breaker: Prevents duplicate handoffs for the same source→target within 7 days.Re-escalation Cap: Maximum of 2 escalations in the same direction within 7 days. After that, sets
needs_manual_review flag.Error Handling
The system follows a strict error handling pattern:Validation Errors
Return structured errors:
Notion API Errors
Catch in try/catch, return structured error:
Dependencies
The system relies on three core dependencies:- @notionhq/client — Notion API client
- @notionhq/workers — Worker runtime and registration (
Worker,.tool()) - date-fns — Date formatting and parsing (Chicago time, age checks)
process.env via src/shared/notion-client.ts.
Module System
The project uses ES Modules (ESM):Import paths require
.js extensions even when importing from .ts files due to the NodeNext module resolution.Next Steps
Agent System
Learn about the 11-agent system and digest patterns
Governance
Understand the rules and boundaries that keep the system safe
API Reference
Detailed documentation for each worker
Quick Start
Get started with your first integration