# WCAG-ADA Configuration

Centralized configuration management for the WCAG-ADA compliance platform, built on top of the core configuration system.

## Overview

This configuration system provides:
- Type-safe configuration with Zod schemas
- Multi-source configuration (JSON files + environment variables)
- Environment-specific overrides
- Service-specific configurations
- Feature flags management

## Usage

### Basic Usage

```typescript
import { initializeWcagConfig, getWcagConfig } from '@wcag-ada/config';

// Initialize configuration (do this once at app startup)
const config = initializeWcagConfig('api'); // 'api' | 'dashboard' | 'worker'

// Access configuration values
console.log(config.services.api.port); // 3001
console.log(config.scanner.concurrency); // 2
```

### Helper Functions

```typescript
import { 
  getScannerConfig,
  getWorkerConfig,
  isFeatureEnabled,
  getServiceConfig
} from '@wcag-ada/config';

// Get specific configurations
const scannerConfig = getScannerConfig();
const workerConfig = getWorkerConfig();

// Check feature flags
if (isFeatureEnabled('screenshots')) {
  // Screenshot feature is enabled
}

if (isFeatureEnabled('reports.pdf')) {
  // PDF reports are enabled
}

// Get service configuration
const apiConfig = getServiceConfig('api');
```

## Configuration Structure

### Scanner Configuration
- `concurrency`: Number of concurrent scans (1-10)
- `timeout`: Maximum scan duration
- `headless`: Run browser in headless mode
- `blockResources`: Block images/fonts for faster scans
- `viewport`: Default viewport dimensions

### Worker Configuration
- `concurrency`: Number of concurrent jobs
- `queueName`: BullMQ queue name
- `redis`: Redis connection settings
- `jobs`: Job-specific configurations
- `scheduler`: Scheduled job settings

### Features Configuration
- `screenshots`: Screenshot capture settings
- `customRules`: Custom accessibility rules
- `multiPage`: Multi-page scanning
- `reports`: Report generation features
- `integrations`: External service integrations
- `enterprise`: Enterprise features (SSO, white-label)

### Providers Configuration
- `storage`: File storage (local, S3, GCS, Azure)
- `email`: Email providers (SMTP, SendGrid, SES)
- `auth`: Authentication settings (JWT, OAuth)
- `analytics`: Analytics providers
- `cdn`: CDN configuration

## Environment Variables

The system supports environment variable overrides with the `WCAG_` prefix:

```bash
# Scanner settings
WCAG_SCANNER_CONCURRENCY=5
WCAG_SCANNER_TIMEOUT=180000
WCAG_SCANNER_HEADLESS=true

# Worker settings
WCAG_WORKER_CONCURRENCY=3
WCAG_WORKER_REDIS_HOST=redis.example.com
WCAG_WORKER_REDIS_PORT=6379

# Service ports
WCAG_SERVICES_API_PORT=3001
WCAG_SERVICES_DASHBOARD_PORT=3000

# Storage
WCAG_PROVIDERS_STORAGE_TYPE=s3
WCAG_PROVIDERS_STORAGE_S3_BUCKET=wcag-ada-storage
WCAG_PROVIDERS_STORAGE_S3_REGION=us-east-1

# Authentication
WCAG_PROVIDERS_AUTH_JWT_SECRET=your-secret-key
```

## Configuration Files

Configuration files are loaded in this order (later files override earlier ones):
1. `config/default.json` - Base configuration
2. `config/{environment}.json` - Environment-specific (development, production, test)
3. Environment variables - Highest priority

## Service-Specific Configuration

Each service can have its own configuration:

```typescript
// API Service
initializeWcagConfig('api');
// Uses services.api configuration

// Dashboard
initializeWcagConfig('dashboard');
// Uses services.dashboard configuration

// Worker
initializeWcagConfig('worker');
// Uses services.worker configuration
```

## Adding New Configuration

1. Add schema definition in `src/schemas/`
2. Update `wcag-app.schema.ts` to include new schema
3. Add default values in `config/default.json`
4. Add environment-specific overrides as needed
5. Create helper functions in `src/index.ts` for easy access

## Examples

### Check Subscription Limits

```typescript
import { getSubscriptionConfig } from '@wcag-ada/config';

const starterLimits = getSubscriptionConfig('starter');
console.log(starterLimits.websites); // 5
console.log(starterLimits.scansPerMonth); // 500
```

### Get Compliance Settings

```typescript
import { getComplianceConfig } from '@wcag-ada/config';

const compliance = getComplianceConfig();
console.log(compliance.defaultLevel); // { standard: 'WCAG21', level: 'AA' }
console.log(compliance.criticalCriteria); // ['1.1.1', '1.3.1', ...]
```

### Storage Configuration

```typescript
import { getStorageConfig } from '@wcag-ada/config';

const storage = getStorageConfig();
if (storage.type === 's3') {
  // Use S3 storage
} else {
  // Use local storage
}
```