An AI-powered travel assistant chat application built with Ktor and Kotlin Multiplatform. This application provides personalized travel recommendations, information, and advice through a conversational interface.
This project demonstrates how to build a modern AI-powered chat application using Kotlin and Ktor. It features:
- A travel agency assistant that provides personalized travel recommendations
- Real-time chat interface using WebSockets and Server-Sent Events (SSE)
- AI-powered responses using OpenAI models via LangChain4j
- Retrieval Augmented Generation (RAG) for enhanced responses with domain-specific knowledge
- Conversation memory to maintain context across messages
- OAuth authentication (with Keycloak)
- Metrics tracking for AI question answering
- Ktor: Kotlin asynchronous web framework
- LangChain4j: Java/Kotlin library for working with large language models
- OpenAI: AI models for generating responses
- Exposed: Kotlin SQL framework for database access
- Flyway: Database migration tool
- Kotlinx.serialization: JSON serialization/deserialization
- WebSockets & SSE: For real-time communication
- Keycloak: For OAuth authentication and authorization
- Kotlin Multiplatform: For sharing code between platforms
- Compose Multiplatform: For cross-platform UI development
- Ktor Client: For WebSocket and HTTP communication with the server
- Docker: For containerization and deployment
- Gradle: For build automation
- Grafana: For metrics visualization
- PostgreSQL: For data storage
- Nginx: For reverse proxy and routing
The application follows a modular architecture:
- AI Module: Handles interaction with OpenAI models and document retrieval
- Chat Module: Manages WebSocket/SSE connections and message routing
- Security Module: Handles OAuth authentication with Keycloak
- Admin Module: Provides administrative functions for document management
- ComposeApp Module: Implements the cross-platform user interface
The application uses Retrieval Augmented Generation (RAG) to enhance AI responses with domain-specific knowledge. It can ingest documents to build a knowledge base that the AI can reference when answering questions.
The project follows a multi-module setup:
app
: Main server application with KtorcomposeApp
: Cross-platform UI using Compose Multiplatformlangchain4j-kotlinx-coroutines
: Custom extensions for LangChain4j with Kotlin coroutines support
The project uses a version catalog (see gradle/libs.versions.toml
) to declare and version dependencies.
- JDK 17 or higher
- Docker and Docker Compose
./gradlew build
The database is automatically set up when running with Docker Compose. The application uses Flyway to manage database migrations.
- Start the Docker services:
cd docker
docker-compose up -d
- Run the server:
./gradlew run
- The UI is available at http://localhost
- Login with the credentials configured in Keycloak (user: ktor_user, pw: ktor_password)
You can ask the travel assistant questions like:
- "What are some good destinations for a family vacation in Europe?"
- "I'm planning a trip to Japan in April. What should I know?"
- "What's the best way to travel between Paris and London?"
The application can be deployed using Docker Compose:
cd docker
docker-compose up -d
This will start:
- PostgreSQL database
- Grafana for monitoring
- Keycloak for authentication
- Nginx as a reverse proxy
Configuration options can be modified in:
app/src/main/resources/application.yaml
docker/docker-compose.yml
docker/nginx.conf
- Relies on TestContainers to start Postgres
./gradlew test
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.