Where can I see if my routes are properly compiled for the frontend? β
The racletteJS backend will, during startup, create a config file based on your plugins route configs. You can easily find that file in your plugin folder at ./plugins/YOURPLUGIN/frontend/generated-config.ts.
When the file changes: in development, generated-config.ts is rewritten on each backend server start (including restarts triggered by hot reload). In a production build, it is generated once at build time; a deployed app does not mutate this file at runtime.
How to define routes
import type { Static } from "@sinclair/typebox"
import type { FastifyReply, FastifyRequest } from "fastify"
import { Type } from "@sinclair/typebox"
import type { PluginFastifyInstance } from "@raclettejs/types"
const ParamsSchema = Type.Object({
_id: Type.String(),
})
type Params = Static<typeof ParamsSchema>
export default (fastify: PluginFastifyInstance) => {
const handler = async (
req: FastifyRequest<{
Params: Params
}>,
reply: FastifyReply,
) => {
try {
/* YOUR BUSINESS LOGIC */
} catch (err: any) {
fastify.log.error(err.message)
return reply.internalServerError(err.message)
}
}
return {
handler,
onRequest: [fastify.authenticate],
config: {
type: dataUpdate,
broadcastChannels: ["exampleUpdated"],
},
schema: {
summary: "Example example get Route",
description: "Example example get Route",
tags: ["myApp/example"],
body: exampleBaseSchema,
},
}
}What does that tell me? β
This is an auto-generated plugin configuration produced by the backend.
It describes how a plugin communicates with the API, how data operations behave, and which real-time channels are emitted per operation.
π§ Core Concept β
Each plugin exposes:
- metadata (plugin identity + routing)
- entities (e.g.
todo) - operations (CRUD + custom actions)
- channels (real-time events emitted per operation)
π¦ Top-Level Plugin Metadata β
pluginName: string
author: string
pluginKey: string
routePrefix: string
pluginPath: stringMeaning β
pluginNameβ human-readable name of the pluginauthorβ plugin namespace ownerpluginKeyβ unique identifier used across frontend systemsroutePrefixβ base API route for all operationspluginPathβ internal filesystem path reference
π§© Data Section β
data: {
[entity]: {
type: string
operations: Record<string, Operation>
}
}Example:
data.todoRepresents a domain entity (e.g. todos, users, posts).
βοΈ Operation Structure β
Each operation defines how the frontend interacts with the backend.
operation: {
target: string | (payload) => string
method: "get" | "post" | "patch" | "delete"
storeActionType: string
channels?: Channel[]
}π‘ Operation Types β
1. Read Operations β
getAll β
target: "/todo/all"
method: "get"
storeActionType: "dataRead"- Fetches full collection
- No channels emitted
get β
target: (payload) => `/todo/${payload._id}`
method: "get"
storeActionType: "dataRead"- Fetches single entity by ID
- Dynamic route based on payload
2. Write Operations β
create β
method: "post"
storeActionType: "dataCreate"- Creates new entity
- Emits real-time channels
update β
method: "patch"
storeActionType: "dataUpdate"- Updates existing entity
- Emits update channels
delete β
method: "delete"
storeActionType: "dataDelete"- Deletes entity
- Emits delete channels
π§© Custom Operations β
Example:
updateCheckTask
deleteHard- Functionally identical to standard operations
- Just custom backend endpoints
- Fully integrated into
$data
π‘ Channels (Real-time Events) β
Operations may define channels:
channels: [
{
channel: "pacifico__example-todo--todoCreated",
channelKey: "todoCreated",
prefix: "pacifico__example-todo"
}
]Channel Fields β
channel β
- Full backend-emitted event name
- Scoped to plugin + entity + operation
channelKey β
- Normalized frontend event name
- Used in
$socket.on(...)
prefix β
Namespace grouping
Helps distinguish:
- plugin-specific events
- global broadcast events
π Channel Behavior Model β
After a successful operation:
- Backend executes API call
- Backend emits channel event(s)
- Frontend receives via
$socket - UI reacts (refresh, update store, notify)
π§ Key Takeaways β
This config is fully backend-generated
It defines:
- API endpoints (
target) - HTTP behavior (
method) - store integration (
storeActionType) - real-time sync (
channels)
- API endpoints (
Operations are automatically exposed to
$dataChannels are automatically consumable via
$socket
β οΈ Important Rule β
Do not modify manually
It is the single source of truth for:
- API structure
- frontend data operations
- real-time events