grails

Grails

Grails convention-over-configuration web framework patterns for building Groovy-based full-stack web applications

Details

Language / Topic
groovyGroovy
Category
framework
Compatible Frameworks
grails

Rules

balanced
- Follow Grails naming conventions: `BookController`, `BookService`, `Book` domain class — the framework autowires collaborators by name via Spring DI.
- Use GORM for persistence: `Book.findByTitle("Refactoring")` for simple queries — use Criteria API or HQL for complex multi-join queries.
- Controller actions return a model map: `return [books: bookService.list()]` — Grails resolves `grails-app/views/book/index.gsp` by convention.
- Keep business logic in `@Transactional`-annotated services — never put database or business logic directly in controllers.
- Configure per-environment settings in `grails-app/conf/application.yml` under `environments.production:` — never hardcode credentials.
- Define domain constraints: `static constraints = { name blank: false, maxSize: 100; email email: true, unique: true }` — GORM validates before saving.
- Use GSP tag libraries in `grails-app/taglib/BookTagLib.groovy`: `static namespace = "bk"; def badge = { attrs, body -> out << "<span>${attrs.text}</span>" }`.
- Generate scaffolding with `grails generate-all com.example.Book` as a starting point — always customise generated code before treating it as production.