Girouette

Introduction

Elegant decorator-based routing for AdonisJS v7

Girouette

Elegant decorator-based routing for AdonisJS v7

Girouette provides a beautiful, fluent API for defining your AdonisJS routes using decorators. By bringing route definitions closer to your controller methods, Girouette makes your application's routing more intuitive and maintainable.

Why Girouette?

Traditional AdonisJS routing requires defining routes in a separate file, which can become difficult to maintain as your application grows. Girouette solves this by:

  • Colocation: Keep route definitions next to your controller methods
  • Type Safety: Full TypeScript support with decorator metadata
  • Familiar Patterns: Similar to routing in NestJS, Laravel, or Spring Boot
  • Zero Runtime Overhead: Routes are registered at boot time
  • Tuyau Compatible: Works seamlessly with AdonisJS's type-safe API client

Quick Example

import { Get, Post, Middleware } from '@adonisjs-community/girouette'
import { middleware } from '#start/kernel'
import { HttpContext } from '@adonisjs/core/http'

export default class UsersController {
  @Get('/users') 
  async index() {
    return User.all()
  }

  @Get('/users/:id') 
  async show({ params }: HttpContext) {
    return User.findOrFail(params.id)
  }

  @Post('/users') 
  @Middleware([middleware.auth()]) 
  async store({ request }: HttpContext) {
    return User.create(request.body())
  }
}

How It Works

Girouette generates a start/routes.girouette.ts file that contains all your decorated routes. This file is automatically kept in sync with your controllers, enabling Hot Module Replacement (HMR) during development. When you modify the logic inside a controller method, your changes are reflected instantly without restarting the server.

When you change the routing itself (adding/removing routes, modifying paths, or changing decorators), a full server reload is required since routes are registered at boot time.

Girouette automatically scans your controllers and registers routes at application boot. No additional configuration needed after installation.

Features at a Glance

Getting Started

Install Girouette via the AdonisJS CLI:

node ace add @adonisjs-community/girouette

That's it! You can now start using decorators in your controllers.

Available Decorators

DecoratorDescription
@GetDefine a GET route
@PostDefine a POST route
@PutDefine a PUT route
@PatchDefine a PATCH route
@DeleteDefine a DELETE route
@AnyMatch any HTTP method
@ResourceCreate RESTful resource routes
@GroupGroup routes with prefix/name
@GroupMiddlewareApply middleware to all routes
@GroupDomainRestrict routes to a domain
@MiddlewareApply middleware to a route
@ResourceMiddlewareApply middleware to resource actions
@WhereAdd route parameter constraints
@PickInclude specific resource actions
@ExceptExclude specific resource actions
@ApiOnlyInclude only API actions

Next Steps

On this page