Skip to content

Nhucanada/Barline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

196 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍸 Barline - CodeJam 15 Best UI/UX Winner

Your personal AI-powered virtual bartender

A 90's inspired retro video game-style web application where you chat with Arthur, a PS1-style 3D bartender who crafts custom cocktails right before your eyes using Three.js and AI.

Watch our video demonstrating Arthur's capabilities here.


🎯 Overview

Barline is an immersive virtual bartending experience that combines:

  • AI-Powered Conversations: Chat naturally with Arthur, your virtual bartender, powered by Google Gemini
  • Real-Time 3D Rendering: Watch your drink come to life with realistic liquid physics, ice cubes, and garnishes
  • Smart Cocktail Generation: Create custom drinks, search by ingredients, or get personalized recommendations
  • Personal Cocktail Library: Save your favorite recipes with detailed ingredients and instructions
  • Retro Aesthetic: Nostalgic 90's video game style with PS1-era low-poly graphics

✨ Features

πŸ€– AI Bartender Chat

  • Real-time WebSocket communication with Arthur
  • Natural language drink requests and conversations
  • Context-aware responses using RAG (Retrieval-Augmented Generation)
  • Intelligent action routing: create, search, or suggest drinks

🎨 Immersive 3D Experience

  • 10 Different Glass Types: Martini, rocks, highball, shot, hurricane, zombie, and more
  • Realistic Liquid Physics: Animated pour with color mixing and surface effects
  • Dynamic Garnishes: Mint leaves, lemon wedges, cherries with gravity animations
  • Ice Cube System: Staggered falling animations with bobbing physics
  • PS1-Style Graphics: Low-poly bartender character in a retro sci-fi bar environment
  • Sound Effects: Synchronized pour and ice sounds

πŸ“š Cocktail Management

  • Save drinks to your personal shelf
  • Browse your collection with visual cards
  • View detailed recipes with ingredients and instructions
  • Duplicate detection to keep your shelf organized

πŸ” User Authentication

  • Secure email/password authentication via Supabase
  • Automatic JWT token refresh (every 4 minutes)
  • Session management with logout confirmation

πŸ›  Tech Stack

Frontend

Technology Purpose
Three.js 3D graphics rendering and scene management
TypeScript Type-safe application development
Vite Fast build tool and dev server
Tween.js Smooth animations for liquid and physics
WebSocket Real-time bidirectional communication

Backend

Technology Purpose
Python+ Core backend language
FastAPI Modern async web framework
Uvicorn ASGI server for FastAPI
Pydantic Data validation and serialization

Database & Storage

Technology Purpose
Supabase (PostgreSQL) Primary database with auth
pgvector Vector database for semantic search
Supabase Storage Asset storage for RAG documents

AI & ML

Technology Purpose
Google Gemini API LLM for conversational AI (gemini-2.0-flash)
scikit-learn Cosine similarity for RAG retrieval
Custom Agent Engine RAG + Few-Shot + Chain-of-Thought orchestration

DevOps

Technology Purpose
Docker Containerization
docker-compose Multi-container orchestration
pnpm Fast, disk-efficient package manager

πŸ— Architecture

Agentic AI Core

Barline uses a sophisticated multi-layered AI system for intelligent cocktail creation:

User Message β†’ Prompt Selection β†’ RAG Augmentation β†’ Few-Shot Examples β†’ Gemini API β†’ Structured Output

Components:

  1. Prompt System (apps/backend/src/infra/agent_core/prompt.py)

    • Composable prompt builder with RAG support
    • Modular segments for system instructions, task descriptions, and examples
  2. Prompt Prototypes (apps/backend/src/infra/agent_core/prototypes.py)

    • Pre-built templates: action_generation, retrieval_augmented, chat_style, etc.
    • Chain-of-Thought (CoT) structured prompts for better reasoning
  3. RAG Strategy (apps/backend/src/infra/agent_core/rag.py)

    • Vector similarity search over cocktail knowledge base
    • Top-K retrieval (default: 5 chunks) for context augmentation
    • Reduces hallucinations by 2-4x
  4. Few-Shot Learning (apps/backend/src/infra/agent_core/examples/)

    • Example-driven action selection (create, search, suggest)
    • Reduces invalid JSON by 2-5x
    • Improves action selection accuracy by 1.5-2.5x
  5. Agentic Engine (apps/backend/src/infra/agent_core/engine.py)

    • Fast heuristic template selection
    • Structured JSON output via Pydantic schemas
    • Streaming support for real-time responses

Performance Multipliers:

  • RAG: 2-4x reduction in hallucinations, 1.5-3x higher task success
  • Few-Shot: 2-5x reduction in invalid JSON, 1.5-2.5x better action selection
  • Chain-of-Thought: 1.5-3x better on complex reasoning
  • Combined: 2-4x end-to-end task success, 2-5x reduction in bad responses

3D Rendering Pipeline

Backend Recipe β†’ DrinkMapper β†’ Three.js Scene Update β†’ Animations (Liquid/Ice/Garnish)
  1. Backend sends DrinkRecipeSchema with glass type, garnish, ingredients
  2. drinkMapper.ts converts to frontend CocktailConfig
  3. GlassLoader switches to appropriate glass model
  4. LiquidHandler calculates color and animates pour
  5. IceLoader drops ice cubes with staggered timing (150ms delays)
  6. GarnishLoader adds garnish after ice settles
  7. Sound effects synchronized with animations

WebSocket Chat Flow

Client β†’ [USER]: message β†’ Server β†’ Agent Engine β†’ Stream Response β†’ Client UI Update
  • Client maintains conversation history (last 50 messages)
  • Server validates JWT token on connection
  • Streaming responses with stream_start, stream_delta, stream_end events
  • Agent metadata includes action type, reasoning, and created cocktails

πŸš€ Getting Started

Prerequisites

Option 1: Local Development

1. Install Root Dependencies

pnpm install

2. Install Frontend Dependencies

cd apps/frontend
pnpm install

3. Install Backend Dependencies

cd apps/backend
pip3 install -e .
# Or using the requirements file:
pip3 install -r ../../requirements.txt

4. Configure Environment Variables

Create apps/backend/.env:

# Supabase
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-anon-key-here
SUPABASE_JWT_SECRET=your-jwt-secret-here

# Google Gemini
GEMINI_API_KEY=your-gemini-api-key

# App Settings
APP_NAME=Arthur API
APP_VERSION=1.0.0
DEBUG=false

# CORS (for local dev)
CORS_ORIGINS=http://localhost:5173

5. Run Backend

cd apps/backend
uvicorn src.main:app --reload --port 8000

Backend will be available at: http://localhost:8000

6. Run Frontend (New Terminal)

cd apps/frontend
pnpm dev

Frontend will be available at: http://localhost:5173

Option 2: Docker Deployment

1. Configure Environment

Create apps/backend/.env (same as above)

2. Start Services

cd infra
docker-compose up

Services will be available at:

  • Frontend: http://localhost:5173
  • Backend: http://localhost:8000

3. Stop Services

cd infra
docker-compose down

πŸ“ Access Points

Service URL Description
Frontend http://localhost:5173 Main application UI
Backend API http://localhost:8000 REST API endpoints
API Docs (Swagger) http://localhost:8000/docs Interactive API documentation
API Docs (ReDoc) http://localhost:8000/redoc Alternative API docs

πŸ”§ Environment Variables

Required Variables

Variable Description Example
SUPABASE_URL Your Supabase project URL https://abc123.supabase.co
SUPABASE_KEY Supabase anonymous key eyJhbG...
SUPABASE_JWT_SECRET JWT secret from Supabase settings your-secret-key
GEMINI_API_KEY Google Gemini API key AIza...

Optional Variables

Variable Default Description
APP_NAME Arthur API Application name
APP_VERSION 1.0.0 API version
DEBUG false Enable debug logging
CORS_ORIGINS http://localhost:5173 Allowed CORS origins (comma-separated)

WebSocket Chat

Endpoint: ws://localhost:8000/api/v1/chat/ws?token=<access_token>

Message Types:

  • user - User message to Arthur
  • stream_start - Response stream begins
  • stream_delta - Partial response chunk
  • stream_end - Complete response with agent action metadata
  • error - Error message

Example Message Flow:

// Client sends
{
  "content": "Make me a refreshing summer cocktail",
  "conversation_history": "[USER]: Hello\n[ASSISTANT]: Hi! ..."
}

// Server streams back
{ "type": "stream_start" }
{ "type": "stream_delta", "content": "I'd be " }
{ "type": "stream_delta", "content": "happy to " }
{
  "type": "stream_end",
  "content": "I'd be happy to make you a Mojito!",
  "agent_action": {
    "action_type": "create_drink",
    "reasoning": "User requested refreshing summer drink",
    "created_cocktail": { /* DrinkRecipeSchema */ }
  }
}

🎨 3D Scene Components

Glass Types (10 Available)

Glass ID Type Best For
zombie_glass_0 Tall tiki glass Tropical drinks, zombies
cocktail_glass_1 Classic cocktail Martinis, cosmopolitans
rocks_glass_2 Short tumbler Old fashioned, whiskey
hurricane_glass_3 Curved tropical PiΓ±a coladas, hurricanes
pint_glass_4 Beer pint Beer, hard cider
seidel_Glass_5 Beer stein German beers, oktoberfest
shot_glass_6 Small shot Shots, shooters
highball_glass_7 Tall mixed drink Mojitos, Tom Collins
margarita_glass_8 Wide bowl Margaritas, daiquiris
martini_glass_9 V-shaped Classic martinis

Rendering Features

  • Liquid System: Color mixing, animated fills, realistic surface materials
  • Ice Physics: Gravity-based falling, bobbing motion, glass-specific positioning
  • Garnishes: GLTF models for mint, lemon, cherry with coordinated timing
  • Audio: Pour and ice SFX synchronized with animations
  • Lighting: Atmospheric fog and PS1-style lighting
  • Environment: Retro sci-fi bar with wood floor textures

πŸ“‚ Project Structure

CodeJam-15/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/                 # Python FastAPI backend
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ api/v1/         # Route handlers (auth, chat, cocktails)
β”‚   β”‚   β”‚   β”œβ”€β”€ core/           # Config and dependencies
β”‚   β”‚   β”‚   β”œβ”€β”€ domain/         # Pydantic models and schemas
β”‚   β”‚   β”‚   β”œβ”€β”€ infra/          # Infrastructure layer
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ agent_core/ # RAG + LLM agent engine
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ engine.py
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ prompt.py
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ prototypes.py
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ rag.py
β”‚   β”‚   β”‚   β”‚   β”‚   └── examples/  # Few-shot examples
β”‚   β”‚   β”‚   β”‚   └── repositories/  # Database access
β”‚   β”‚   β”‚   β”œβ”€β”€ services/       # Business logic
β”‚   β”‚   β”‚   └── main.py         # FastAPI app entry
β”‚   β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”‚   └── pyproject.toml
β”‚   β”‚
β”‚   β”œβ”€β”€ frontend/               # Three.js/TypeScript frontend
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ api/           # Backend API client
β”‚   β”‚   β”‚   β”œβ”€β”€ assets/        # Audio, textures
β”‚   β”‚   β”‚   β”œβ”€β”€ components/    # UI components (login, shelf)
β”‚   β”‚   β”‚   β”œβ”€β”€ models/        # GLTF 3D models
β”‚   β”‚   β”‚   β”œβ”€β”€ scene/         # Three.js scene components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BarLoader.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CharacterLoader.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ GlassLoader.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LiquidHandler.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ IceLoader.ts
β”‚   β”‚   β”‚   β”‚   └── GarnishLoader.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/            # SVG icons and UI elements
β”‚   β”‚   β”‚   β”œβ”€β”€ utils/         # Helpers and mappers
β”‚   β”‚   β”‚   β”œβ”€β”€ websocket/     # WebSocket client
β”‚   β”‚   β”‚   └── main.ts        # App entry point
β”‚   β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── test/                   # Testing utilities
β”‚
β”œβ”€β”€ infra/
β”‚   └── docker-compose.yml      # Docker orchestration
β”‚
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ utils-py/              # Shared Python utilities
β”‚   └── utils-ts/              # Shared TypeScript utilities
β”‚
β”œβ”€β”€ requirements.txt           # Python dependencies
└── package.json              # Root package file

πŸ§ͺ Development

Running Tests

# WebSocket test
cd apps/test
python test_websocket.py

# Backend tests
cd apps/backend
python test_few_shot_examples.py

Common Commands

# Frontend
pnpm dev              # Start dev server
pnpm build            # Build for production
pnpm preview          # Preview production build

# Backend
uvicorn src.main:app --reload  # Start with hot reload
uvicorn src.main:app --port 8000  # Specify port

# Docker
docker-compose up              # Start all services
docker-compose up -d           # Start in detached mode
docker-compose down            # Stop all services
docker-compose logs -f backend # View backend logs

Database Schema

Core Tables:

  • cocktail - Cocktail recipes
  • ingredient - Ingredient master data with ABV and colors
  • garnish - Garnish types and assets
  • glass - Glass types and 3D models
  • user_cocktails - User's saved cocktails (junction table)
  • cocktail_ingredient - Cocktail ingredients with quantities
  • cocktail_garnish - Cocktail garnishes
  • cocktail_to_glass - Cocktail glass pairings

πŸ™ Credits & Acknowledgments

Technologies & Libraries

3D Assets

  • PS1-style character model
  • Retro sci-fi bar environment
  • GLTF glass and garnish models

Inspiration

  • 90's video game aesthetics
  • Classic bartending experiences
  • Retro UI/UX design patterns

Built with ❀️ By Albert, Edward, Ellie and Nathan

Drink responsibly. Barline is for entertainment purposes only.

About

CodeJam 15 Best UI/UX Winner - Your personal AI-powered virtual bartender - https://devpost.com/software/barline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors