---
url: /runcobo/migrate/lucky.md
description: >-
  Coming from Lucky? How actions, pipes, params, serializers, pages and Avram
  map to Runcobo.
---

# Coming from Lucky

Lucky and Runcobo share the core idea: **one class per action**, with its route declared inside it and as much as possible checked by the compiler. Pipes even have the same names. The main differences are how input is read, how responses are rendered and how the database is accessed.

## At a glance

| Lucky | Runcobo |
| --- | --- |
| `class Posts::Show < ApiAction` | `class Posts::ShowPost < Blog::BaseAction` |
| `get "/posts/:post_id" do ... end` | `get "/posts/:id"` + `call do ... end` |
| Route params as methods (`post_id`) | Contract fields: `validate(ShowPostContract).id` |
| `params.from_json`, operation params | One [contract](/guide/contracts) for path, query and body |
| `before require_sign_in` / `after` / `skip` | [`before` / `after` / `skip`](/guide/filters) — the same |
| A pipe returns `continue` | A filter returns anything; `byebye` halts (`continue` also works) |
| `json(...)`, serializers | `render_json(...)`, or [Jbuilder](/guide/views#jbuilder) templates |
| HTML pages and components | [Water](/guide/views#water) templates, layouts and partials |
| Avram models and query objects | Named SQL queries → a typed [`store`](/guide/database) |
| `SaveOperation` validations | Contracts for input; constraints in SQL for data |
| Avram migrations (Crystal DSL) | Plain SQL migrations |
| `lucky dev` | `bin/cobo dev` |
| `lucky routes` | `bin/cobo routes` |
| `lucky db.migrate` | `bin/cobo db migrate` |

## An action

```crystal
# Lucky
class Api::Posts::Show < ApiAction
  get "/api/posts/:post_id" do
    post = PostQuery.find(post_id)
    json PostSerializer.new(post)
  end
end
```

```crystal
# Runcobo
class Posts::ShowPost < Blog::BaseAction
  get "/posts/:id"

  call do
    input = validate(ShowPostContract)
    if post = store.get_post?(id: input.id)
      render                               # → show_post.jbuilder
    else
      render_json({error: "post_not_found"}, status_code: 404)
    end
  end
end
```

```crystal [src/actions/posts/show_post_contract.cr]
class Posts::ShowPostContract < RequestValidation::Contract
  schema do
    required :id, Int64
  end
end
```

```crystal [src/actions/posts/show_post.jbuilder]
json.id post.id
json.title post.title
```

The path parameter is declared with a type in the contract, so `/posts/abc` is a `422` before your code runs, and the same contract also reads query and body fields.

## Pipes are filters

```crystal
abstract class Blog::AdminAction < Blog::BaseAction
  before require_admin

  private def require_admin
    unless admin?
      render_json({error: "forbidden"}, status_code: 403)
      return byebye
    end
  end
end
```

The behavior matches Lucky's pipes: filters run in declaration order, are inherited, and `skip require_admin` removes an inherited one. A filter that doesn't return `byebye` lets the request continue.

## Avram becomes SQL

Instead of models and query objects, write each query in SQL and generate typed methods:

```sql [db/queries/posts.sql]
-- name: ListPublishedPosts :many
SELECT id, title FROM posts WHERE published_at IS NOT NULL ORDER BY published_at DESC;
```

```crystal
store.list_published_posts   # => Array(Blog::Store::ListPublishedPostsRow)
```

Both approaches are type-safe; Runcobo checks the SQL against your migrations when you run `bin/cobo generate`, and the result types come from the database schema. Related records are loaded explicitly, with a `JOIN` or [one batch query](/guide/n-plus-one).

## Pages become templates

Lucky renders HTML with page classes. Runcobo uses Water templates that sit beside the action, rendered with `render engine: :water` or by default after `Runcobo.views "src/actions", engine: :water`. See [Views](/guide/views).

## What's different

* **Input is a contract, not a method per param.** One `validate` call checks everything and returns a typed object.
* **Responses are templates or `render_json`.** There are no serializer classes.
* **No ORM.** SQL is the source of truth, through [crsql](/guide/database).
* **Smaller surface.** Runcobo has no asset pipeline, mailer or authentication generator. Bring the libraries you need.

Next: [Installation](/guide/installation), then the [blog tutorial](/guide/example).
