Skip to content

Eomm/opensearch-vibe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fastify + OpenSearch UBI Hello World App

A minimal "Hello World" web application using Node.js with the Fastify v5 framework, containerized with Docker, and integrated with OpenSearch v3 User Behavior Insights (UBI) plugin.

Project Structure

project-root/
├── app/
│   ├── index.js          # Main Fastify application
│   ├── package.json      # Node.js dependencies
│   └── ubiClient.js      # OpenSearch UBI client
├── Dockerfile            # Docker configuration for the app
├── docker compose.yml    # Multi-service Docker setup
└── README.md            # This file

Features

  • Fastify v5 Web Server: Latest version of the lightweight and fast web framework
  • Hello World Endpoint: GET / returns { message: "Hello World" }
  • OpenSearch v3 Integration: Sends UBI events to the latest OpenSearch version
  • Docker Containerization: Both app and OpenSearch run in containers
  • Health Checks: Built-in health monitoring for services

API Endpoints

  • GET / - Returns Hello World message and logs a UBI event
  • GET /health - Health check endpoint
  • GET /opensearch-status - Check OpenSearch connection status

Version Information

This project uses the latest versions:

  • Fastify v5: Latest major version with improved performance and ESM support
  • OpenSearch v3: Latest version with enhanced features and performance improvements
  • Node.js 20+: Required for Fastify v5 compatibility
  • OpenSearch Client v3: Latest JavaScript client for OpenSearch v3

Prerequisites

  • Docker and Docker Compose installed on your system
  • At least 2GB of available RAM (for OpenSearch v3)
  • Node.js 20+ (if running locally without Docker)

Quick Start

1. Build and Run the Application

# Clone or navigate to the project directory
cd /path/to/your/project

# Build and start all services
docker compose up --build

# Or run in detached mode
docker compose up --build -d

2. Verify the Application

Check if services are running:

docker compose ps

Test the Hello World endpoint:

curl http://localhost:3000/
# Expected response: {"message":"Hello World"}

Check application health:

curl http://localhost:3000/health

Verify OpenSearch connection:

curl http://localhost:3000/opensearch-status

3. Verify OpenSearch

Check OpenSearch is accessible:

curl http://localhost:9200

Check OpenSearch cluster health:

curl http://localhost:9200/_cat/health

View UBI events (after accessing the / endpoint):

curl http://localhost:9200/ubi-events/_search?pretty

4. Access OpenSearch Dashboards (Optional)

OpenSearch Dashboards is available at: http://localhost:5601

How It Works

  1. Application Startup: The Fastify app starts and waits for OpenSearch to be ready
  2. UBI Integration: When the / endpoint is accessed, the app:
    • Returns the Hello World message
    • Sends a mock UBI event to OpenSearch
  3. Event Logging: UBI events are stored in the ubi-events index in OpenSearch

Mock UBI Event Structure

{
  "timestamp": "2025-07-22T10:30:00.000Z",
  "user_id": "user123",
  "session_id": "session456",
  "action": "page_view",
  "object_type": "web_page",
  "object_id": "hello_world_page",
  "query": null,
  "position": null,
  "metadata": {
    "page": "/",
    "user_agent": "fastify-app/1.0.0",
    "message": "Hello World page accessed"
  }
}

Environment Variables

The following environment variables can be configured:

  • PORT: Application port (default: 3000)
  • HOST: Application host (default: 0.0.0.0)
  • OPENSEARCH_URL: OpenSearch endpoint (default: http://opensearch:9200)
  • OPENSEARCH_USERNAME: OpenSearch username (default: admin)
  • OPENSEARCH_PASSWORD: OpenSearch password (default: admin)

Development

Running Locally (without Docker)

  1. Install dependencies:
cd app
npm install
  1. Start OpenSearch separately:
docker compose up opensearch -d
  1. Run the application:
cd app
OPENSEARCH_URL=http://localhost:9200 npm start

Logs

View application logs:

docker compose logs app -f

View OpenSearch logs:

docker compose logs opensearch -f

View all service logs:

docker compose logs -f

Stopping the Application

# Stop all services
docker compose down

# Stop and remove volumes (clears OpenSearch data)
docker compose down -v

Troubleshooting

Common Issues

  1. Port conflicts: Make sure ports 3000, 9200, and 5601 are not in use
  2. Memory issues: OpenSearch requires at least 2GB RAM
  3. Connection timeouts: Wait for health checks to pass before testing

Check Service Status

# Check if containers are running
docker ps

# Check service health
docker compose ps

# View container logs
docker compose logs [service-name]

Reset Everything

# Stop all services and remove volumes
docker compose down -v

# Remove images (optional)
docker compose down --rmi all

# Rebuild and restart
docker compose up --build

Next Steps

  • Implement real user authentication for UBI events
  • Add more sophisticated UBI event types
  • Configure OpenSearch security
  • Add monitoring and alerting
  • Implement proper logging and error handling
  • Explore Fastify v5's new features like ESM support and improved TypeScript integration
  • Leverage OpenSearch v3's enhanced performance and new features

About

Vibecoded

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors