> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Base44 entities: Entities and the entity SDK (web apps)

> source commit is in /SOURCE_COMMIT at the repository root. Edits here are overwritten by

> [!WARNING]
>
> This page is part of an AI coding agent skill and is written for agents, not humans. For the human-readable Base44 docs, see the [developer documentation](https://docs.base44.com/developers).

# Base44 entities: Entities and the entity SDK (web apps)

Entities = JSON schema objects defining stored data. Built-in attributes on every record (never declare): id, created\_date, updated\_date, created\_by\_id.
Enum fields take `enumColors`, a list parallel to `enum` (green, yellow, red, blue, purple, pink, gray) that colors each option's badge in the Data table: an ordered scale runs green → yellow → red (easy → hard, low → high), a status follows its meaning (done green, failed red, draft gray), and plain categories get distinct colors.

\<deleting\_entities>
Delete records with the SDK (`delete` / `deleteMany`); the user can restore them from the app dashboard: Data → the table → Recently deleted. Deleting an entity's `base44/entities/<Name>.jsonc` file removes the entity itself.
\</deleting\_entities>
\<user\_entity>
User is built-in on every app — never create it. Read-only: id, created\_date, full\_name, email. Editable: role (defaults 'admin'/'user'; freely change values by editing base44/entities/User.jsonc, declaring only customized fields). Built-in security: only admins list/update/delete other users. Don't add custom User RLS unless explicitly asked. You cannot insert User records — users join via invites; say so if asked.
\</user\_entity>

\<field\_limits>
Never store large content (base64, PDFs, blobs) in entity fields — upload via UploadPrivateFile for anything an end user uploads, store the returned file\_uri; oversized fields break record operations.
\</field\_limits>

\<entities\_sdk>
Entities SDK on the pre-initialized base44 client; each entity is base44.entities.EntityName. The server filters, counts and sums, not JS on loaded records: a list on screen is one page with a "load more"; a number is count; totals per group or a chart is aggregate; a filter or search box is a new filter() call.

```js theme={null}
import { base44 } from '@/api/base44Client';

base44.entities.Todo.filter({status: 'open', priority: {$in: ['high', 'urgent']}}, {sort: '-created_date', limit: 50})  // → {items, next_cursor, has_more}: with options it returns a page, read .items. Load more: the same call with cursor: page.next_cursor. Operators: $in/$nin/$gt/$gte/$lt/$lte/$ne/$exists/$or, $regex for text search. Same options on list({sort, limit, cursor})
base44.entities.Todo.count({status: 'open'})  // a number: totals, badges, "N of M"
base44.entities.Todo.aggregate({query: {status: 'done'}, groupBy: 'owner', sum: ['amount']})  // {rows: [{owner, count, sum_amount}]}; also avg/min/max and dateBucket: {field: 'created_date', unit: 'day'|'week'|'month'}. One call covers all counters of an entity
base44.entities.Todo.list({distinct: 'category'})  // dropdown values: {items: values}
// An entity with field-level read rules rejects aggregate and distinct (400): use count and a filter page there
base44.entities.Todo.create({title: "Todo 1"})
base44.entities.Todo.bulkCreate([{title: "Todo 2"}, {title: "Todo 3"}])
base44.entities.Todo.update(todo.id, {description: "new"})
base44.entities.Todo.updateMany({status: "active"}, {$set: {status: "done"}})  // same change to all matches; up to 500 records, returns has_more=true if remains — call again for the next batch, but your $set must change a field in the query or the same rows re-match forever. 2nd arg uses MongoDB update operators (not a plain {field: value}): $set, $rename, $unset, $inc, $mul, $min, $max, $currentDate, $addToSet, $push, $pull. careful: no schema validation
base44.entities.Todo.bulkUpdate([{id: id1, status: "done"}, {id: id2, status: "open"}])  // different change per record, up to 500 records
base44.entities.Todo.delete(todo.id)
base44.entities.Todo.deleteMany({status: "archived"})  // deletes all matches in one call. careful: a broad or empty ({}) query deletes everything it's allowed to
```

\<user\_and\_auth>
Built-in User entity uses the same SDK for reads (await base44.entities.User.list(), …), but User records can't be created or imported (create returns 405) — invite users with `base44.users.inviteUser(email, role)`. count, aggregate and the cursor form are not available on User. Auth SDK:

* await base44.auth.me() — current user; can throw if not logged in on a public app.
* await base44.auth.updateMe(data) — persist extra data on the current user (returned by later me()); built-ins (id, email, full\_name, role) can't be overridden.
* base44.auth.isAuthenticated() — Promise\<boolean>.
* base44.auth.logout(redirectUrl?: string) — then redirect to redirectUrl, or reload.
* base44.auth.redirectToLogin(nextUrl?: string) — app login page; after login → nextUrl, else the triggering page.
  \</user\_and\_auth>

\<realtime\_subscriptions>

```js theme={null}
useEffect(() => {
  // event: { id, type: 'create'|'update'|'delete', data }
  const unsubscribe = base44.entities.Todo.subscribe((event) => { /* update state from event */ });
  return unsubscribe;
}, []);
```

\</realtime\_subscriptions>
\</entities\_sdk>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.