Grails Conventions and Folder Structure

Site Admin · 11 Sep 2026 · 6 views

Convention over Configuration

Grails relies heavily on conventions to reduce boilerplate configuration. If you follow the naming and placement rules, Grails automatically wires your application together. This means less XML, fewer annotations, and more productive coding.

The Core Directories

Every Grails application has these key directories inside grails-app:

  • controllers/ - Handle HTTP requests and responses.
  • domain/ - Define your data model as domain classes.
  • services/ - Business logic layer with optional transaction support.
  • views/ - GSP templates for HTML rendering.
  • conf/ - Application configuration files.
  • init/ - Application bootstrap and initialization.

URL Mapping Conventions

Grails automatically maps URLs to controllers based on naming conventions. A controller named BookController responds to URLs like /book/index, /book/list, and so on.

// grails-app/controllers/com/example/BookController.groovy
class BookController {
    def index() { }
    def list() { }
}

View Resolution

When a controller action returns a model map, Grails looks for a corresponding GSP view in grails-app/views/controllerName/actionName.gsp. For example, the list action in BookController renders grails-app/views/book/list.gsp.

Asset Pipeline

Static assets such as CSS, JavaScript, and images live in the grails-app/assets directory. Grails uses the asset pipeline plugin to compile, minify, and bundle these files.

Key Points

  • Grails uses conventions to eliminate boilerplate configuration.
  • Each directory in grails-app has a specific purpose.
  • Controller and action names directly map to URLs and views.
  • The asset pipeline handles static resources.
  • Following conventions means Grails wires everything automatically.
Share this post:

Comments (0)

Please login or register to comment.