# Address Validation Service

This is a simple address validation service for the Postaci application, designed to validate Swiss addresses.

## Features

- Validates and formats Swiss addresses
- Extracts street name, house number, postal code, and city
- Identifies Swiss cantons based on postal code prefixes
- Provides confidence scores for validation results
- Returns standardized address format
- Mock street lookup for testing

## Setup & Running

1. Install dependencies:
   ```
   npm install
   ```

2. Start the server:
   ```
   npm start
   ```
   
   For development with auto-restart:
   ```
   npm run dev
   ```

## Starting the Development Environment

A startup script has been created to launch both the validation service and the Next.js application:

```bash
# From the project root
./start-dev.sh
```

This will:
1. Start the validation service in the background
2. Launch the Next.js application
3. Automatically stop the validation service when Next.js is terminated

## API Endpoints

### Validate Address
- **URL**: `/api/validate-address`
- **Method**: `POST`
- **Body**: `{ "address": "Your address string" }`
- **Response**: Returns a formatted address string if valid, or the original address if validation fails

### Detailed Address Validation
- **URL**: `/api/validate-address/detailed`
- **Method**: `POST`
- **Body**: `{ "address": "Your address string" }`
- **Response**: Returns a detailed validation result with components, confidence score, and validity

### Address Lookup (Mock)
- **URL**: `/api/address-lookup`
- **Method**: `GET`
- **Query Parameters**: `postalCode` or `city`
- **Response**: Returns a list of streets for the given postal code or city

### Health Check
- **URL**: `/api/health`
- **Method**: `GET`
- **Response**: `{ "status": "up", "message": "Address validation service is running" }`

## Testing the Service

You can test the service using curl:

```bash
# Health check
curl http://localhost:8000/api/health

# Validate an address
curl -X POST http://localhost:8000/api/validate-address \
  -H "Content-Type: application/json" \
  -d '{"address": "Luzernstrasse 27, 4552 Derendingen"}'

# Get detailed validation
curl -X POST http://localhost:8000/api/validate-address/detailed \
  -H "Content-Type: application/json" \
  -d '{"address": "Luzernstrasse 27, 4552 Derendingen"}'

# Get streets in Zürich
curl "http://localhost:8000/api/address-lookup?postalCode=8000"
```

## Swiss Address Format

The validation service understands the standard Swiss address format:
- Street name + house number (e.g., "Bahnhofstrasse 10")
- Four-digit postal code + city (e.g., "8001 Zürich")
- Canton identification from postal code prefix