Skip to main content
Version: 1.0

Creating a Tool

A tool is a folder of five files plus one line in the registry.

The fast path​

pnpm create-tool <tool-id> "Display Name" <category>
# e.g.
pnpm create-tool url-encode "URL Encode / Decode" web

This scaffolds src/tools/url-encode/ with definition.ts, logic.ts, logic.test.ts, component.tsx and content.ts, and registers it in src/tools/registry.ts. Then you fill in the blanks.

<category> must be one of: json, dotnet, encoding, security, text, devutils, sql, datetime, data, images, web. It defaults to devutils.

The five files​

1. definition.ts: metadata​

Keep it light: no heavy imports and no React component. The registry imports every definition eagerly for search, categories and the command palette.

import { defineTool } from "@/lib/tool-sdk";

export default defineTool({
id: "url-encode", // URL-safe id; also the route /tools/url-encode
name: "URL Encode / Decode",
description: "Percent-encode or decode text and URLs, all local.",
category: "web",
keywords: ["url", "encode", "decode", "percent", "uri", "querystring"],
execution: "local", // "local" | "server" | "hybrid"
inputType: "text", // what a Send-To may hand this tool
outputType: "url", // what this tool emits
popular: false, // optional: show in homepage "popular"
});

Good keywords power search, so add the aliases users might type.

2. logic.ts: pure functions​

All real work lives here as pure, framework-free functions: no DOM access, no React, no side effects. This is what gets unit-tested, what a Web Worker can run, and what tool chaining can reuse.

export function encodeUrl(input: string): string {
return encodeURIComponent(input);
}

export function decodeUrl(input: string): string {
return decodeURIComponent(input);
}

3. logic.test.ts: tests​

Every non-trivial tool needs tests, including edge cases (empty input, Unicode, malformed input). Test behaviour, not implementation details.

import { describe, expect, it } from "vitest";
import { decodeUrl, encodeUrl } from "./logic";

describe("url-encode", () => {
it("round-trips reserved characters", () => {
const s = "a b&c=d/?#";
expect(decodeUrl(encodeUrl(s))).toBe(s);
});
});

4. component.tsx: the UI​

A Client Component ("use client") with a default export. It receives ToolComponentProps ({ initialInput?: string }), which is how Send To seeds the tool. Treat initialInput as ephemeral and never persist it.

Reuse the shared building blocks: ToolEditor, ConverterLayout, Button, CopyButton, FavoriteButton and SendToMenu.

"use client";

import { useEffect, useMemo, useState } from "react";
import type { ToolComponentProps } from "@/lib/tool-sdk";
import { getDefinition } from "@/lib/registry";
import { ToolEditor } from "@/components/tool/ToolEditor";
import { CopyButton } from "@/components/ui/CopyButton";
import { SendToMenu } from "@/components/tool/SendToMenu";
import { encodeUrl } from "./logic";

export default function UrlEncodeTool({ initialInput }: ToolComponentProps) {
const [input, setInput] = useState(initialInput ?? "");
const definition = getDefinition("url-encode")!;

useEffect(() => {
if (initialInput !== undefined) setInput(initialInput);
}, [initialInput]);

const output = useMemo(() => encodeUrl(input), [input]);

return (
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
<ToolEditor label="Input" value={input} onChange={setInput} minRows={16} />
<ToolEditor
label="Output"
value={output}
readOnly
minRows={16}
actions={
<>
<CopyButton size="sm" variant="ghost" value={output} />
<SendToMenu source={definition} value={output} />
</>
}
/>
</div>
);
}

Style with theme tokens (text-foreground, bg-surface, border-border, text-accent), never hardcoded hex colours.

5. content.ts: the page copy​

The component is loaded client-side only, so it contributes nothing to the server-rendered HTML. content.ts holds the text of the tool page:

import { defineContent } from "@/lib/tool-sdk";

export default defineContent({
title: "URL Encoder & Decoder", // <title> minus the site name, 8-45 chars
metaDescription:
"Percent-encode or decode URLs and query parameters in your browser, component-wise or whole, with UTF-8 handled correctly.", // 110-170
heading: "Percent-encoding, both directions",
intro: "60-90 words: what it does, when you reach for it, what stays local.",
steps: ["Paste the URL…", "Choose component or full…", "Copy the result…"],
notes: ["Optional paragraphs about formats, limits or gotchas."],
faq: [{ question: "What is percent-encoding?", answer: "25-45 words." }],
related: ["url-parser", "query-string", "base64"],
});

Then regenerate the content registry:

pnpm generate:content

A test checks the mechanical rules: lengths, 3-5 steps, 3-5 answered questions, a minimum word count, valid related ids, and no text duplicated from another tool.

Registering manually​

If you did not use the generator, add one entry to src/tools/registry.ts. The load thunk must be a dynamic import(), which is what code-splits the tool:

import urlEncode from "./url-encode/definition";
// …
export const TOOL_ENTRIES: ToolEntry[] = [
// …
{ definition: urlEncode, load: () => import("./url-encode/component") },
];

Tool SDK reference​

interface ToolDefinition {
id: string; // URL-safe, stable. Also the route: /tools/<id>
name: string;
description: string; // one sentence, no marketing (drives SEO + header)
category: ToolCategoryId; // single primary bucket
keywords: string[]; // aliases/search terms
tags?: string[]; // optional cross-cutting tags (converter, generator…)
execution: ToolExecution; // "local" | "server" | "hybrid"
inputType?: ToolDataType; // what a Send-To may hand this tool
outputType?: ToolDataType; // what this tool emits
shortName?: string; // optional compact label
popular?: boolean; // optional: homepage "popular" section
}

ToolDataType values: text, json, xml, yaml, sql, markdown, html, csv, base64, jwt, url, image, binary. inputType and outputType are how Send To finds compatible tools without any tool knowing about another.

Common registry helpers from src/lib/registry:

FunctionReturns
getAllDefinitions()every tool's metadata
getDefinition(id)one definition (or undefined)
getEntry(id)metadata + loader
getDefinitionsByCategory(cat)definitions in a category
getPopularDefinitions()popular: true tools
getToolIds()all ids
searchTools(query)scored search results
getSendToTargets(sourceDefinition)compatible Send To destinations

Heavy tools: Web Workers​

If a tool can receive large inputs (big JSON, large diffs, images), move the expensive work to a worker. For a single input-to-output transform, use the useWorkerTransform hook. It runs on the main thread for small inputs and offloads to the worker above a size threshold, with an automatic fallback:

const { result, error, pending } = useWorkerTransform<Req, Res>({
createWorker: () => new Worker(new URL("./worker.ts", import.meta.url)),
buildRequest: () => ({ sql: input, options }),
compute: (r) => formatSql(r.sql, r.options), // main-thread + fallback
size: input.length,
deps: [input, options],
threshold: 20_000,
});

The worker imports the same pure logic.ts:

import { handleWorkerMessages } from "@/lib/worker/workerClient";
import { diffText, type DiffRequest, type DiffResult } from "./logic";

handleWorkerMessages<DiffRequest, DiffResult>((req) =>
diffText(req.a, req.b, req.options),
);

Only use a worker when the input can be large. Reference implementations are src/tools/sql-formatter/ (hook) and src/tools/text-compare/ (manual WorkerClient).

Checklist​

  • definition.ts with accurate execution, inputType, outputType and keywords
  • logic.ts pure and framework-free
  • logic.test.ts covering edge cases
  • component.tsx using shared components and theme tokens
  • content.ts written from the real behaviour, then pnpm generate:content
  • Registered in src/tools/registry.ts
  • No input sent anywhere, logged, or placed in a URL
  • pnpm typecheck && pnpm lint && pnpm test && pnpm build all pass