Skip to content
/ haft Public

⚡ The missing CLI for Spring Boot. Built in Go. Accelerate development with interactive scaffolding, instant REST API boilerplate, and smart dependency management.

License

Notifications You must be signed in to change notification settings

KashifKhn/haft

Repository files navigation

Haft - Spring Boot CLI and Scaffolding Tool

The Spring Boot CLI that Spring forgot to build

Release License Go Report

Documentation · Releases · Report Bug · Discussions


Haft - Interactive CLI for Spring Boot


Table of Contents
  1. The Problem
  2. The Solution
  3. Installation
  4. Quick Start
  5. Features

The Problem

You start a Spring Boot project with Spring Initializr. Great. Now what?

Every new feature means the same tedious ritual:

  • Create UserEntity.java
  • Create UserRepository.java
  • Create UserService.java
  • Create UserServiceImpl.java
  • Create UserController.java
  • Create UserRequest.java
  • Create UserResponse.java
  • Create UserMapper.java

8 files. Every. Single. Time.

Copy-paste from existing code. Fix the class names. Fix the imports. Miss something. Debug. Repeat.

The Solution

haft generate resource User

Done. All 8 files. Properly structured. Matching your project's existing patterns.

Haft Demo

Intelligent Code Generation

Haft doesn't just generate boilerplate — it learns from your codebase and generates code that matches your existing conventions.

What Haft Detects Automatically

Detection What It Does
Architecture Pattern Layered, Feature/Package-by-Feature, Hexagonal, Clean, Modular
Feature Style Flat (user/UserController.java) vs Nested (user/controller/UserController.java)
DTO Naming UserRequest/UserResponse vs UserDTO
ID Type Long vs UUID with correct annotations
Lombok Usage @Data, @Builder, @NoArgsConstructor, @AllArgsConstructor
Mapper Type MapStruct, ModelMapper, or manual mapping
Base Entity Extends your BaseEntity if detected
Validation Style Jakarta (jakarta.validation) vs Javax (javax.validation)
Swagger/OpenAPI Adds @Operation, @Tag annotations if detected
Database Type JPA, MongoDB, Cassandra, R2DBC

Profile Caching

First run scans your project and caches the profile to .haft/profile.json. Subsequent runs are instant.

# First run (~200ms) - scans and caches
haft generate resource User

# Second run (~10ms) - uses cache
haft generate resource Product

# Force re-scan if needed
haft generate resource Order --refresh

Why Haft?

Spring Initializr Haft
Project Bootstrap
Works Offline
Resource Generation
Intelligent Detection
Architecture Aware
Test Generation
Dependency Management
Interactive TUI
Lifecycle Companion

Haft works completely offline. No web browser. No internet dependency. Just you and your terminal.

Install

curl -fsSL https://raw.githubusercontent.com/KashifKhn/haft/main/install.sh | bash

Note: You can inspect the install.sh script before running it. We prioritize security and transparency.

Linux
# AMD64
curl -L https://github.com/KashifKhn/haft/releases/latest/download/haft-linux-amd64.tar.gz | tar xz
sudo mv haft-linux-amd64 /usr/local/bin/haft

# ARM64
curl -L https://github.com/KashifKhn/haft/releases/latest/download/haft-linux-arm64.tar.gz | tar xz
sudo mv haft-linux-arm64 /usr/local/bin/haft
macOS
# Intel
curl -L https://github.com/KashifKhn/haft/releases/latest/download/haft-darwin-amd64.tar.gz | tar xz
sudo mv haft-darwin-amd64 /usr/local/bin/haft

# Apple Silicon
curl -L https://github.com/KashifKhn/haft/releases/latest/download/haft-darwin-arm64.tar.gz | tar xz
sudo mv haft-darwin-arm64 /usr/local/bin/haft
Windows
Invoke-WebRequest -Uri "https://github.com/KashifKhn/haft/releases/latest/download/haft-windows-amd64.zip" -OutFile "haft.zip"
Expand-Archive -Path "haft.zip" -DestinationPath "."
Move-Item "haft-windows-amd64.exe" "$env:LOCALAPPDATA\Microsoft\WindowsApps\haft.exe"

Or download manually from Releases.

Go
go install github.com/KashifKhn/haft/cmd/haft@latest
From Source
git clone https://github.com/KashifKhn/haft.git
cd haft
make build
sudo mv bin/haft /usr/local/bin/
Shell Completions

Enable tab completions for your shell:

# Bash
haft completion bash > /etc/bash_completion.d/haft

# Zsh
haft completion zsh > "${fpath[1]}/_haft"

# Fish
haft completion fish > ~/.config/fish/completions/haft.fish

# PowerShell
haft completion powershell > haft.ps1

Quick Start

Create a New Project

haft init

An interactive wizard guides you through project setup:

? Project name: my-api
? Group ID: com.example  
? Java version: 21
? Spring Boot: 3.4.1
? Dependencies: web, data-jpa, lombok, validation

Generate Resources (Smart Mode)

cd my-app

# Generate a complete CRUD resource
# Haft automatically detects your architecture and conventions
haft generate resource User

Generated files match your project structure:

# If your project uses Feature/Package-by-Feature (flat style):
user/
├── UserController.java
├── UserService.java
├── UserServiceImpl.java
├── UserRepository.java
├── User.java
├── UserMapper.java
└── dto/
    ├── UserRequest.java
    └── UserResponse.java

# If your project uses Layered architecture:
controller/UserController.java
service/UserService.java
service/impl/UserServiceImpl.java
repository/UserRepository.java
entity/User.java
dto/UserRequest.java
dto/UserResponse.java
mapper/UserMapper.java

Generate with Tests

# Generate resource + unit/integration tests
haft generate resource Product

# Skip test generation
haft generate resource Payment --skip-tests

Generated test files:

# ServiceTest - Unit tests with Mockito
# ControllerTest - Integration tests with MockMvc
# RepositoryTest - Integration tests with @DataJpaTest
# EntityTest - Unit tests for entity

Individual Generators

haft generate controller Product   # haft g co Product
haft generate service Order        # haft g s Order
haft generate repository Payment   # haft g repo Payment
haft generate entity Customer      # haft g e Customer
haft generate dto Invoice          # Request + Response DTOs

Generate Security Configuration

# Interactive selection of security types
haft generate security

# Generate JWT authentication
haft generate security --jwt

# Generate session-based authentication
haft generate security --session

# Generate OAuth2 authentication (Google, GitHub, Facebook)
haft generate security --oauth2

# Generate all security types
haft generate security --all

Generated files for JWT:

security/
├── SecurityConfig.java
├── JwtUtil.java
├── JwtAuthenticationFilter.java
├── AuthenticationController.java
├── CustomUserDetailsService.java
└── dto/
    ├── AuthRequest.java
    ├── AuthResponse.java
    ├── RegisterRequest.java
    └── RefreshTokenRequest.java

Manage Dependencies

# Interactive search picker
haft add

# Browse by category
haft add --browse

# Add using shortcuts (330+ available)
haft add lombok validation jwt

# Add using Maven coordinates (auto-verified)
haft add org.mapstruct:mapstruct

# Remove dependencies
haft remove lombok
haft remove   # Interactive picker

Development Workflow

haft dev serve   # Start with hot-reload
haft dev build   # Build project
haft dev test    # Run tests
haft dev clean   # Clean artifacts

Project Analysis

haft info              # Project information
haft info --loc        # With lines of code
haft routes            # List REST endpoints
haft routes --files    # With file locations
haft stats             # Code statistics
haft stats --cocomo    # COCOMO cost estimates

Features

  • Intelligent Detection — Learns from your codebase patterns
  • Architecture Aware — Supports Layered, Feature, Hexagonal, Clean, Modular
  • Test Generation — Unit and integration tests with Mockito, MockMvc
  • Profile Caching — Instant subsequent runs with .haft/profile.json
  • Interactive TUI — Beautiful terminal interface with keyboard navigation
  • Offline First — No internet required, all metadata bundled
  • Smart Defaults — Sensible defaults that match industry standards
  • Back Navigation — Made a mistake? Press Esc to go back
  • Dependency Search — Find any dependency with /
  • Maven Central Verification — Auto-verify and fetch latest versions

Keyboard Shortcuts

Key Action
Navigate
Enter Select
Esc Go back
Space Toggle
/ Search
Tab Next category
0-9 Jump to category

Supported Architectures

Haft automatically detects and generates code for:

Architecture Description
Layered Traditional controller/, service/, repository/, entity/
Feature Package-by-feature with nested or flat structure
Hexagonal Ports & Adapters with adapter/, application/, domain/
Clean Clean Architecture with usecase/, gateway/, infrastructure/
Modular Modular monolith with api/, internal/

Roadmap

  • Project initialization wizard
  • All Spring Initializr dependencies
  • Maven & Gradle support
  • Intelligent architecture detection
  • Test generation
  • Profile caching
  • haft generate resource — Full CRUD generation
  • haft add / haft remove — Dependency management
  • haft dev — Development commands
  • haft info / haft routes / haft stats — Project analysis
  • Shell completions (bash, zsh, fish, powershell)
  • Security configuration (JWT, Session, OAuth2)
  • Custom templates
  • Neovim integration
  • VS Code extension
  • IntelliJ plugin

Built With

  • Go - High-performance compiled binary.
  • Bubble Tea - The TUI framework.
  • Cobra - CLI command structure.

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

License

MIT License. See LICENSE for details.


Built for developers who value their time