# What is Maryk?

Canonical: https://maryk.io/what/
Source: https://github.com/marykdb/maryk/blob/main/website/src/content/docs/what.mdx

Maryk is a Kotlin Multiplatform data toolkit built around one idea: the data model should be the contract.

You define the model once in Kotlin. Maryk uses it to validate values, serialize values, build typed requests, execute those requests against stores, retain history, stream updates, and drive tooling.

```mermaid
flowchart TB
    accTitle: One model connects the data layers
    accDescr: A Kotlin model defines validation, serialization, requests and tooling. Stores execute the typed requests.
    Model["Kotlin data model"] --> Values["Create and validate values"]
    Model --> Serialization["JSON, YAML and ProtoBuf"]
    Model --> Requests["Typed requests"]
    Model --> Tools["App, CLI and generators"]
    Requests --> Stores["Memory, IndexedDB, RocksDB, FoundationDB or Remote"]
```

## The pieces

| Layer         | Role                                                                                                                        |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- |
| Data models   | define properties, indexes, validations, keys, and references.                                                              |
| Values        | are typed records created and validated through those models.                                                               |
| Requests      | describe add/change/delete/get/scan/history/update operations, atomic change sets and serializable transaction journals.    |
| SQL           | provides optional bounded queries, joins, reporting and mutations over those same models and requests.                      |
| Stores        | execute requests through one API: Memory, IndexedDB, RocksDB, FoundationDB, Remote.                                         |
| Serialization | writes the same values and requests as YAML, JSON, or ProtoBuf.                                                             |
| Tools         | let you inspect and edit records through the [CLI](https://maryk.io/cli/index.md) and [App](https://maryk.io/app/index.md). |

## A tiny taste

```kotlin
object Person : RootDataModel<Person>() {
  val firstName by string(index = 1u)
  val lastName by string(index = 2u)
}


val john = Person.create { firstName with "John"; lastName with "Smith" }
Person.validate(john) // throws if invalid
```

## Why the model matters

Maryk uses stable property indexes. This makes serialization compact and lets readers skip unknown fields. That is the basis for safe evolution, cross-platform compatibility, and history-aware storage.

Maryk also treats queries as typed request objects. Those requests can run locally, be serialized, be sent to a remote store, or be watched as update streams.

## When Maryk fits

- Multi-client apps that need one shared data contract.
- Local-first apps that need embedded persistence and sync.
- Kotlin backends that want typed operational storage and compact transport.
- Tools that need to read, validate, export, import, or edit structured records.
- Systems that benefit from historic reads, update streams, or incremental sync.

## Next steps

- Quick setup: [Getting Started](https://maryk.io/getting-started/index.md)
- Complete tutorial: [First Store Tutorial](https://maryk.io/tutorials/first-store/index.md)
- Model design: [Data Design](https://maryk.io/data-modeling/data-design/index.md)
- Existing data: [Changing Models Safely](https://maryk.io/guides/change-models-safely/index.md)
- Fit and comparisons: [Tradeoffs](https://maryk.io/tradeoffs/index.md)
