Skip to Content
Getting StartedAdd Your First Entity

Add Your First Entity

What are entities?

An entity is a data model — think of it as a database table. You define the shape of your data (fields and types), and Myco gives you a full API to create, read, update, and delete records.

For example, a “Task” entity might have fields like title (string), completed (boolean), and priority (string).

Create an entity

From inside your app directory, run:

myco entity create \ --name "Task" \ --slug task \ --schema '{"properties":{"title":{"type":"string"},"completed":{"type":"boolean"},"priority":{"type":"string"}}}'

Required flags

FlagDescription
--nameDisplay name (e.g., “Task”)
--slugURL-safe identifier (e.g., task)

Optional flags

FlagDefaultDescription
--descriptionEntity description
--schema{}JSON schema defining fields
--scopeworkspaceworkspace (shared) or user (per-user)

Schema format

The schema uses a simple JSON format:

{ "properties": { "title": { "type": "string" }, "count": { "type": "number" }, "active": { "type": "boolean" }, "status": { "type": "string" } } }

Supported field types: string, number, boolean.

Generated types

After creating an entity, the CLI automatically generates TypeScript types at src/types/myco.generated.ts. This file maps your entity slugs to their field types:

// DO NOT EDIT — auto-generated by `myco entity typegen` export interface Task { title: string; completed: boolean; priority: string; } export interface EntityTypes { task: Task; }

Never edit myco.generated.ts by hand. If you change an entity’s schema, run myco entity typegen to regenerate it.

Use the data in your app

Now you can use the SDK to read and write records. Here’s a quick example:

import { useMyco } from "@myco-dev/sdk"; import type { EntityTypes } from "@/types/myco.generated"; function TaskList() { const myco = useMyco<EntityTypes>(); const { data: tasks, isPending } = myco.data.useRecords("task"); if (isPending) return <div>Loading...</div>; return ( <ul> {tasks?.map(task => ( <li key={task._id}>{task.title}</li> ))} </ul> ); }

See the Entities and Data guide for the full API.

Next step