# Composition and bindings

## Principle

Composition remains explicit.

A pack never activates another pack because it happens to need something.

Instead:

```text
provider pack
    provides capability
        ↓
dryv.yaml pack activation bind
        ↓
consumer pack
    needs capability
```

Existing Dryv capability slots remain the model:

- `schema.types`
- `schema.validation`
- `schema.persistence`
- `property.enum.types`
- `operation.client`

The slot catalogue may evolve separately, but pack layout does not replace capability composition.

## Example graph

```text
TypeORM entities
  inject
  provides schema.persistence
         │
         ▼
NestJS backend
  project
  needs schema.persistence
         │

TypeScript API client
  package
  provides operation.client
         │
         ▼
Next.js frontend
  project
  needs operation.client
```

## Same-unit versus cross-unit binding

Same unit:

```text
apps/backend
├── NestJS project pack
├── TypeORM inject pack
└── validation inject pack
```

Cross unit:

```text
packages/api_client
└── API package pack
       provides operation.client
             │
             ▼
apps/web
└── Next.js project pack
       needs operation.client
```

Both should use the same `provides / needs / bind` mechanism.

The difference belongs to planning/addressing, not to a second dependency system.

## Pack-level binding context

Current `file.dependencies[]` is useful for artifact-specific dependencies.

Root/global project files sometimes need broader knowledge.

Example:

```text
apps/mobile/pubspec.yaml
```

needs to know that `operation.client` comes from Dart package `riderescue_api` even though `pubspec.yaml` is not a specific operation artifact.

Therefore the future template context likely needs a generic pack/unit binding view.

Conceptually:

```text
pack.bindings.operation_client.provider
pack.bindings.operation_client.unit
pack.bindings.operation_client.package
```

This must remain planning-derived and demand-driven.

It must not expose framework-specific facts such as:

```text
uses_zod
uses_dio
uses_next_api_bridge
```

## No nested composition

Do not allow:

```text
dryv.yaml
  → pack A
      → hidden dryv.yaml
          → pack B
          → pack C
```

The project must remain able to inspect every activated pack and binding in its own usage configuration.

Under the proposed Usage redesign, pack activations also reference shared `sources.packs` entries and typed `destinations.code` entries. This changes project wiring, not the `provides / needs / bind` capability model.

A starter/recipe can prepare that explicit configuration, but it cannot remain a hidden runtime layer.

## Capability binding versus action batching

Capability composition and command/action composition are separate concerns.

```text
needs / provides / bind
  -> which generated artifacts satisfy semantic capability slots

same destination + same action ID
  -> which generation-support actions may batch for one unit
```

For example, TypeORM and class-validator may both contribute an `install` action to the backend application. Those actions can batch without either pack providing a capability to the other.

Likewise a capability binding does not imply any command dependency or package-manager choice.

Both mechanisms meet only at the generated unit, where the Engine can explain:

- which packs provide/need capabilities;
- which packs contributed dependencies;
- which packs requested each action;
- which destination choice selected the concrete command.
