Abstract Background
Back to Projects
PythonFastAPILangChainPostgreSQLpgvectorOllamaDockerWordPress

AI Chat System for WordPress Business Website

How I replaced a generic contact form with an intelligent chat assistant that automatically crawls the client's website, builds a knowledge base, and answers visitor questions 24/7 with full Hostinger deployment and WordPress integration.

▢ Key Challenge

Building a chat system that stays accurate as the website content changes without manual updates. The crawler had to handle multilingual content, respect rate limits, and stay within server constraints on shared Hostinger hosting.

The Problem: Static Websites, Dynamic Questions

The client ran a UK-based electronics business (Nidrip Central Electronics) on WordPress. Visitors would land on the site, browse products, and then leave, because they couldn't quickly get answers to specific questions about product compatibility, specifications, or stock. A generic contact form with a 24-hour response time was costing them conversions.

They needed an intelligent assistant that actually knew their business every product, every page, every detail and could answer visitor questions instantly. The solution had to run on their existing Hostinger server and integrate cleanly with WordPress.

System Architecture

I built a fully self-contained RAG system packaged as a single Docker container managed by Supervisor. The key insight: instead of manually feeding content into the system, a background crawler automatically discovers and indexes the entire website on a schedule.

Architecture diagram
Architecture diagram
ComponentTechnologyRole
API BackendFastAPI (Python 3.11)Chat endpoint, crawl triggers, health checks
Vector DatabasePostgreSQL 15 + pgvectorStores page embeddings for semantic search
LLM EngineOllama (llama3)Local inference, no OpenAI costs
OpenAI FallbackOpenAI APIOptional swap-in for higher quality responses
Web CrawlerBeautifulSoup4 + RequestsAuto-discovers and indexes all site pages
RAG FrameworkLangChainRetrieval chain, prompt management
Process ManagerSupervisorRuns all services in one container
Web ServerNginxReverse proxy + SSL termination
ContainersDocker ComposeDev + prod configurations

The Auto-Crawling Knowledge Base

The system's most valuable feature is automatic self-updating. Every hour (configurable in config.yaml), a background crawler starts at the site's root URL, follows internal links up to a configured depth, extracts clean text content from each page, and stores semantic embeddings in PostgreSQL.

yaml
# config.yaml the entire system configured in 5 lines
domains:
  - name: nidripcentralelectronics.co.uk
    start_url: https://nidripcentralelectronics.co.uk/
    languages: [en]

crawl_interval: 3600      # Re-crawl every hour
max_pages_per_domain: 150  # Safety limit

When the client updates a product page or adds new content to their WordPress site, the next crawl cycle automatically picks up the changes. Zero manual maintenance required.

Chat API & WordPress Integration

The FastAPI backend exposes a rate-limited chat endpoint (5 requests per minute per user) that handles the full RAG pipeline: embed the visitor's question → retrieve the top matching page chunks from pgvector → construct a prompt → generate a response via Ollama. Privacy is built in, all chat logs are stored with hashed queries and responses for DSGVO/GDPR compliance.

WordPress integration is a single line: add the embeddable JavaScript widget snippet to the theme's footer. The widget opens a chat panel that communicates with the FastAPI backend.

html
<!-- Add to WordPress footer, that's all the integration needed -->
<script src="https://your-server.com/static/widget.js"></script>

Dual LLM Mode: Local or Cloud

Local mode (default): Ollama running llama3 inside the container zero per-query cost, full privacy, works offline
OpenAI mode: swap the LLM backend to GPT-4o for higher quality responses when needed, just update the .env file
The LangChain abstraction layer makes switching between providers a config change, not a code change

Hostinger Deployment

Hostinger's VPS environment required careful configuration. I set up the full production stack: Docker Compose with a dedicated Nginx container for SSL termination, Let's Encrypt certificate auto-renewal via a shell script, and Supervisor managing the FastAPI, Ollama, and crawler processes within a single container to minimise resource usage on the shared server.

1.Configure config.yaml with the client's domain(s)
2.Run init-letsencrypt.sh to provision SSL certificates
3.docker-compose -f docker-compose.prod.yml up -d
4.Add the widget script tag to the WordPress theme footer
5.First crawl completes within minutes, chat is live

Results & Impact

Delivered a fully self-contained AI chat assistant deployed on Hostinger, embedded in the client's WordPress site via a one-line script tag. The system automatically re-crawls the website every hour, keeping its knowledge base current. Visitors get instant, accurate answers about products and services at any time of day.