# cordiverse/cordis architecture

> Architecture diagram of the GitHub repository cordiverse/cordis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cordiverse/cordis
- Repository: https://github.com/cordiverse/cordis

## Overview

#### Purpose and Package Topology
Cordis is a TypeScript monorepo implementing a meta-framework for spatiotemporal composability: scoped service contexts, plugin lifecycles, eventing, dependency association, and runtime reconfiguration. The primary public runtime is `@cordisjs/core` at `packages/core/src/index.ts`; surrounding packages add configuration loading, HMR, scoped grouping, timers, logging, and project creation.

#### Core Context and Service Runtime
The central execution model is the context/service graph:
- `packages/core/src/context.ts` defines scoped contexts and their composition/isolation boundaries.
- `packages/core/src/service.ts` manages service provisioning, lookup, lifecycle, and dependency-facing behavior.
- `packages/core/src/registry.ts` maintains registrations and associations.
- `packages/core/src/index.ts` exports the public framework API.

Plugins and services are attached to contexts rather than a global container, enabling localized capabilities and disposal.

#### Plugin Lifecycle, Fibers, and Disposal
Plugin invocation and teardown are coordinated through:
- `packages/core/src/fiber.ts` for lifecycle/disposable execution units.
- `packages/core/src/context.ts` for context-owned plugin application and cleanup.
- `packages/core/src/reflect.ts` for metadata/reflection used in association and injection-like behavior.

This establishes ownership boundaries: disposing a context or fiber should clean up work and services created beneath it without requiring application-wide shutdown.

#### Event and Logging Boundary
Core provides runtime observability and communication:
- `packages/core/src/events.ts` implements context/event dispatch semantics.
- `packages/core/src/logger.ts` defines framework logging facilities.
- `packages/logger-console/src/index.ts` provides a console-backed logger integration, with browser-specific support in `packages/logger-console/src/browser.ts`.

Events decouple producers from scoped consumers; logging is an adapter boundary so core does not depend on a specific output target.

#### Declarative Loading and Configuration Graphs
`@cordisjs/loader` turns configuration into a context/plugin topology:
- `packages/loader/src/index.ts` is the loader entry point.
- `packages/loader/src/config/tree.ts` models hierarchical configuration.
- `packages/loader/src/config/group.ts` and `packages/loader/src/config/isolate.ts` represent group and isolation boundaries.
- `packages/loader/src/internal.ts` contains loader-runtime integration.

The loader is the principal bridge from declarative configuration to imperative core context/plugin creation.

#### Runtime Reconfiguration Extensions
Several packages modify or extend active compositions:
- `packages/hmr/src/index.ts` supplies hot-module/plugin reload behavior; `packages/hmr/src/error.ts` handles reload failures.
- `packages/include/src/index.ts` supports inclusion/patching of configuration or plugin sources.
- `packages/group/src/index.ts` provides grouping semantics compatible with the scoped composition model.
- `packages/timer/src/index.ts` adds time-based execution primitives.

HMR is an important control-flow boundary: replacement must coordinate with core lifecycle disposal and error reporting rather than simply re-import code.

#### Entrypoints and Execution Environment
The repository targets Node.js/TypeScript package consumers, with browser support specifically represented by the console logger adapter. CLI entrypoints are:
- `packages/core/bin.js` for the core package executable.
- `packages/create/src/bin.ts` for project scaffolding.
- `packages/create/src/index.ts` for the create-package implementation.

Build/test automation is GitHub Actions-based (`.github/workflows/build.yml`), while package orchestration is defined at the monorepo root (`package.json`, `yakumo.yml`). No application server, database, or external hosted service is present in the repository.

Main entry points: [`packages/core/src/context.ts`](https://github.com/cordiverse/cordis/blob/main/packages/core/src/context.ts) (Scoped Contexts), [`packages/hmr/src/index.ts`](https://github.com/cordiverse/cordis/blob/main/packages/hmr/src/index.ts) (Hot Reload), [`packages/core/src/service.ts`](https://github.com/cordiverse/cordis/blob/main/packages/core/src/service.ts) (Service Runtime), [`packages/loader/src/internal.ts`](https://github.com/cordiverse/cordis/blob/main/packages/loader/src/internal.ts) (Loader Runtime Bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core Runtime"]
  node_core_api["Core Public API<br/>package entrypoint<br/>[index.ts]"]
  node_context["Scoped Contexts<br/>runtime boundary<br/>[context.ts]"]
  node_service["Service Runtime<br/>service container<br/>[service.ts]"]
  node_registry[("Service Registry<br/>registration graph<br/>[registry.ts]")]
  node_fiber["Lifecycle Fibers<br/>disposable unit<br/>[fiber.ts]"]
  node_reflect["Reflection Metadata<br/>[reflect.ts]"]
  node_events["Scoped Events<br/>event runtime<br/>[events.ts]"]
  node_core_logger["Logger Interface<br/>logging boundary<br/>[logger.ts]"]
end

subgraph group_loader["Declarative Loading"]
  node_loader_api["Loader Entrypoint<br/>package entrypoint<br/>[index.ts]"]
  node_config_tree["Configuration Tree<br/>config model<br/>[tree.ts]"]
  node_config_boundaries["Group &amp; Isolate Config<br/>config boundaries<br/>[group.ts]"]
  node_loader_runtime["Loader Runtime Bridge<br/>core integration<br/>[internal.ts]"]
end

subgraph group_extensions["Runtime Extensions"]
  node_hmr["Hot Reload<br/>runtime extension<br/>[index.ts]"]
  node_hmr_errors["Reload Errors<br/>error handling<br/>[error.ts]"]
  node_include["Include &amp; Patch<br/>runtime extension<br/>[index.ts]"]
  node_group["Scoped Grouping<br/>runtime extension<br/>[index.ts]"]
  node_timer["Timers<br/>runtime extension<br/>[index.ts]"]
  node_console_logger["Console Logger<br/>logging adapter<br/>[index.ts]"]
end

subgraph group_tooling["Tooling"]
  node_core_cli["Core CLI<br/>executable<br/>[bin.js]"]
  node_create_cli["Create CLI<br/>scaffolding executable<br/>[bin.ts]"]
  node_create["Project Creator<br/>scaffolding implementation<br/>[index.ts]"]
end

node_core_api -->|"exports"| node_context
node_context -->|"owns scoped services"| node_service
node_service -->|"registers and associates"| node_registry
node_service -->|"uses metadata"| node_reflect
node_context -->|"applies and disposes plugins"| node_fiber
node_context -->|"dispatches scoped events"| node_events
node_context -->|"uses logging boundary"| node_core_logger
node_loader_api -->|"loads"| node_config_tree
node_config_tree -->|"contains"| node_config_boundaries
node_loader_api -->|"delegates to"| node_loader_runtime
node_loader_runtime -->|"creates compositions"| node_context
node_loader_runtime -->|"applies plugins"| node_fiber
node_hmr -->|"replaces compositions"| node_context
node_hmr -->|"coordinates disposal"| node_fiber
node_hmr -->|"reports failures"| node_hmr_errors
node_include -->|"extends sources"| node_loader_api
node_group -->|"adds grouping semantics"| node_context
node_timer -->|"adds scheduled work"| node_context
node_console_logger -->|"implements"| node_core_logger
node_core_cli -->|"invokes"| node_core_api
node_create_cli -->|"invokes"| node_create

click node_core_api "https://github.com/cordiverse/cordis/blob/main/packages/core/src/index.ts"
click node_context "https://github.com/cordiverse/cordis/blob/main/packages/core/src/context.ts"
click node_service "https://github.com/cordiverse/cordis/blob/main/packages/core/src/service.ts"
click node_registry "https://github.com/cordiverse/cordis/blob/main/packages/core/src/registry.ts"
click node_fiber "https://github.com/cordiverse/cordis/blob/main/packages/core/src/fiber.ts"
click node_reflect "https://github.com/cordiverse/cordis/blob/main/packages/core/src/reflect.ts"
click node_events "https://github.com/cordiverse/cordis/blob/main/packages/core/src/events.ts"
click node_core_logger "https://github.com/cordiverse/cordis/blob/main/packages/core/src/logger.ts"
click node_loader_api "https://github.com/cordiverse/cordis/blob/main/packages/loader/src/index.ts"
click node_config_tree "https://github.com/cordiverse/cordis/blob/main/packages/loader/src/config/tree.ts"
click node_config_boundaries "https://github.com/cordiverse/cordis/blob/main/packages/loader/src/config/group.ts"
click node_loader_runtime "https://github.com/cordiverse/cordis/blob/main/packages/loader/src/internal.ts"
click node_hmr "https://github.com/cordiverse/cordis/blob/main/packages/hmr/src/index.ts"
click node_hmr_errors "https://github.com/cordiverse/cordis/blob/main/packages/hmr/src/error.ts"
click node_include "https://github.com/cordiverse/cordis/blob/main/packages/include/src/index.ts"
click node_group "https://github.com/cordiverse/cordis/blob/main/packages/group/src/index.ts"
click node_timer "https://github.com/cordiverse/cordis/blob/main/packages/timer/src/index.ts"
click node_console_logger "https://github.com/cordiverse/cordis/blob/main/packages/logger-console/src/index.ts"
click node_core_cli "https://github.com/cordiverse/cordis/blob/main/packages/core/bin.js"
click node_create_cli "https://github.com/cordiverse/cordis/blob/main/packages/create/src/bin.ts"
click node_create "https://github.com/cordiverse/cordis/blob/main/packages/create/src/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_api,node_context,node_service,node_registry,node_fiber,node_reflect,node_events,node_core_logger toneBlue
class node_loader_api,node_config_tree,node_config_boundaries,node_loader_runtime toneAmber
class node_hmr,node_hmr_errors,node_include,node_group,node_timer,node_console_logger toneMint
class node_core_cli,node_create_cli,node_create toneRose
```

## Components

### Core Runtime

Scoped composition and lifecycle primitives.

- [Core Public API](https://github.com/cordiverse/cordis/blob/main/packages/core/src/index.ts): package entrypoint · `packages/core/src/index.ts`
- [Scoped Contexts](https://github.com/cordiverse/cordis/blob/main/packages/core/src/context.ts): runtime boundary · Owns localized capabilities, plugins, and cleanup. · `packages/core/src/context.ts`
- [Service Runtime](https://github.com/cordiverse/cordis/blob/main/packages/core/src/service.ts): service container · Provides lookup and lifecycle behavior for scoped services. · `packages/core/src/service.ts`
- [Service Registry](https://github.com/cordiverse/cordis/blob/main/packages/core/src/registry.ts): registration graph · `packages/core/src/registry.ts`
- [Lifecycle Fibers](https://github.com/cordiverse/cordis/blob/main/packages/core/src/fiber.ts): disposable unit · Coordinates plugin execution and teardown. · `packages/core/src/fiber.ts`
- [Reflection Metadata](https://github.com/cordiverse/cordis/blob/main/packages/core/src/reflect.ts): metadata · Supports service association and injection-like behavior. · `packages/core/src/reflect.ts`
- [Scoped Events](https://github.com/cordiverse/cordis/blob/main/packages/core/src/events.ts): event runtime · `packages/core/src/events.ts`
- [Logger Interface](https://github.com/cordiverse/cordis/blob/main/packages/core/src/logger.ts): logging boundary · Keeps core independent of output targets. · `packages/core/src/logger.ts`

### Declarative Loading

Configuration-to-runtime composition.

- [Loader Entrypoint](https://github.com/cordiverse/cordis/blob/main/packages/loader/src/index.ts): package entrypoint · `packages/loader/src/index.ts`
- [Configuration Tree](https://github.com/cordiverse/cordis/blob/main/packages/loader/src/config/tree.ts): config model · Models hierarchical declarative composition. · `packages/loader/src/config/tree.ts`
- [Group & Isolate Config](https://github.com/cordiverse/cordis/blob/main/packages/loader/src/config/group.ts): config boundaries · Represents grouping and isolation declarations. · `packages/loader/src/config/group.ts`
- [Loader Runtime Bridge](https://github.com/cordiverse/cordis/blob/main/packages/loader/src/internal.ts): core integration · Materializes configuration as contexts and plugins. · `packages/loader/src/internal.ts`

### Runtime Extensions

Packages that augment active compositions.

- [Hot Reload](https://github.com/cordiverse/cordis/blob/main/packages/hmr/src/index.ts): runtime extension · Replaces active plugins while coordinating disposal. · `packages/hmr/src/index.ts`
- [Reload Errors](https://github.com/cordiverse/cordis/blob/main/packages/hmr/src/error.ts): error handling · `packages/hmr/src/error.ts`
- [Include & Patch](https://github.com/cordiverse/cordis/blob/main/packages/include/src/index.ts): runtime extension · Includes or patches configuration and plugin sources. · `packages/include/src/index.ts`
- [Scoped Grouping](https://github.com/cordiverse/cordis/blob/main/packages/group/src/index.ts): runtime extension · `packages/group/src/index.ts`
- [Timers](https://github.com/cordiverse/cordis/blob/main/packages/timer/src/index.ts): runtime extension · Adds time-based execution primitives. · `packages/timer/src/index.ts`
- [Console Logger](https://github.com/cordiverse/cordis/blob/main/packages/logger-console/src/index.ts): logging adapter · Console-backed logger with browser support. · `packages/logger-console/src/index.ts`

### Tooling

CLI and project scaffolding.

- [Core CLI](https://github.com/cordiverse/cordis/blob/main/packages/core/bin.js): executable · `packages/core/bin.js`
- [Create CLI](https://github.com/cordiverse/cordis/blob/main/packages/create/src/bin.ts): scaffolding executable · `packages/create/src/bin.ts`
- [Project Creator](https://github.com/cordiverse/cordis/blob/main/packages/create/src/index.ts): scaffolding implementation · `packages/create/src/index.ts`

## Connections

- Core Public API → Scoped Contexts: exports
- Scoped Contexts → Service Runtime: owns scoped services
- Service Runtime → Service Registry: registers and associates
- Service Runtime → Reflection Metadata: uses metadata
- Scoped Contexts → Lifecycle Fibers: applies and disposes plugins
- Scoped Contexts → Scoped Events: dispatches scoped events
- Scoped Contexts → Logger Interface: uses logging boundary
- Loader Entrypoint → Configuration Tree: loads
- Configuration Tree → Group & Isolate Config: contains
- Loader Entrypoint → Loader Runtime Bridge: delegates to
- Loader Runtime Bridge → Scoped Contexts: creates compositions
- Loader Runtime Bridge → Lifecycle Fibers: applies plugins
- Hot Reload → Scoped Contexts: replaces compositions
- Hot Reload → Lifecycle Fibers: coordinates disposal
- Hot Reload → Reload Errors: reports failures
- Include & Patch → Loader Entrypoint: extends sources
- Scoped Grouping → Scoped Contexts: adds grouping semantics
- Timers → Scoped Contexts: adds scheduled work
- Console Logger → Logger Interface: implements
- Core CLI → Core Public API: invokes
- Create CLI → Project Creator: invokes
