Skip to main content

haft doctor

Analyze your Spring Boot project for issues, warnings, and suggestions.

Usage

haft doctor [flags]
haft doc [flags] # Alias
haft check [flags] # Alias
haft health [flags] # Alias

Description

The doctor command performs comprehensive health checks on your Spring Boot project. It identifies problems early and suggests improvements to help you maintain a healthy codebase.

Health Checks

Build Checks

CheckSeverityDescription
build_fileErrorBuild file exists (pom.xml or build.gradle)
spring_boot_configErrorSpring Boot parent/plugin is configured
java_versionWarningJava version is specified (warns for Java 8)

Source Checks

CheckSeverityDescription
source_directoryErrorSource directory exists (src/main/java or src/main/kotlin)
test_directoryWarningTest directory exists (src/test/java or src/test/kotlin)
main_classErrorMain class with @SpringBootApplication found

Configuration Checks

CheckSeverityDescription
config_fileWarningConfiguration file exists (application.yml/properties)
hardcoded_secretsErrorNo hardcoded passwords, secrets, or API keys

Security Checks

CheckSeverityDescription
h2_scopeWarningH2 database not in compile scope
devtools_scopeWarningDevTools marked as optional

Dependency Checks

CheckSeverityDescription
test_dependenciesWarningspring-boot-starter-test is present
suggest_actuatorSuggestionConsider adding Actuator for monitoring
suggest_validationSuggestionConsider adding Validation for input validation
suggest_openapiSuggestionConsider adding OpenAPI for API documentation

Best Practice Checks

CheckSeverityDescription
lombok_configInfoLombok configured with lombok.config

Flags

FlagDescription
--jsonOutput results as JSON (for CI/CD pipelines)
--strictExit with code 1 on any warning
--categoryFilter by category (build, source, config, security, dependencies, best-practice, docker)

Examples

# Run full health check
haft doctor

# Output as JSON (for CI/CD)
haft doctor --json

# Strict mode (exit 1 on warnings)
haft doctor --strict

# Filter by category
haft doctor --category security
haft doctor --category build
haft doctor --category dependencies

Output Format

Standard Output

🏥 Haft Doctor - Project Health Check
=============================================

Project: my-app
Path: /path/to/my-app
Build Tool: Maven

Passed Checks:
✓ Build file exists (Maven)
✓ Spring Boot configured
✓ Java 17 configured
✓ Source directory exists (Java)
✓ Main class with @SpringBootApplication found
✓ Configuration file found (application.yml)
✓ No hardcoded secrets detected
✓ Test dependencies configured

Warnings:
⚠ H2 database in compile scope
H2 should be test or runtime scope only
→ Change H2 scope to <scope>runtime</scope> or testImplementation

Suggestions:
💡 Consider adding Actuator
Actuator provides health checks, metrics, and monitoring endpoints
→ Run: haft add actuator

---------------------------------------------
Summary: 8 passed, 1 warnings, 2 suggestions

JSON Output

{
"project_path": "/path/to/my-app",
"project_name": "my-app",
"build_tool": "Maven",
"results": [
{
"name": "build_file",
"category": "build",
"passed": true,
"severity": "error",
"message": "Build file exists (Maven)"
},
{
"name": "h2_scope",
"category": "security",
"passed": false,
"severity": "warning",
"message": "H2 database in compile scope",
"details": "H2 should be test or runtime scope only",
"fix_hint": "Change H2 scope to <scope>runtime</scope>"
}
],
"passed_count": 8,
"error_count": 0,
"warning_count": 1,
"suggestion_count": 2
}

Exit Codes

CodeMeaning
0All checks passed (or only warnings/suggestions in non-strict mode)
1Health check failed (errors found, or warnings in strict mode)

Use Cases

Pre-commit Hook

#!/bin/bash
haft doctor --strict || exit 1

CI Pipeline

# GitHub Actions
- name: Check project health
run: haft doctor --json > health-report.json

- name: Fail on issues
run: haft doctor --strict

Quick Security Check

haft doctor --category security

Check Before Release

haft doctor --strict

Categories

Filter checks by category using --category:

  • build - Build file and configuration checks
  • source - Source code structure checks
  • config - Configuration file checks
  • security - Security-related checks
  • dependencies - Dependency recommendations
  • best-practice - Best practice suggestions

Editor Integration

Use this command from your editor:

  • Neovim: Not yet available in haft.nvim (CLI only)
  • VS Code: Coming soon (preview →)
  • IntelliJ IDEA: Coming soon (preview →)

See Also