# Component

> Component Layer

- Skill: `harshamendu/component` (Agent Skill, multi-file: 10 files)
- Install (CLI): `npx skillmds@latest add harshamendu/component`
- Raw SKILL.md: https://api.skillmd.com/api/skills/harshamendu/component/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: Harshamendu (https://skillmd.com/u/harshamendu)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/harshamendu/component

---

# Component Layer

> **📝 Note:** This guide uses generic placeholder names to be reusable across any Spring Boot microservice.
> Replace with your actual implementation:
> - `{YourService}` → Your service name (e.g., `OrderService`, `PaymentService`)
> - `BusinessService` → Your core service (e.g., `OrderService`, `UserService`)
> - `DataService` → Your data processing service (e.g., `PaymentService`, `InventoryService`)
> - `IntegrationService` → Your external integration (e.g., `PaymentGatewayService`)
> - `{RequestType}` → Your request DTO (e.g., `CreateOrderRequest`)
> - `{ResponseType}` → Your response DTO (e.g., `OrderResponse`)


## Overview
Spring `@Component` beans that integrate with Spring Boot framework features for type conversion and health monitoring.

**Package**: `com.example.microserviceorch.component.example`

## Component Types

### 1. Type Converters
Automatic conversion of HTTP parameters to domain types via Spring's `ConversionService`.

**Key Interface**: `Converter<String, EnumType>`

### 2. Health Indicators  
Custom health checks that integrate with Spring Boot Actuator for monitoring.

**Key Interface**: `HealthIndicator`

## Quick Examples

### Type Converter
```java
@Component
public class EnumConverter implements Converter<String, EnumType> {
    @Override
    public EnumType convert(String value) {
        return EnumType.fromValue(value);
    }
}
```

### Health Indicator
```java
@Component
public class ServiceHealthIndicator implements HealthIndicator {
    @Autowired 
    private Environment environment;
    
    @Autowired 
    private BuildProperties buildProperties;

    @Override
    public Health health() {
        return Health.up()
            .withDetail("environment", String.join(",", environment.getActiveProfiles()))
            .withDetail("version", buildProperties.getVersion())
            .build();
    }
}
```

## Core Principles

1. **Stateless or Thread-Safe**: Components are singletons
2. **Pure Conversion**: No business logic in converters
3. **Lightweight Health Checks**: Fast metadata retrieval only
4. **Dependency Injection**: Constructor injection preferred
5. **Automatic Registration**: Via component scanning

## Documentation

- [Type Converters Guide](guides/converters.md) - Converter implementation and patterns
- [Health Indicators Guide](guides/health-indicators.md) - Health check integration
- [Testing Guide](guides/testing.md) - Unit and integration tests

## Examples

See `/examples/` for:
- `EnumConverter.java` - String-to-enum converter
- `EnumType.java` - Enum with JSON support
- `ServiceHealthIndicator.java` - Service metadata health check
- `EnumConverterTest.java` - Converter unit tests
- `ServiceHealthIndicatorTest.java` - Health indicator unit tests

## Design Patterns

- **Strategy Pattern**: Different converters for different types
- **Template Method**: HealthIndicator interface
- **Singleton Pattern**: Component scope
- **Adapter Pattern**: Type conversion

## Anti-Patterns

❌ Business logic in converters  
❌ Expensive operations in health checks  
❌ Stateful components without thread safety  
❌ Manual dependency creation

## Code Formatting
All code uses **Spotless** with Google Java Format (AOSP):
```bash
./gradlew spotlessApply
```

