imtiajrex/appflare-skills/appflare-handlers

Claude Code and agent skill by imtiajrex/appflare-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Write Appflare backend handlers, including query (GET) and mutation (POST) endpoints with Zod args, authRequired, middleware and ctx.error, background scheduler tasks enqueued with ctx.scheduler, cron jobs, and storageManager rules for R2 storage. Explains how file paths map to routes, client names and task names. Use when creating or editing endpoints, API logic, auth or role checks, background jobs, scheduled tasks or file-access rules in an Appflare project, or when a route is missing from the generated client.

Install

npx vskill@latest install imtiajrex/appflare-skills/appflare-handlers

SKILL.md

The same SKILL.md was published earlier as imtiajrex/appflare-skills/appflare-handlers.

Appflare handlers

Pick the handler kind

NeedHelperExposed as
Read dataqueryGET /queries/<path>/<export>, appflare.queries.<path>.<export>
Change datamutationPOST /mutations/<path>/<export>, appflare.mutations.<path>.<export>
Background workschedulertask <parentDir or root>/<file>/<export>
Time-based workcronCron Trigger
Authorize R2 accessstorageManagerused by ctx.storage and /storage/*

Workflow

  • [ ] Choose a file under scanDir. The path becomes the client path, and a leading queries/ or mutations/ folder is dropped
  • [ ] Import helpers from the relative generated module, e.g. ../_generated/handlers
  • [ ] Write export const name = helper({...}). Only this exact form is discovered
  • [ ] Run bun appflare dev and confirm it succeeds
  • [ ] For data access patterns, load appflare-querying

Query / mutation template

ts
import * as z from "zod";
import { mutation, query } from "../_generated/handlers";
export const listTasks = query({
args: {
projectId: z.string(),
limit: z.coerce.number().int().min(1).max(100).default(20),
done: z.stringbool().optional(),
},
authRequired: true,
handler: async (ctx, args) => {
return ctx.db.tasks.findMany({
where: {
projectId: args.projectId,
...(args.done === undefined ? {} : { done: args.done }),
},
orderBy: { column: "id", direction: "desc" },
limit: args.limit,
});
},
});
export const completeTask = mutation({
args: { id: z.number().int() },
authRequired: true,
handler: async (ctx, args) => {
const [task] = await ctx.db.tasks.update({
where: { id: args.id, assigneeId: ctx.user.id },
set: { done: true },
});
if (!task) ctx.error(404, "Task not found");
return task;
},
});

Rules

  • `args` is a raw Zod shape (a plain object), not z.object(...). Use args: {} for none.
  • Query args arrive as strings and are converted to what the schema expects, so z.boolean(), z.number(), z.array(z.string()) and object args work in a query. z.coerce.* still works. Mutation args are JSON, so any Zod type works.
  • Auth: authRequired: true returns 401 without a session. Otherwise guard with if (!ctx.user) ctx.error(401, "…").
  • Roles and shared checks: use middleware: async (ctx, args, request) => { if (ctx.user?.role !== "admin") ctx.error(403, "Forbidden"); }. It runs after the auth check and before the handler.
  • Errors: ctx.error(status, message, details?) throws and responds { message, details } with that status. Other throws become a sanitized 500 { message: "Internal error", requestId }, so never rely on a raw Error message reaching the client. Constraint failures map automatically (unique → 409, trigger/check → 400).
  • Return JSON-serializable values. A Date reaches the client as a string.
  • Realtime-friendly queries: a subscribed query refreshes only if its handler uses nothing but ctx.db reads plus ctx.user/ctx.session. ctx.error, ctx.$db, ctx.storage or anything that throws on empty results disables pushes, so return null instead of ctx.error(404) in those queries.

Scheduler and cron (quick form)

ts
import { cron, scheduler } from "../../_generated/handlers";
// file: src/jobs/email.ts → task "jobs/email/sendDigest"
export const sendDigest = scheduler({
args: { userId: z.string() },
handler: async (ctx, args) => { /* ... */ },
});
// from any handler:
await ctx.scheduler.enqueue("jobs/email/sendDigest", { userId }, { delaySeconds: 60 });
export const nightly = cron({
cronTrigger: "0 3 * * *", // string literal or array of literals
handler: async (ctx) => { /* ... */ },
});

Gotchas

  • export default, export function, re-exports and wrapped helpers are not discovered.
  • Task names use only the last directory: src/a/jobs/email.ts and src/b/jobs/email.ts collide and fail with Duplicate handler operation discovered.
  • Scheduler and cron contexts have ctx.user === null. Failures are logged and not retried.
  • cronTrigger must be a literal. Variables are invisible to the build.
  • Storage is denied by default. Without a storageManager returning true, even ctx.storage calls in your own handlers get 403.
  • ctx.user is typed non-null but can be null without authRequired.
  • Writes through ctx.$db don't trigger realtime updates. Use ctx.db.
  • A mutation that writes several tables should use ctx.db.batch or ctx.db.transaction so a mid-way failure leaves nothing behind.
  • Files named *.test.* or *.spec.*, anything in __tests__/, and config exclude globs are not discovered.

References

  • Read references/context.md when you need a ctx field (db, $db, user, session, auth, storage, scheduler, context.env, mutationEvents, error).
  • Read references/background-jobs.md when writing scheduler tasks or cron jobs, or debugging queue and cron execution.
  • Read references/storage.md when writing storageManager rules or using ctx.storage or the /storage/* routes.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/imtiajrex/appflare-skills/appflare-handlers/badge)](https://verified-skill.com/skills/imtiajrex/appflare-skills/appflare-handlers)

Something wrong with this skill or its page? Tell us.