Backend
Backend overview
The components in this library are only half of a product: a LoginForm needs an account system, a DataTable needs a paginated endpoint, a Composer needs a model that streams. The Backend section documents three packages that provide that other half, designed together so that the props a component takes are exactly what the API returns.
| Package | Language | What it is |
|---|---|---|
| pleate-backend | Python | Reusable Django 6.1 apps with Django REST Framework and an OpenAPI schema, on MongoDB. |
| pleate-client | TypeScript | A typed fetch client, Server-Sent Events, list helpers and React hooks that return props for pleate components. |
| apps/backend-demo | Python | An example Django project wired with every app, plus a Product resource that shows how to add your own. |
How a request travels
Take the login screen. LoginForm calls onSubmit, which comes from useLogin().loginFormProps. The hook calls client.auth.login(), which fetches a CSRF cookie if needed and posts JSON to /api/auth/login. Django checks the rate limits, the password and the 2FA state, writes the session to MongoDB and answers either the user or {mfa_required: true}. The hook flips to the second step and the page renders TwoFactorForm with twoFactorFormProps. Errors come back in one format, so the same hook can put field messages under the right inputs.
pleate component
Your Next.js app
<LoginForm>, <DataTable>, <Composer>…
Hook
pleate-client/react
useLogin(), useList(), useChat()…
Client
pleate-client
createPleateClient(): CSRF, errors, SSE, uploads
REST API
HTTP, same origin
/api/auth, /api/files, /api/ai… JSON and SSE
Django app
pleate-backend
pleate_backend.accounts, .files, .ai_chat…
MongoDB
Replica set
django-mongodb-backend, GridFS for files
"use client";
import { LoginForm } from "pleate/auth/login-form";
import { TwoFactorForm } from "pleate/auth/two-factor-form";
import { useLogin } from "pleate-client/react";
export default function Login() {
const login = useLogin({ onSuccess: () => location.assign("/") });
return login.mfaRequired
? <TwoFactorForm {...login.twoFactorFormProps} />
: <LoginForm {...login.loginFormProps} />;
}The apps
Each feature is its own Django app, mounted under its own prefix by pleate_backend.urls. Remove an app from INSTALLED_APPS and its routes, its /auth/me fields and its section of the data export disappear with it.
| App | Prefix | Backs |
|---|---|---|
| core | /api | Health, CSRF, errors, pagination, filters, realtime, cache, tasks |
| accounts | /api/auth | LoginForm, SignupForm, ForgotPasswordForm, ResetPasswordForm, SessionList |
| mfa | /api/auth/mfa | TwoFactorForm, TwoFactorSetup |
| oauth | /api/auth/oauth | OAuthButtons |
| rbac | /api/rbac | Roles, object permissions, feature flags |
| apikeys | /api/api-keys | ApiKeyList |
| files | /api/files | FileUpload |
| notifications | /api/notifications | NotificationBell, NotificationCenter |
| emails | Transactional emails for every other app | |
| audit | /api/activity | Timeline, DataTable of activity |
| ratelimit | Throttles and RateLimit headers | |
| webhooks | /api/webhooks | Outgoing and incoming webhooks |
| ai_chat | /api/ai | ChatThread, Composer, ModelPicker, PromptSuggestions, Reasoning |
| marketing | /api/marketing | Newsletter, ContactForm, waitlist |
| billing | /api/billing | Pricing |
| staff | /api/staff | Back office tables and StatCard |
| usage | /api/usage | UsageMeter |
| search | /api/search | CommandPalette |
Why Django on MongoDB
The backend uses django-mongodb-backend, the official MongoDB backend for the Django ORM, instead of talking to MongoDB through PyMongo or an ODM such as MongoEngine. The choice is about what comes for free:
- The Django ORM. Models, migrations, querysets,
select_related, signals and transactions, the API every Django developer already knows. Your own models sit next to pleate's and can point at itsUserwith a plainForeignKey. - Django auth. Password hashing (Argon2), permissions, groups, sessions and
authenticate()work unchanged, so roles and object permissions build on them instead of reinventing them. - The admin. Every app registers its models, so staff can browse users, files, bans or webhook deliveries on day one.
- Django REST Framework and OpenAPI. Serializers, permissions, throttles, filters and drf-spectacular all need the ORM. The OpenAPI schema is what generates the TypeScript types of pleate-client.
- The ecosystem. django-filter, django-storages, django-anymail and Celery plug in as they do on PostgreSQL. With PyMongo or MongoEngine each of these would need its own glue.