# `PhoenixKit.Modules.Entities.Mirror.Exporter`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L1)

Exports entities and their data to JSON files.

Each entity is exported as a single file containing:
- The entity definition (schema)
- All data records for that entity (when data mirroring is enabled)

## File Format

    {
      "export_version": "1.0",
      "exported_at": "2025-12-11T10:30:00Z",
      "definition": {
        "name": "brand",
        "display_name": "Brand",
        ...
      },
      "data": [
        {"title": "Acme Corp", "slug": "acme-corp", ...},
        {"title": "Globex", "slug": "globex", ...}
      ]
    }

# `export_all`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L123)

```elixir
@spec export_all() ::
  {:ok, %{definitions: non_neg_integer(), data: non_neg_integer()}}
```

Exports all entities with their data (full export).

Returns definition count and data record count.

# `export_all_data`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L105)

```elixir
@spec export_all_data() :: {:ok, [result]}
when result: {:ok, String.t()} | {:error, term()}
```

Exports all data for all entities.

Re-exports each entity file with its data included.

# `export_all_entities`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L88)

```elixir
@spec export_all_entities() :: {:ok, [result]}
when result: {:ok, String.t()} | {:error, term()}
```

Exports all entities (definitions only, no data).

# `export_entity`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L51)

```elixir
@spec export_entity(struct() | String.t()) ::
  {:ok, String.t(), :with_data | :definition_only} | {:error, term()}
```

Exports a single entity with its definition and optionally data.

## Parameters
  - `entity` - Entity struct or entity name string

## Returns
  - `{:ok, file_path}` on success
  - `{:error, reason}` on failure

# `export_entity_data`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L77)

```elixir
@spec export_entity_data(struct()) :: {:ok, String.t()} | {:error, term()}
```

Exports a single entity data record.

This re-exports the entire entity file with updated data.

# `serialize_entity`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L149)

```elixir
@spec serialize_entity(struct()) :: map()
```

Serializes an entity struct to a map suitable for JSON export.

# `serialize_entity_data`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.65/lib/modules/entities/mirror/exporter.ex#L168)

```elixir
@spec serialize_entity_data(struct()) :: map()
```

Serializes an entity data record to a map suitable for JSON export.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
