Remix

From TanStack/ai · View interactive version

Remix is an AI agent skill from the GitHub repository TanStack/ai. Build and review Remix 3 applications using the `remix` npm package and subpath imports. Use when working on Remix app structure, routes, controllers, middleware, validation, data access, auth, sessions, file uploads, server setup, UI components, hydration, HMR, navigation, or tests.

How to use this skill

Skill file

Build a Remix App

Use this skill for end-to-end Remix app work. This skill helps you choose the right layer first, reach for the right package, and avoid the most common Remix-specific mistakes.

Full Package Documentation

This skill is the quick guide. When you need fuller API documentation, examples, or package-specific details for a remix/* subpath, first look for a README next to the relevant generated source file in the published remix package: node_modules/remix/src/<subpath>/README.md. These published README files are generated mirrors; in the Remix source repository, the canonical README lives in the owning packages/* package and the packages/remix/src/**/README.md mirrors are intentionally ignored. If that README does not exist, look for the nearest parent README because some subpaths share their parent package documentation.

Examples:

What Remix Is

Remix 3 is a server-first web framework built on Web APIs such as Request, Response, URL, and FormData. All packages ship from a single npm package, remix, and are imported via subpath. There is no top-level remix import.

A Remix app has four main pieces:

When To Use This Skill

Use this skill for:

Load Only The References You Need

Classify the task first, then load the smallest useful reference set. Each reference file starts with a "What This Covers" section that lists the topics inside it — read that first to confirm the file is relevant before reading the rest.

Use the table below to find candidates. Loading more than two or three files at once is usually a sign that the task hasn't been narrowed enough yet.

| Task involves... | Start with |

| ------------------------------------------------------------------------------------------- | ------------------------------------------- |

| Defining URLs, writing controllers and actions, returning responses | references/routing-and-controllers.md |

| Composing the request lifecycle, ordering middleware, bridging to a server, development HMR | references/middleware-and-server.md |

| Compiling and serving browser modules, asset URL namespaces, preloads, browser HMR | references/assets-and-browser-modules.md |

| Parsing input, validating with schemas, defining tables, querying, migrations | references/data-and-validation.md |

| Per-browser state, login flows, route protection, identity | references/auth-and-sessions.md |

| Component setup, state, lifecycle, updates, queueTask, context | references/component-model.md |

| Event handlers, styles, refs, click/key behavior, simple animations | references/mixins-styling-events.md |

| clientEntry, run, <Frame>, navigation, browser HMR update handling, <head> | references/hydration-frames-navigation.md |

| Router tests, component tests, test isolation | references/testing-patterns.md |

| Spring physics, tweens, layout transitions | references/animate-elements.md |

| Authoring custom reusable mixins | references/create-mixins.md |

Common bundles:

Default Workflow

  1. Classify the change. Decide whether it changes the route contract, request lifecycle, data model, auth or session behavior, or only UI.
  2. Start from the server contract. Add or update app/routes.ts before wiring handlers or UI.
  3. Put code in the narrowest owner. Favor route-local code first, then promote only when reuse is real.
  4. Make the server path correct before adding browser behavior. A route should return the right Response via router.fetch(...) before you add clientEntry(...), animations, or DOM effects.
  5. Add middleware deliberately. Keep fast-exit middleware early and request-enriching middleware later. Export a typed AppContext from the middleware stack and use it in controllers.
  6. Validate input at the boundary. Parse and validate Request, FormData, params, cookies, and external payloads before they reach rendering or persistence logic.
  7. Hydrate only when necessary. Prefer server-rendered UI. Use clientEntry(...) and run(...) only for real browser interactivity or browser-only APIs.
  8. Test the narrowest meaningful layer. Prefer router tests for route behavior. Use component tests when the behavior is truly interactive or DOM-specific.
  9. Finish with verification. Re-read the route flow, confirm auth and authorization boundaries, and run the smallest relevant test and typecheck loop.

Project Layout

Use these root directories consistently:

Inside app/, organize by responsibility:

Placement Precedence

When code could live in multiple places:

  1. Put it in the narrowest owner first.
  2. If it belongs to one route, keep it with that route.
  3. If it is shared UI across route areas, move it to app/ui/.
  4. If it is request lifecycle setup, keep it in app/middleware/.
  5. If it is schema, query, persistence, or startup data logic, keep it in app/data/.
  6. Use app/utils/ only as a last resort for truly cross-layer helpers.

Route Ownership

Response Rendering And Utilities

Layout Anti-Patterns

Core Remix Rules

Security And Session Defaults

Testing Defaults

Common Mistakes To Avoid

Package Map

Use this map to find the right package quickly. Each entry says what the package is for, not just what it exports. Open the linked reference file when you need full examples.

Routing, Server, and Responses

Data, Validation, and Persistence

Auth, Sessions, and Cookies

UI, Hydration, and Browser Behavior

Middleware

Test

Canonical Patterns

Define routes first

import { form, get, post, resources, route } from 'remix/routes'

export const routes = route({
  home: '/',
  contact: form('contact'),
  books: {
    index: '/books',
    show: '/books/:slug',
  },
  auth: route('auth', {
    login: form('login'),
    logout: post('logout'),
  }),
  admin: route('admin', {
    index: get('/'),
    books: resources('books', { param: 'bookId' }),
  }),
})

Type controllers against the route contract

import { createController } from 'remix/router'

import { databaseContext } from '../middleware/database.ts'
import { routes } from '../routes.ts'

export default createController(routes.books, {
  actions: {
    async index({ get }) {
      let db = get(databaseContext)
      let allBooks = await db.findMany(books, { orderBy: ['id', 'asc'] })
      return render(<BooksIndexPage allBooks={allBooks} />)
    },
    async show({ get, params }) {
      let db = get(databaseContext)
      let book = await db.findOne(books, { where: { slug: params.slug } })
      if (!book) return new Response('Not Found', { status: 404 })
      return render(<BookShowPage book={book} />)
    },
  },
})

Register Controllers Explicitly

import { createRouter } from 'remix/router'

import rootController from './actions/controller.tsx'
import adminController from './actions/admin/controller.tsx'
import adminBooksController from './actions/admin/books/controller.tsx'
import authController from './actions/auth/controller.tsx'
import authLoginController from './actions/auth/login/controller.tsx'
import booksController from './actions/books/controller.tsx'
import contactController from './actions/contact/controller.tsx'
import { routes } from './routes.ts'

export const router = createRouter({ middleware })

router.map(routes, rootController)
router.map(routes.contact, contactController)
router.map(routes.books, booksController)
router.map(routes.auth, authController)
router.map(routes.auth.login, authLoginController)
router.map(routes.admin, adminController)
router.map(routes.admin.books, adminBooksController)

Compose middleware deliberately

import { createRouter } from 'remix/router'

let middleware = []

if (process.env.NODE_ENV === 'development') {
  middleware.push(logger())
}

middleware.push(compression())
middleware.push(staticFiles('./public'))
middleware.push(formData())
middleware.push(methodOverride())
middleware.push(session(cookie, storage))
middleware.push(asyncContext())
middleware.push(loadDatabase())
middleware.push(loadAuth())

let router = createRouter({ middleware })

Validate, mutate, and respond

import { createController } from 'remix/router'
import { redirect } from 'remix/response/redirect'
import * as s from 'remix/data-schema'
import * as f from 'remix/data-schema/form-data'
import { Session } from 'remix/session'

import { databaseContext } from '../middleware/database.ts'
import { routes } from '../routes.ts'

let bookSchema = f.object({
  slug: f.field(s.string()),
  title: f.field(s.string()),
})

export default createController(routes.books, {
  actions: {
    async create({ get }) {
      let parsed = s.parseSafe(bookSchema, get(FormData))
      if (!parsed.success) {
        return render(<NewBookPage errors={parsed.issues} />, { status: 400 })
      }

      let db = get(databaseContext)
      let book = await db.create(books, parsed.value)

      let session = get(Session)
      session.flash('message', `Added ${book.title}.`)

      return redirect(routes.books.show.href({ slug: book.slug }))
    },
  },
})

This shape works without JavaScript, returns a Response for every outcome, and is ready for clientEntry(...) interactivity when the UI needs it.

Build UI from handle props plus render

import { on, type Handle } from 'remix/ui'

function Counter(handle: Handle<{ initialCount?: number; label: string }>) {
  let count = handle.props.initialCount ?? 0

  return () => (
    <button
      mix={on('click', () => {
        count++
        handle.update()
      })}
    >
      {handle.props.label}: {count}
    </button>
  )
}

Only add clientEntry(...) and run(...) when the component needs browser interactivity or browser-only APIs.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.