04-code-implementation-guidelines

A set of coding rules covering TypeScript, React, naming, styling, and testing practices. It emphasizes typed components and functions, reusable code, clear names, and Tailwind CSS for styling.

In plain words
What is it for?
Use it as a reference when implementing or reviewing frontend code, especially TypeScript React components, hooks, utility functions, file names, and class names.
Why use it?
It gives developers shared standards so code is easier to read, safer to change, and consistent across a project.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/dafthunk-com/dafthunk/04-code-implementation-guidelines
Clone the repo
git clone --depth 1 https://github.com/dafthunk-com/dafthunk

Made for: Cursor.

Per session 546 This file is loaded in full into every session.
When invoked 546 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00546 $0.00546
Opus 5 $0.00273 $0.00273
Sonnet 5 $0.00109 $0.00109
Haiku 4.5 $0.00055 $0.00055

Measured yesterday against content hash 6577ed50a65e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

04-code-implementation-guidelines scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/04-code-implementation-guidelines.mdc · 59 lines

How it starts

The opening of the file, as written. The whole thing — 59 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Development Guidelines

General

  • Write correct, DRY, bug-free code — leave no TODOs.
  • Prefer functional components and hooks; use TypeScript types/interfaces consistently.
  • Use early returns to reduce nesting.
  • Choose descriptive names for variables, functions, and components.

Typing

  • Use strict TypeScript: avoid any, unknown, and implicit any.
  • Prefer interface over type aliases, unless a type cannot be expressed with an interface.
  • Always type:
    • Props
    • State
    • Event handlers
    • Returned values
  • Favor readonly and as const assertions for immutability and safety.
  • Narrow types when possible (e.g., 'small' | 'medium' | 'large' instead of string).
  • Use utility types like Partial, Pick, Omit thoughtfully to improve clarity and type safety.

Styling

  • Use Tailwind CSS exclusively — do not use external CSS or styled-components.
  • Use the cn utility from @/utils/utils for conditional class names.
    • Avoid ternaries in className strings.

Naming Conventions

  • kebab-case for file names (e.g., my-component.tsx).
  • camelCase for hooks and utility functions (e.g., useMyHook, formatDate).
  • Prefix event handlers with handle (e.g., handleSubmit, handleClick).

Testing & QA

  • Write tests using Vitest.
  • Cover critical paths, edge cases, and user-facing logic.
  • Provide fallback UI and error boundaries where appropriate.

REST API Best Practices

Shared Types

  • Define shared types in: packages/types/src/index.ts
  • Use them:
    • To serialize data in API routes (backend).
    • To deserialize and validate data on the frontend.
  • This ensures type safety and consistency across backend and frontend.

Statelessness

  • REST APIs must be stateless:
    • Each request must be self-contained.
    • The server must not depend on in-memory or session state.
  • Clients manage session (e.g., cookies, auth headers, tokens).
  • Use headers or tokens to communicate user context, not prior API calls.

Read the full file on GitHub · 59 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 59 lines · 546 tokens per session scan A 6577ed50a65e

Subscribe to this mod's changes

04-code-implementation-guidelines is a cursor rule published in the GitHub repository dafthunk-com/dafthunk (119 stars, last pushed 5d ago), licensed MIT. It adds 546 tokens to every session, about $0.0027 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.