# How a project flows through Dryv

```mermaid
flowchart LR
    A["Author<br/>TypeScript or Python"] -->|compile| B["Canonical<br/>Runtime IR"]
    B -->|stream| C["Dryv Engine<br/>validate + plan"]
    P["Packs<br/>dryv.yaml"] --> C
    C -->|render| D["Template servers"]
    D --> E["Plan + diff<br/>+ trace"]
    E -->|you approve| F["Generated files"]
```

1. **Author.** You describe schemas, operations, events, policies and apps with the author
   library, in TypeScript or Python.
2. **Compile.** The client runs your project's compiler (`dryv-ts` or `dryv-py`). The
   compiler turns the declarations into **Canonical Runtime IR**, the single source of meaning.
3. **Validate and plan.** The client streams the IR to the engine. The engine validates it,
   loads the packs listed in `dryv.yaml`, and plans every file: which template, which
   subject, which path, and what it depends on.
4. **Render.** Template servers render each planned file. The engine returns the files and
   a trace that explains why each one exists.
5. **Apply.** The client shows the diff and writes files only when you approve.

Your source code never leaves your machine, only the compiled IR does. The engine never
writes to your workspace. The client does.

## 1. Author

TypeScript, in `dryv/contracts/index.ts`:

```ts
import { dryv, property } from "@dryvcode/author";

const shop = dryv.group({ name: "shop" });

export const shopProperties = shop.properties({
  Id: property.string.uuid(),
  Name: property.string(),
  Price: property.number.money({ minorUnits: true, currency: "USD" }),
});

export default dryv.app({ name: "shop" }).groups(shop);
```

Python uses the same concepts with Pythonic names: `type: python` and a Python
entrypoint such as `app.py`.

## 2. Configure: dryv.yaml

```yaml
version: dryv/v1alpha1

sources:
  authoring:
    main:
      type: typescript # or python
      path: dryv/contracts
      entrypoint: index.ts
  packs:
    official:
      repository: https://github.com/dryvcode/packs
      ref: <commit> # written for you by `dryv pack add`
      root: packs

packs:
  entities:
    source:
      $ref: "#/sources/packs/official"
      path: inject/persistence/typeorm-entities
    destination: { $ref: "#/destinations/entities" }

destinations:
  ir:
    main: { path: dryv/ir }
  entities:
    path: src/generated/entities

authoring:
  source: { $ref: "#/sources/authoring/main" }
  destination: { $ref: "#/destinations/ir/main" }
```

You rarely write the pack source by hand: `dryv pack add <id>` does it. See [Find and use packs](/docs/usage/packs) and [dryv.yaml](/docs/usage/dryv-yaml).

## 3. Run

| Command                   | What it does                                                                    | Writes files?       |
| ------------------------- | ------------------------------------------------------------------------------- | ------------------- |
| `dryv build`              | Compiles authored source and writes configured Runtime IR YAML/JSON/JSONL files | yes                 |
| `dryv validate`           | Compiles and validates against the engine                                       | no                  |
| `dryv plan`               | Shows every planned file, its template and its path                             | no                  |
| `dryv generate --dry-run` | Renders and shows the diff                                                      | no                  |
| `dryv generate`           | Renders, shows the diff and asks before writing                                 | yes, after approval |
| `dryv generate --check`   | Fails when the generated files are out of date (for CI)                         | no                  |

Every command takes `--api <url>`, or reads `DRYV_API_URL`.

## Where to go next

- [Installation](/docs/usage/installation)
- [Authoring](/docs/concepts/authoring)
- [Packs & templating](/docs/concepts/packs)
- [Planning & explainability](/docs/concepts/planning)
