crinit

Version, currently master branch1 version
  • master branchlatestSep 18, 2026

gitlab.com/renich/crinit

Next-generation pluggable project scaffolding for Crystal.

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  crinit:
    gitlab: renich/crinit
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.21.0
License
MIT
Author
Rénich Bon Ćirić
Target
  • crinit from src/main.cr

Dependencies

Development Dependencies

  • ameba*github: crystal-ameba/amebadev

README

Project Metadata:

  • Description: Next-generation pluggable project scaffolding engine for Crystal. Engineered for arbitrary tree mirroring, macro-safe token replacement, and zero-dependency upstream compiler integration.
  • Topics / Tags: crystal, crystal-lang, scaffolding, generator, template-engine, compiler, cli, ameba, flaw, sphinx, crstlint

🎯 Intent & Upstream Vision

crinit was created with the explicit intention of being proposed and merged directly into the upstream Crystal compiler (crystal init).

The current implementation of crystal init (located in src/compiler/crystal/tools/init.cr) has remained frozen for years and exhibits several architectural limitations that hinder production engineering:

  1. Hardcoded File Inventory: The compiler explicitly declares a static set of eight views: .gitignore, .editorconfig, LICENSE, README.md, shard.yml, src/<name>.cr, spec/spec_helper.cr, and spec/<name>_spec.cr.
  2. Monolithic Flat Hierarchy: Modern production architectures require domain-segregated directory structures (config/, containers/, packaging/, scripts/, docs/). The current tool forces all projects into a single flat file under src/.
  3. Mandatory License Lock-In: The embedded LICENSE and shard.yml templates strictly mandate the MIT license. Organizations or open-source authors wishing to release software under copyleft terms (GPLv3, AGPLv3, MPL-2.0) are forced to manually overwrite files after initialization.
  4. Zero Community Extensibility: Framework authors (Kemal, Lucky, Athena, Blueprint) cannot provide canonical skeletons. Instead, they must either maintain bespoke generator shards or instruct developers to perform tedious manual setup.

crinit acts as the reference prototype, testbed, and dogfooding tool to prove the design before submitting the formal Crystal RFC and Pull Request to crystal-lang/crystal.


πŸ’‘ Key Highlights & Architectural Principles

  • Zero External Runtime Dependencies: Uses strictly Crystal's standard library (OptionParser, YAML, File, Dir, Process, Path). No heavy scripting interpreters.
  • Offline-First & Network-Decoupled: Operates entirely on the local filesystem. Remote template fetching is intentionally decoupled to respect the compiler team's separation between crystal and shards.
  • 100% Backward Compatible: Drops in as a replacement for crystal init app <name> and crystal init lib <name>, preserving existing behavior via embedded fallbacks unless overridden.
  • Multi-Platform Native Support: First-class support across the entire official Crystal tier matrix (Linux, macOS, Windows).
  • Arbitrary Tree Mirroring: Complete topological freedom over directories, nested namespaces (src/<name>/init.cr), assets, and licensing.
  • Macro-Safe Token Substitution: Prevents syntax collisions with Crystal's native macro delimiters ({{ ... }}) while supporting explicit escaping (\{{ ... \}}).

πŸš€ Quickstart

Prerequisites

  • Crystal: >= 1.21.0
  • Shards: Bundled with Crystal
  • GNU Make & Git
  • cRSTLint (optional, for documentation linting)

Build and Install Locally

# 1. Clone repository
git clone https://gitlab.com/renich/crinit.git
cd crinit

# 2. Compile release binary
make build

# 3. Run full verification quality gates
make check

# 4. Install to ~/.local/bin (or sudo make install for /usr/local/bin)
install -m 0755 bin/crinit ~/.local/bin/crinit

Usage

# Using standard built-in skeletons (100% compatible with crystal init)
crinit app my_application
crinit lib my_library

# Using a custom template installed in your user/system template path
crinit service telemetry_agent

# Using an explicit filesystem template path
crinit --template ~/Projects/crystal/init/app telemetry_agent

# Forcing overwrite or skipping existing files
crinit service telemetry_agent --force
crinit service telemetry_agent --skip-existing

πŸ“‚ Cross-Platform Template Resolution

crinit resolves templates across standard platform directories in the following order:

Priority 1: --template <path>                                (Explicit CLI flag)
Priority 2: CRYSTAL_TEMPLATE_PATH                           (Environment variable, split by Process::PATH_DELIMITER)
Priority 3: ./.crystal/templates/<TYPE>                     (Project/Workspace local)
Priority 4: User Data Directory                             (OS-native user path)
Priority 5: System Data Directory                           (OS-native system path or $ORIGIN-relative)
Priority 6: Built-in Defaults                               (Embedded app / lib fallback)

OS Directory Mappings

PlatformUser Template Directory (Priority 4)System Template Directory (Priority 5)
Linux/BSD$XDG_DATA_HOME/crystal/templates(Fallback: ~/.local/share/crystal/templates)/usr/share/crystal/templates(or $ORIGIN/../share/crystal/templates)
macOS~/Library/Application Support/crystal/templates(Fallback: ~/.local/share/crystal/templates)/opt/homebrew/share/crystal/templates(or /usr/local/share/crystal/templates)
Windows%LOCALAPPDATA%\crystal\templates(Fallback: %USERPROFILE%\.crystal\templates)%ProgramFiles%\Crystal\templates(or $ORIGIN\..\share\crystal\templates)

πŸ› οΈ Template Anatomy & Substitution Tokens

A custom template is simply a directory containing files, directories, and an optional manifest:

~/.local/share/crystal/templates/service/
β”œβ”€β”€ template.yml                  # Optional metadata and variable prompts
β”œβ”€β”€ .editorconfig
β”œβ”€β”€ .gitlab-ci.yml
β”œβ”€β”€ .ameba.yml
β”œβ”€β”€ GNUmakefile
β”œβ”€β”€ LICENSE                       # Use any license you want (GPLv3, Apache-2.0, etc.)
β”œβ”€β”€ shard.yml
β”œβ”€β”€ config/
β”‚   └── database/
β”‚       β”œβ”€β”€ connection.cr
β”‚       └── migrations.cr
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ {{name}}.cr               # Entry point
β”‚   └── {{name}}/
β”‚       β”œβ”€β”€ init.cr               # Initialization logic
β”‚       β”œβ”€β”€ cli.cr
β”‚       └── app.cr
└── spec/
    β”œβ”€β”€ spec_helper.cr
    └── {{name}}_spec.cr

Standard Replacement Tokens

TokenDescriptionSource
{{name}}Normalized project nameUser argument / directory basename
{{module_name}}PascalCase Crystal module identifier (e.g. my-app $\to$ MyApp, foo-bar $\to$ Foo::Bar)Derived algorithm
{{author}}Author full namegit config user.name (fallback: your-name-here)
{{email}}Author email addressgit config user.email (fallback: your-email-here)
{{github_user}}GitHub/GitLab usernamegit config github.user (fallback: your-github-user)
{{year}}Current four-digit yearTime.local.year
{{crystal_version}}Current compiler versionCrystal::VERSION

πŸ—οΈ Build System Targets

The repository includes a standard, FHS-compliant GNUmakefile:

TargetDescription
make buildCompiles optimized release binary to bin/crinit (default)
make specExecutes complete Crystal spec test suite (crystal spec)
make lintRuns Ameba static analysis
make flawRuns Flaw security vulnerability scanner
make rstlintValidates reStructuredText documentation using crstlint
make checkRuns full zero-defect verification gate (spec, lint, flaw, rstlint)
make docsCompiles Sphinx HTML documentation suite
make installInstalls release binary to /usr/local/bin/crinit
make cleanRemoves bin/ build artifacts and documentation build cache

πŸ“š Documentation Suite

Full architectural blueprints, functional specifications, and operational playbooks are maintained under docs/:

GuideScope & HighlightsEntry Point
Business Context & StrategyStakeholder requirements, ROI objectives, and user personas.Business Specs
Functional SpecificationsRequirements [FUNC-001]–[FUNC-008] and behavioral contracts.Functional Specs
Technical ArchitectureProcess architecture, cross-platform matrix, and token engine spec.Technical Specs
Architecture Decisions (ADRs)Immutable logs of architectural decisions and trade-offs.ADR Index
Project RoadmapPhased milestone tracking and bidirectional audit matrix.Project Roadmap
User ManualOperational tutorials and template authoring guides.User Manual

🀝 Contributing & Code of Honor

All contributions must adhere to the Universal Code of Honor and Contributing Guidelines.


πŸ“„ License

  • Software: MIT License (LICENSE).
  • Documentation: GNU Free Documentation License v1.3 or later (LICENSE-DOCS).

Copyright © 2026 Rénich Bon Ćirić <renich@evalinux.com>.


πŸ’– Support & Donations

If you find this project useful and wish to support its ongoing development, please consider donating: