Skip to content

AndriiEagle/eaa-chatbot

Repository files navigation

πŸ€– EAA ChatBot - AI-Powered European Accessibility Act Consultation Platform

TypeScript Node.js React OpenAI Supabase License

Revolutionary AI-powered consultation platform for European Accessibility Act (EAA) compliance with RAG architecture, multi-agent AI system, voice input, and intelligent compliance guidance.

🚨 IMPORTANT: API Keys Required

⚠️ THIS APPLICATION WILL NOT START WITHOUT VALID API KEYS!

This project requires API keys from:

  • OpenAI (for GPT-4o-mini and embeddings)
  • Supabase (for vector database and storage)

The application will immediately exit with an error message if these keys are not provided.

πŸ”‘ Getting Your API Keys

  1. OpenAI API Key: Visit OpenAI Platform
  2. Supabase Keys: Go to Supabase Dashboard β†’ Your Project β†’ Settings β†’ API

πŸ“‹ Required Environment Variables

OPENAI_API_KEY=your_openai_api_key_here
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your_supabase_service_key_here

Without these keys properly configured, you will see a detailed error message and the application will not start.

🌟 Key Features

  • 🧠 RAG Architecture - Retrieval-Augmented Generation with vector search
  • πŸ€– Multi-Agent AI System - Specialized agents for different consultation aspects
  • 🎀 Voice Input - OpenAI Whisper integration for accessibility
  • 😀 Frustration Detection - AI-powered emotional analysis and escalation
  • πŸ“§ Smart Escalation - Automatic email notifications for complex cases
  • πŸ’¬ Intelligent Suggestions - Context-aware question recommendations
  • πŸ” Semantic Search - pgvector-powered similarity matching
  • πŸ“± Responsive UI - Modern React interface with accessibility features
  • πŸ”’ Enterprise Security - Secure authentication and data handling
  • πŸ“Š Analytics & Monitoring - Comprehensive performance tracking

πŸš€ Quick Start

Prerequisites

  • Node.js 18.0.0+
  • npm 8.0.0+
  • Supabase account
  • OpenAI API key

Installation

  1. Clone the repository
git clone https://github.com/your-username/eaa-chatbot.git
cd eaa-chatbot/ParserForChuncks
  1. Install dependencies
npm install
  1. Environment setup (CRITICAL STEP)
cp env.example .env

⚠️ MANDATORY: Configure your .env file with valid API keys:

# OpenAI Configuration (REQUIRED)
OPENAI_API_KEY=your_openai_api_key_here

# Supabase Configuration (REQUIRED)
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your_supabase_service_key_here

# Server Configuration
PORT=3000
NODE_ENV=development

# Email Configuration (Optional)
SMTP_HOST=your_smtp_host
SMTP_PORT=587
SMTP_USER=your_email
SMTP_PASS=your_password

🚨 IMPORTANT: Replace the placeholder values with your actual API keys. The application will not start without them and will display a detailed error message if they're missing.

  1. Build and start
npm run build-and-run

Or for development:

npm run dev

πŸ—οΈ Architecture Overview

Core Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React Client  β”‚    β”‚  Express Server β”‚    β”‚   Supabase DB   β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Chat UI       │◄──►│ β€’ RAG Engine    │◄──►│ β€’ Vector Store  β”‚
β”‚ β€’ Voice Input   β”‚    β”‚ β€’ AI Agents     β”‚    β”‚ β€’ Chat History  β”‚
β”‚ β€’ Suggestions   β”‚    β”‚ β€’ Memory System β”‚    β”‚ β€’ User Facts    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
         └──────────────►│   OpenAI API    β”‚β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚                 β”‚
                        β”‚ β€’ GPT-4o-mini   β”‚
                        β”‚ β€’ Embeddings    β”‚
                        β”‚ β€’ Whisper STT   β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Multi-Agent System

  • 🎯 Suggestion Agent - Generates contextual questions
  • 😀 Frustration Agent - Detects user emotional state
  • πŸ‘€ Persona Agent - Identifies user type and expertise level
  • πŸ” Behavior Agent - Analyzes interaction patterns
  • πŸ“§ Email Agent - Composes escalation notifications
  • 🎀 Voice Agent - Processes speech-to-text

πŸ“š API Documentation

Core Endpoints

Chat & Consultation

POST /ask
Content-Type: application/json

{
  "question": "What are the EAA requirements for mobile apps?",
  "user_id": "user123",
  "session_id": "session456",
  "similarity_threshold": 0.78,
  "max_chunks": 5,
  "stream": true
}

Session Management

GET /chat/sessions/:userId          # Get user sessions
GET /chat/messages/:sessionId       # Get session messages
DELETE /chat/sessions/:sessionId    # Delete session

Voice Processing

POST /whisper/transcribe
Content-Type: multipart/form-data

# Audio file upload for transcription

Health & Configuration

GET /health                         # Server health check
GET /config                         # API configuration

Response Format

{
  "success": true,
  "data": {
    "answer": "The EAA requires mobile applications to...",
    "sources": [
      {
        "title": "Chapter 2: Scope and Requirements",
        "similarity": 0.89,
        "preview": "Mobile applications must comply with..."
      }
    ],
    "suggestions": [
      "What about web applications?",
      "Are there any exceptions for small businesses?"
    ],
    "metadata": {
      "chunks_used": 3,
      "processing_time": 1.2,
      "model": "gpt-4o-mini"
    }
  }
}

πŸ§ͺ Testing

Run Tests

# All tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

# Specific test suites
npm run test:unit
npm run test:integration

Test Coverage

  • βœ… 14/14 tests passing (100%)
  • 🧠 AI agent functionality
  • πŸ’Ύ Database operations
  • πŸ” Search algorithms
  • πŸ“§ Email notifications
  • 🎀 Voice processing

πŸ”§ Development

Code Quality

# Linting
npm run lint
npm run lint:fix

# Type checking
npm run type-check

# Formatting
npm run format
npm run format:check

Database Management

# Schema updates
npm run db:migrate

# Health check
npm run db:health

# Apply fixes
npm run db:apply-fix

Documentation

# Generate API docs
npm run docs:api

# Serve documentation
npm run docs:serve

πŸ—„οΈ Database Schema

Core Tables

-- Chat sessions
CREATE TABLE chat_sessions (
  id UUID PRIMARY KEY,
  user_id TEXT NOT NULL,
  title TEXT,
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW(),
  message_count INT DEFAULT 0,
  escalated BOOLEAN DEFAULT FALSE
);

-- Chat messages with vector embeddings
CREATE TABLE chat_messages (
  id UUID PRIMARY KEY,
  session_id UUID REFERENCES chat_sessions(id),
  role TEXT NOT NULL,
  content TEXT NOT NULL,
  embedding VECTOR(1536),
  created_at TIMESTAMP DEFAULT NOW()
);

-- User facts and business information
CREATE TABLE user_facts (
  id UUID PRIMARY KEY,
  user_id TEXT NOT NULL,
  fact_type TEXT NOT NULL,
  fact_value TEXT NOT NULL,
  confidence FLOAT DEFAULT 1.0,
  created_at TIMESTAMP DEFAULT NOW()
);

-- Frustration analysis
CREATE TABLE frustration_analysis (
  id UUID PRIMARY KEY,
  user_id TEXT NOT NULL,
  session_id UUID,
  frustration_level FLOAT,
  risk_score FLOAT,
  created_at TIMESTAMP DEFAULT NOW()
);

πŸš€ Deployment

Docker

# Build image
npm run docker:build

# Run container
npm run docker:run

# Docker Compose
npm run docker:compose

Production

# Build for production
npm run build

# Start production server
npm run start

# PM2 process management
npm run pm2:start
npm run pm2:restart
npm run pm2:stop

Environment Variables for Production

NODE_ENV=production
PORT=3000
LOG_LEVEL=info
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

πŸ“Š Monitoring & Analytics

Performance Metrics

  • Response time tracking
  • Token usage monitoring
  • User satisfaction scores
  • Escalation rates
  • Voice processing accuracy

Logging

# View logs
npm run logs

# Error logs
npm run logs:error

πŸ”’ Security Features

  • Rate Limiting - Express rate limiting middleware
  • Input Validation - Zod schema validation
  • SQL Injection Protection - Supabase ORM
  • Environment Variables - No hardcoded secrets
  • CORS Configuration - Secure cross-origin requests
  • Helmet.js - Security headers

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write comprehensive tests
  • Update documentation
  • Use conventional commits
  • Ensure 100% test coverage for new features

πŸ“‹ Roadmap

  • Multi-language Support - Internationalization
  • Advanced Analytics Dashboard - Real-time metrics
  • Mobile App - React Native implementation
  • Plugin System - Extensible architecture
  • Advanced Voice Features - Voice responses
  • Integration APIs - Third-party service connections

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ™ Acknowledgments

  • European Accessibility Act documentation
  • OpenAI for GPT-4o-mini and Whisper API
  • Supabase for vector database capabilities
  • The accessibility community for valuable feedback

Built with ❀️ for digital accessibility and inclusion