Golden Path β Plugin index.ts β
For every plugin that has a backend folder, raclette loads exactly one file: backend/index.ts (or the path configured in your plugin manifest). That file must default-export an async plugin function. If this file is missing or does not export the plugin correctly, the backend will not register that plugin.
This file is your plugin entry in the backend: it should mostly wire models, services, routes, payload, schemas, and contracts β not hold large amounts of business logic (put that in services and helpers).
Datatype-oriented example (single merged code block) β
import type {
PluginFastifyInstance,
PluginOptions,
} from "@raclettejs/core/backend"
import { createModels } from "./example.model"
import { createExampleService } from "./example.service"
import { registerRoutes } from "./routes"
import { registerPayload } from "./helpers/payload"
import { registerExampleSchemas } from "./example.schema"
const examplePlugin = async (
fastify: PluginFastifyInstance,
_opts: PluginOptions,
) => {
const models = createModels(fastify)
const exampleService = createExampleService(models.example)
fastify.custom.exampleService = exampleService
await fastify.register((instance) => registerRoutes(instance))
registerPayload(fastify)
registerExampleSchemas(fastify)
}
export default examplePluginFrontend generation β
By default, the plugin loader registers your plugin for frontend config generation with {} after your index.ts runs, so you usually do not need to call fastify.registerForFrontendGeneration yourself. Use it only when you need custom options or to opt out β see Frontend entity mapping.
Related pages β
- Overview and datatypes
- Routes β route handler shape and
config - Helpers β payload registration details