# Adding A New Tool

Use this workflow to add a new `video.haus` tool without breaking dashboard routing or shared patterns.

## 1. Create the Tool Definition

Add a new entry in [`lib/tools-registry.ts`](../lib/tools-registry.ts) using `ToolDefinitionInput` shape.

- `slug` should be unique and URL-safe
- `route` is optional and defaults to `/tools/<slug>`
- pick an accent from [`starterAccentPresets`](../lib/tools/new-tool-starter.ts)

Starter reference:

- [`newToolDefinitionTemplate`](../lib/tools/new-tool-starter.ts)
- [`newToolChecklist`](../lib/tools/new-tool-starter.ts)

## 2. Add The Tool UI Component

Create:

- `components/tools/<slug>-tool.tsx`

Guidelines:

- Reuse shared components in `components/media/*`
- Keep page logic focused on orchestration
- Put repeated utility logic in `lib/client/*` or `hooks/*`

## 3. Register The Component For `/tools/[slug]`

Add mapping in [`lib/tool-page-components.ts`](../lib/tool-page-components.ts):

- key: `slug`
- value: tool component

The dynamic route page already resolves tool metadata + component from registry/mapping.

## 4. Add Tool API Routes (Optional)

If the tool needs server processing, add:

- `app/api/tools/<slug>/.../route.ts`

Recommended baseline:

- validate file input via `validateVideoUploadFile`
- write upload via `writeUploadToTemp`
- use helpers in `lib/media-processing/*`
- return standard responses via `createSuccessResponse` / `createErrorResponse`
- always cleanup temp files in `finally`

## 5. Add Shared Processing Helpers (When Reusable)

If behavior can be reused by other tools, implement in:

- `lib/media-processing/*`
- `lib/ffmpeg/*`
- `lib/ffprobe/*`
- `lib/uploads/*`

Avoid one-off route-only command logic when it can live in shared modules.

## 6. Update Documentation

Update [`README.md`](../README.md):

- add tool summary under initial tools
- list API routes and outputs
- include any env vars or FFmpeg requirements

## 7. Validate Before Merge

Run:

```bash
npm run typecheck
npm run lint
npm run build
```

If these pass, the tool is usually safe to integrate.
