Reach me out via LinkedIn, Portfolio Contact Form or mail@pascal-nehlsen.de
Book an appointment directly using the AI Chatbot (bottom-right corner) - just type "Termin" or "appointment"
AI Chatbot - Technical Documentation
Executive Summary
This is a production-ready, multi-tenant platform for embedding customizable AI chatbots with appointment booking capabilities into e-commerce websites. Built with a modern fullstack architecture emphasizing security, scalability, and DevSecOps best practices.
Tech Stack: Next.js 13, React 18, TypeScript, Prisma ORM, PostgreSQL 17, OpenAI GPT-4, Docker, Node.js 20
Architecture Overview
The platform consists of client websites embedding a widget via script tag, a Next.js server handling API routes, and a PostgreSQL database. External services include OpenAI API and SMTP for emails.
High-Level Architecture
┌─────────────────────────────────────────────────────────────┐
│ Client Websites │
│ (Multiple domains embedding widget via <script> tag) │
└─────────────┬─────────────────────────────────────────── ────┘
│
│ HTTPS (CORS-protected)
▼
┌─────────────────────────────────────────────────────────────┐
│ Next.js Application Server │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ API Routes (/api/*) │ │
│ │ • Bot Configuration Management │ │
│ │ • Chat Interface (OpenAI Integration) │ │
│ │ • Appointment Booking System │ │
│ │ • Authentication & Authorization │ │
│ │ • Password Reset Flow │ │
│ └──────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Widget Distribution (/dist/widget.iife.js) │ │
│ │ • Shadow DOM isolated React component │ │
│ │ • Self-contained styling │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────┬────────────────────────────────────────────────┘
│
│ Prisma ORM
▼
┌─────────────────────────────────────────────────────────────┐
│ PostgreSQL 17 Database │
│ • Bot configurations (multi-tenant) │
│ • Conversation history │
│ • Appointment schedules │
│ • Password reset tokens (bcrypt hashed) │
└─────────────────────────────────────────────────────────────┘
External Services
┌──────────────────┐
│ OpenAI API │
│ (GPT-4.1-mini) │
└──────────────────┘
┌──────────────────┐
│ SMTP Server │
│ (Nodemailer) │
└──────────────────┘
Technology Stack
Frontend Technologies
| Technology | Version | Purpose |
|---|---|---|
| React | 18.2.0 | Widget UI framework with hooks-based state management |
| TypeScript | 5.8.3 | Type safety across frontend and API layers |
| Vite | 7.0.0 | Widget bundler with IIFE output for script tag embedding |
| TailwindCSS | 3.3.2 | Utility-first CSS framework (build-time only) |
| Shadow DOM | Native | CSS/JS isolation for widget embedding |
Backend Technologies
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 13.4.12 | Full-stack React framework with API routes |
| Node.js | 20 | Server runtime (LTS version) |
| Prisma | 6.11.1 | Type-safe ORM with migration system |
| PostgreSQL | 17.5 | Primary relational database |
| OpenAI SDK | 4.18.0 | GPT-4 integration for conversational AI |
Security & Infrastructure
| Technology | Version | Purpose |
|---|---|---|
| bcryptjs | 3.0.3 | Password hashing (12 rounds, salted) |
| jsonwebtoken | 9.0.2 | JWT token generation for session management |
| Nodemailer | 7.0.4 | Secure email delivery (password resets, appointments) |
| CORS | Built-in | Origin validation per bot configuration |
| Docker | Latest | Containerization for consistent deployments |
| Docker Compose | v2 | Multi-container orchestration |
Security Architecture
The platform implements comprehensive DevSecOps practices with multi-layered security.
Authentication & Authorization
- 12-round bcrypt hashing for all passwords
- Secure password reset flow with time-limited tokens (1 hour expiry)
- Rate limiting: Max 3 reset requests per hour per user
- Password policy enforcement: Min 8 chars, 1 uppercase, 1 number
Data Protection
Sensitive data handling ensures passwords are never exposed in API responses. Environment variables isolate secrets like OPENAI_API_KEY, JWT_SECRET, and EMAIL_PASS. Email security includes SMTP authentication, TLS encryption, and no sensitive data in subjects.