Runcobo
Runcobo is a batteries-included web framework for Crystal. Each endpoint is one action class that declares its route, validates its input against a typed contract and renders its response, with the contract and template beside it in the same folder.
Documentation: https://runcobo.github.io/runcobo/
Features
- Typed input — request contracts for path, query, form and JSON input; invalid requests get a structured
422automatically. - Compile-time views — Jbuilder (JSON) and Water (HTML) templates, layouts and partials checked by the compiler.
- SQL-first ORM — crsql generates typed query methods from the SQL you write, for PostgreSQL, MySQL and SQLite.
- Database toolchain — local databases for PostgreSQL, MySQL and SQLite, SQL migrations with verified rollbacks, and staging/production migration commands.
- Production server — request IDs, structured logging, error handling, uploads, static files, trusted proxies, TLS and graceful shutdown.
- One CLI —
coboruns the dev server, console, scripts, tasks, tests and code generation.
Installation
Crystal >= 1.22.0 and < 2.0.0 is required. Create a project and add Runcobo to shard.yml:
crystal init app blog && cd blog
dependencies:
runcobo:
github: runcobo/runcobo
version: ~> 3.1
Then install it, which also builds the cobo CLI, and set the project up:
shards install
bin/cobo init # --database postgresql (default), mysql, sqlite or none
bin/cobo dev
See Installation for details.
Example
require "runcobo"
class CreateNoteContract < RequestValidation::Contract
schema do
required :title, String, filled: true, max_size: 100
end
end
class CreateNote < BaseAction
post "/notes"
call do
input = validate(CreateNoteContract)
render_json({title: input.title}, status_code: 201)
end
end
Runcobo.start
crystal run src/notes.cr
curl localhost:3000/notes -H 'Content-Type: application/json' -d '{"title":"Hello"}'
# {"title":"Hello"}
Continue with the Quick Start, then Project Structure for how a full application is laid out.
Common commands
cobo init Set up a project created by crystal init app
cobo routes Print the application's route table
cobo dev Prepare the database, run the server and restart it on changes
cobo db ... Manage local databases and migrations
cobo generate Generate typed queries (--check to verify them in CI)
cobo test Run the specs against the test database
See the CLI reference for every command and runcobo.yml.
Documentation
- Guide — actions, routing, contracts, views, uploads, database, server, testing and deployment
- CLI — the
cobocommand andruncobo.yml - API reference — generated with
crystal docs - Changelog
The manual's source is in website/; run npm install && npm run docs:dev there to preview it.
Contributing
Local development
The development branch requires Crystal >= 1.22.0 and < 2.0.0, with Shards
and Make installed. Automated checks run on Crystal 1.22.0 and 1.22.3.
Dependencies, including request-validation and the crsql 1.0 generator from
shootingfly/sqlc-gen-crystal, install from public repositories. Generation uses sqlc
1.31.1; database tests use a dedicated PostgreSQL database.
git clone https://github.com/runcobo/runcobo.git
cd runcobo
make check
To develop against local clones of request-validation or crsql, create the
ignored shard.override.yml in the Runcobo root:
dependencies:
request_validation:
path: ../request-validation
crsql:
path: ../sqlc-gen-crystal
Automated checks install the same public dependencies and need no repository secrets, so pull requests from forks run the full checks.
make check installs dependencies, builds the framework and development generator, runs the specs, compiles the example application,
checks formatting in src and spec, builds bin/cobo, and checks its --version and --help
commands. It does not install anything into system directories. The same
command runs for pushes and pull requests targeting main. Automated checks
also run make generate-check and make integration; see the database example
for preparing the dedicated test database.
For individual tasks:
make build # Build bin/cobo locally; also the default for make
make test # Install dependencies and run specs
make examples-check # Compile the example applications without linking
make generate # Regenerate the crsql example queries (requires sqlc)
make generate-check # Check generation against the committed file
make integration # Run with DATABASE_URL pointing to runcobo_crsql_test
make format # Apply formatting to src and spec
make format-check # Check formatting without changing files
make help # List development commands
Dependencies and the local dependency lock file (shard.lock) are ignored in
this library repository. Applications should commit their own lock files.
To install cobo and dbmate explicitly, use make install. The default
installation directory is /usr/local/bin; use an existing writable prefix
to avoid requiring elevated permissions:
make install INSTALL_DIR="$HOME/.local/bin"
Add that directory to your shell's command search path before running cobo.
Submitting changes
- Fork it (https://github.com/runcobo/runcobo/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Write specs and run
make check(usemake formatto apply formatting) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Shootingfly - creator and maintainer
License
MIT — see LICENSE.