# B2B Flight Ticketing Platform - Quick Start Guide

Get the B2B Flight Ticketing Platform up and running in minutes!

## Prerequisites

- Docker and Docker Compose installed
- Java 17+ (for local development)
- Maven 3.8+ (for building)

## Quick Start with Docker Compose

### 1. Clone and Configure

```bash
# Clone the repository
git clone <repository-url>
cd b2b-flight-platform

# Copy environment template
cp .env.example .env

# Edit .env and add your Amadeus API credentials
# AMADEUS_API_KEY=your_key_here
# AMADEUS_API_SECRET=your_secret_here
# ENCRYPTION_SECRET_KEY=generate_using_EncryptionUtil
```

### 2. Start All Services

```bash
docker-compose up -d
```

This will start:
- PostgreSQL (port 5432)
- Redis (port 6379)
- RabbitMQ (port 5672, management UI on 15672)
- Keycloak (port 8080)
- Application (port 8081)

### 3. Wait for Services to Start

```bash
# Check service status
docker-compose ps

# Watch application logs
docker-compose logs -f app
```

Wait until you see: `Started B2BFlightPlatformApplication`

### 4. Configure Keycloak

```bash
# Access Keycloak Admin Console
open http://localhost:8080

# Login with: admin / admin
# Follow the Keycloak setup in docs/DEPLOYMENT.md
# Or import the realm configuration:
docker-compose exec keycloak /opt/keycloak/bin/kc.sh import \
  --file /opt/keycloak/data/import/realm-config.json
```

### 5. Access the Application

- **API**: http://localhost:8081
- **Swagger UI**: http://localhost:8081/swagger-ui.html
- **Health Check**: http://localhost:8081/actuator/health
- **Keycloak**: http://localhost:8080
- **RabbitMQ Management**: http://localhost:15672 (flight_user/flight_pass)

## Quick Test

### 1. Get Access Token

```bash
curl -X POST http://localhost:8080/realms/b2b-flight-platform/protocol/openid-connect/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "client_id=b2b-flight-backend" \
  -d "client_secret=b2b-flight-backend-secret" \
  -d "username=superadmin" \
  -d "password=your_password" \
  -d "grant_type=password"
```

### 2. Test API

```bash
# Replace {token} with the access token
curl -X GET http://localhost:8081/actuator/health \
  -H "Authorization: Bearer {token}"
```

## Local Development (Without Docker)

### 1. Start Infrastructure

```bash
docker-compose up -d postgres redis rabbitmq keycloak
```

### 2. Build and Run

```bash
# Build
mvn clean package -DskipTests

# Run
java -jar target/b2b-flight-platform-1.0.0-SNAPSHOT.jar
```

Or use Maven:
```bash
mvn spring-boot:run
```

## Next Steps

1. **Configure Keycloak**: See [Keycloak Configuration](docs/DEPLOYMENT.md#keycloak-configuration)
2. **Set up Amadeus API**: See [Amadeus API Setup](docs/DEPLOYMENT.md#amadeus-api-setup)
3. **Explore API**: Open Swagger UI at http://localhost:8081/swagger-ui.html
4. **Read Documentation**:
   - [Deployment Guide](docs/DEPLOYMENT.md)
   - [API Documentation](docs/API_DOCUMENTATION.md)
   - [Resilience Patterns](docs/RESILIENCE_PATTERNS.md)
   - [Transaction Management](docs/TRANSACTION_MANAGEMENT.md)

## Troubleshooting

### Services Won't Start

```bash
# Check logs
docker-compose logs

# Restart services
docker-compose restart

# Clean restart
docker-compose down -v
docker-compose up -d
```

### Port Conflicts

If ports are already in use, edit `docker-compose.yml` to change port mappings.

### Database Connection Issues

```bash
# Check PostgreSQL
docker-compose exec postgres psql -U flight_user -d flight_platform

# View database logs
docker-compose logs postgres
```

## Stopping Services

```bash
# Stop all services
docker-compose down

# Stop and remove volumes (data will be lost)
docker-compose down -v
```

## Getting Help

- Check [Deployment Guide](docs/DEPLOYMENT.md) for detailed instructions
- Review application logs: `docker-compose logs app`
- Check health endpoint: http://localhost:8081/actuator/health
- Review Swagger documentation: http://localhost:8081/swagger-ui.html

## Production Deployment

For production deployment, see:
- [Deployment Guide](docs/DEPLOYMENT.md)
- [Kubernetes Deployment](k8s/README.md)
