# Platform Constraints

Validation rules and predicates for configuration values.

## Constraint Files

### Common (`common.ncl`)

General validation rules applicable to all services:

**Port constraints:**
- `valid_port(port)` - Check if port is in valid range (1024-65535)

**String enumeration constraints:**
- `valid_log_level(level)` - Check against valid log levels
- `valid_auth_method(method)` - Check against valid auth methods
- `valid_storage_backend(backend)` - Check against valid backends
- `valid_deployment_mode(mode)` - Check against deployment modes
- `valid_llm_provider(provider)` - Check against LLM providers

**Numeric constraints:**
- `valid_budget_threshold(percent)` - Check percentage is 0-100
- `valid_worker_count(count)` - Check worker count is in range
- `valid_connection_count(count)` - Check connection count is valid

**URL constraints:**
- `valid_url(url)` - Check URL has valid protocol scheme

## Usage Pattern

```nickel
let constraints = import "constraints/common.ncl" in

# Validate port
assert constraints.valid_port 8080

# Validate enum
assert constraints.valid_log_level "debug"

# In a record definition (using Nickel contracts)
{
  port | Number | doc "Server port" | {
    predicate = fun p => constraints.valid_port p,
    label = "valid port range"
  } = 8080
}
```

## Constraint Philosophy

Constraints are **predicates** - functions that return true/false for validation:

- Used in Nickel's contract system: `field | Type | {predicate = constraint_fn}`
- Enable **gradual validation** - catch errors at config generation time
- Prevent invalid configurations reaching runtime
- Document valid value ranges inline

## References

- Parent: `../README.md`
- Validators: `../validators/README.md`
- Values: `../values/README.md`
