Building admin modules

The module contract — directory layout, navigation, page discovery, composables.

6 min readAdmin

An admin module is a self-contained slice of UI that plugs into the sidebar and routes. It can live in the base layer (for generic modules) or in a project admin (for project-specific ones).

Anatomy

text
modules/<your-module>/
├── module.ts              # navigation + metadata (required)
├── types/index.ts         # wire shapes (optional)
├── composables/
│   └── useYourApi.ts      # typed HTTP wrappers
├── components/            # module-only components, auto-imported globally
│   └── YourWidget.vue
└── pages/<your-module>/   # Vue pages — discovered + mounted
    ├── index.vue          # /your-module
    └── [id].vue           # /your-module/:id

The outer <your-module> appears twice: once as the directory name, once as the route prefix inside pages/. They don't have to match but it's cleaner when they do.

module.ts

ts
export default defineRedelayModule({
  id: 'customers',
  name: 'Customers',
  version: '1.0.0',
  description: 'Customer directory + billing',
  icon: 'i-heroicons-user-group',

  navigation: {
    label: 'Customers',
    icon: 'i-heroicons-user-group',
    group: 'apps',          // 'apps' | 'system' | any group key
    order: 200,             // smaller = higher in the group
    children: [
      { label: 'All',     href: '/customers',          icon: 'i-heroicons-list-bullet',  order: 1 },
      { label: 'Billing', href: '/customers/billing',  icon: 'i-heroicons-credit-card',  order: 2 },
    ],
  },

  permissions: [],
  requiredPermissions: [],

  async onInit() { /* wire permissions, register toast handlers, etc. */ },
})

The sidebar builds itself from every loaded module's navigation entry. Children become a collapsible group; leaf modules with no children render as a single link.

Pages

Every .vue file under pages/<module>/ becomes a route:

FileRoute
pages/customers/index.vue/customers
pages/customers/[id].vue/customers/:id
pages/customers/billing/index.vue/customers/billing
pages/customers/[id]/invoices.vue/customers/:id/invoices

Every page needs:

vue
<script setup>
definePageMeta({
  layout: 'dashboard',
  middleware: ['auth'],
  ssr: false,              // dev-mode reliability, admin is client-rendered anyway
})
</script>

Composables

Put typed HTTP wrappers in composables/. They're auto-imported — no explicit import needed in pages. The globally available $apiFetch (provided by the base layer) handles JWT injection and the /api/v1 prefix:

ts
// modules/customers/composables/useCustomers.ts
import type { Customer, CustomerListResponse } from '../types'

export function useCustomers() {
  async function list(): Promise<CustomerListResponse> {
    return $apiFetch('/api/v1/admin/customers')
  }

  async function get(id: string): Promise<Customer> {
    return $apiFetch(`/api/v1/admin/customers/${encodeURIComponent(id)}`)
  }

  async function create(input: Partial<Customer>): Promise<Customer> {
    return $apiFetch('/api/v1/admin/customers', { method: 'POST', body: input })
  }

  return { list, get, create }
}

Don't import { $apiFetch } from '~/composables/useApiFetch' — the ~ alias resolves to the consuming project, not the base layer. Auto-import Just Works™.

Types

Match the Go struct JSON tags exactly. Go's default is camelCase for struct fields but some modules use snake_case for timestamps — check the live response with curl before drafting types.

ts
// modules/customers/types/index.ts
export interface Customer {
  id: string
  name: string
  email: string
  created_at: string  // snake_case because Go uses bson:"created_at"
  updated_at?: string
}

Components

Files under components/ auto-import globally across the whole admin — they don't need an explicit import in pages either. The EmptyState component in the base layer is a good pattern to copy for anything you want reused.

Page shell

Every page is an AdminPage: a sticky header (title, one-line description, #actions), an optional #toolbar row and a scrolling body.

vue
<template>
  <AdminPage title="Customers" description="Directory and billing." icon="i-lucide-users">
    <template #actions>
      <UButton icon="i-lucide-plus" to="/customers/new">New customer</UButton>
    </template>
    <template #toolbar>
      <!-- quick filters: see "List pages" below -->
    </template>

    <!-- your UI -->
  </AdminPage>
</template>

Colours are Nuxt UI semantic tokens only (bg-default, text-muted, border-default …), so dark mode needs no per-page work.

List pages: filters and bulk actions

A hand-built list keeps its quick filters in one row: AdminFilterBar in the #toolbar.

vue
<template #toolbar>
  <AdminFilterBar v-model:search="q" search-placeholder="Search customers…"
    :count="total" noun="customer" :active="filtered" @reset="resetFilters">
    <AdminSegmented v-model="status" aria-label="Status" :items="[
      { label: 'All', value: 'all', count: counts.all },
      { label: 'Active', value: 'active', count: counts.active },
    ]" />
    <template #filters>
      <USelect v-model="plan" :items="PLANS" icon="i-lucide-tag" size="sm" class="w-36" aria-label="Plan" />
      <USelect v-model="sort" :items="SORTS" icon="i-lucide-arrow-down-wide-narrow" size="sm" class="w-44" aria-label="Sort" />
    </template>
  </AdminFilterBar>
</template>
PartRule
Primary filterAdminSegmented first — status, view or period, 2–10 options, optional counts. Past the row's width it scrolls sideways instead of wrapping. An item with to is a link (separate routes, e.g. Inbox / Spam).
Searchv-model:search + search-placeholder; grows to fill the row, has a clear ✕.
Secondary filters, sortUSelect size="sm" with an icon and an aria-label; short labels ("Visitors · 7d"); defaults read "Any layout" / "Recently updated".
Right sidethe result count (count, noun, noun-plural) and Reset, shown while active (anything differs from its default).
Stateevery filter in the URL query, so a view can be shared; changing a filter goes back to page 1 and clears the selection.
Avoida second row of tabs or chips under the header, filter labels ("Status:"), full-size controls.

Five or more filters, or typed ones (dates, relations): use ResourceTable's filter panel instead.

Selection and bulk actions. A checkbox column with select-all for the page; while rows are selected, a bar above the table reads "N selected · actions · Clear". Per-row quick actions (archive, confirm…) sit in the last column. Destructive bulk actions confirm first.

See existing modules (users, flows, ai, schedules) for full references.

Was this page helpful?