Usage Guide
This guide explains how to use Hix for code generation in your projects.
Installation
Hix can be installed through various package managers:
Using Homebrew (macOS/Linux)
brew install hix
Using Chocolatey (Windows)
choco install hix
Using Nix
nix-env -i hix
Using Docker
docker pull hix/hix
Manual Installation
Download the latest release from the releases page and add it to your PATH.
Project Setup
Initialize a New Project
mkdir my-project
cd my-project
hix init
This creates the following structure:
.hix/
├── config.yaml # Configuration file
├── .gitignore # Git ignore rules for generated files
├── models/ # Directory for model files
├── output/ # Directory for generated code
│ ├── Domain/ # Domain layer output
│ ├── Application/ # Application layer output
│ ├── Infrastructure/ # Infrastructure layer output
│ └── Presentation/ # Presentation layer output
└── templates/ # Directory for template files
Basic Usage
1. Create a Model
Create a JSON file describing your model:
{
"className": "User",
"properties": [
{ "name": "Id", "type": "int" },
{ "name": "Name", "type": "string" },
{ "name": "Email", "type": "string" }
]
}
2. Generate Code
Run Hix with your model file:
hix User.json
This will:
1. Load the model from User.json
2. Read the configuration from .hix/config.yaml
3. Generate code for each layer according to the templates
4. Output the generated files in their respective layer directories
Advanced Usage
Interactive Mode
If you run Hix without arguments, it will prompt you for the model name:
hix
# Then enter the model name when prompted
Help and Documentation
- Show basic help:
hix help
orhix --help
- Show detailed manual:
hix man
- Show version:
hix version
orhix --version
Customizing Configuration
Edit .hix/config.yaml
to customize:
- Architecture type (clean, onion, hexagonal)
- Output paths
- Layer configurations
- Template mappings
Examples
Generate a Domain Entity
- Create a model file
User.json
:
{
"className": "User",
"properties": [
{ "name": "Id", "type": "int" },
{ "name": "Name", "type": "string" }
]
}
- Run Hix:
hix User.json
- Check the generated files in
.hix/output/Domain/
Using Templates
- Create a template in
.hix/templates/domain/Entity.hix
:
public class [[model.className]] {
[[prop]]
private [[prop.type]] [[prop.name]];
[[/prop]]
}
- Add the template to your config:
layers:
- name: Domain
path: ./src/Domain
templates:
- name: Entity
filename: [[model.name]].java
template: templates/domain/Entity.hix
- Generate code:
hix User.json
Troubleshooting
Common Issues
- Model Not Found
- Ensure the model file exists and is in the correct location
-
Check file permissions
-
Configuration Errors
- Verify
config.yaml
syntax -
Check template paths are correct
-
Template Errors
- Check template syntax
- Verify all required model fields are present
Getting Help
- Use
hix help
for basic command information - Use
hix man
for detailed documentation - Check the documentation for more information
- Report issues on our GitHub repository
Running Hix
Before running the command, make sure you have created two files:
template.hix
: your Hix templatemodel.json
: your input data model
Once installed, you can use Hix via the command line to render templates with your model data:
hix template.hix model.json
This will parse template.hix
, apply values from model.json
, and output the result to your terminal.
Example Input Files
model.json
{
"className": "User",
"properties": [
{ "name": "Name", "type": "string" },
{ "name": "IsAdmin", "type": "bool" }
]
}
template.hix
public class [[model.className]] {
[[prop]]
[[if prop.type=bool]]
public bool [[prop.name]];
[[else]]
public [[prop.type]] [[snake_case prop.name]];
[[/if]]
[[/prop]]
}
Output
public class User {
public string name;
public bool IsAdmin;
}
Command-Line Arguments
When you run hix template.hix model.json
, the tool uses:
- The template file's extension (e.g.,
.hix
,.cs.hix
,.html.hix
) to determine the output file extension. - The model's
className
as the base name for the output file.
For example:
hix template.cs.hix Person.json
Will produce:
Person.cs
The CLI accepts two positional arguments:
The CLI accepts two positional arguments:
- template file (e.g.
template.hix
) - model file (e.g.
model.json
)
Windows Installer Support
If you installed Hix using the Windows setup wizard, the hix
command will be available in any terminal.
You may need to restart your terminal session after installation to ensure the PATH
update is active.