ποΈ Chatbot Architecture
ποΈ Chatbot Architecture
System Overview
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Website β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β index.html β β styles.css β β script.js β β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ β
β β
β ββββββββββββββ ββββββββββββββ β
β βchatbot.js β βchatbot.css β β New chatbot files β
β βββββββ¬βββββββ ββββββββββββββ β
ββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β HTTP Request
β (localhost:11434)
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Ollama Service β
β (Running on your Mac) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β darya-assistant Model β β
β β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β Llama 3.2 Base Model (3B) β β β
β β β β’ Natural language processing β β β
β β β β’ Conversation abilities β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β + β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β Your Resume Data (Modelfile) β β β
β β β β’ Education & GPA β β β
β β β β’ Work experience β β β
β β β β’ Technical skills β β β
β β β β’ Projects & achievements β β β
β β β β’ Contact information β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Data Flow
User Types Question
β
ββββββββββββββββββββ
β Chat Widget β (chatbot.js)
β β’ Captures inputβ
β β’ Shows typing β
ββββββββββ¬ββββββββββ
β
β
ββββββββββββββββββββ
β Format Request β
β β’ Add context β
β β’ Set parametersβ
ββββββββββ¬ββββββββββ
β
β HTTP POST
ββββββββββββββββββββ
β Ollama API β (localhost:11434)
β β’ Receives queryβ
β β’ Loads model β
ββββββββββ¬ββββββββββ
β
β
ββββββββββββββββββββ
β AI Processing β
β β’ Understands Q β
β β’ Searches data β
β β’ Generates ans β
ββββββββββ¬ββββββββββ
β
β JSON Response
ββββββββββββββββββββ
β Display Answer β (chatbot.js)
β β’ Format text β
β β’ Show in chat β
ββββββββββββββββββββ
β
User sees answer
File Structure
your-project/
β
βββ index.html β Main website (updated)
βββ styles.css β Main styles
βββ script.js β Main JavaScript
β
βββ chatbot.js β π Chatbot logic & Ollama integration
βββ chatbot.css β π Chatbot styling
βββ Modelfile β π Your custom AI model definition
β
βββ start-chatbot.sh β π Setup automation script
βββ test-chatbot.sh β π Testing script
βββ test-chatbot.html β π Standalone test page
β
βββ QUICK-START.md β π 3-step guide
βββ CHATBOT-README.md β π Full documentation
βββ setup-local-llm.md β π Detailed setup
βββ SETUP-SUMMARY.md β π Overview
βββ ARCHITECTURE.md β π This file
Component Breakdown
1. Chat Widget (chatbot.js + chatbot.css)
Purpose: User interface for the chatbot
Features:
- Floating button in bottom-right
- Expandable chat window
- Message history
- Typing indicators
- Quick question buttons
- Mobile responsive
Key Functions:
initChatbot() // Initialize on page load
toggleChat() // Open/close chat window
handleSubmit() // Process user input
addMessage() // Display messages
getBotResponse() // Get AI response
2. Ollama Service
Purpose: Run the AI model locally
Components:
- HTTP API server (port 11434)
- Model management
- Inference engine
- Memory management
Endpoints Used:
GET /api/tags // List available models
POST /api/generate // Generate response
POST /api/chat // Chat completion
3. Custom Model (Modelfile)
Purpose: Define your personalized AI assistant
Contains:
- Base model reference (llama3.2:3b)
- System prompt with your data
- Generation parameters
- Example conversations
Structure:
FROM llama3.2:3b
PARAMETER temperature 0.7
PARAMETER num_ctx 4096
SYSTEM """[Your resume data]"""
MESSAGE user [example]
MESSAGE assistant [example]
Request/Response Flow
User Asks Question
// 1. User types: "What are Darya's skills?"
const userMessage = "What are Darya's skills?";
// 2. chatbot.js formats request
const request = {
model: 'darya-assistant',
prompt: userMessage,
stream: false,
options: {
temperature: 0.7,
num_predict: 500
}
};
// 3. Send to Ollama
fetch('http://localhost:11434/api/generate', {
method: 'POST',
body: JSON.stringify(request)
});
// 4. Ollama processes with your model
// - Loads darya-assistant model
// - Reads system prompt (your resume)
// - Generates contextual response
// 5. Response received
{
"response": "Darya has strong technical skills in C++...",
"done": true
}
// 6. Display in chat widget
addMessage(response.response, 'bot');
Model Training Process
βββββββββββββββββββββββ
β Base Model β Llama 3.2 (3B parameters)
β (General AI) β β’ Language understanding
ββββββββββββ¬βββββββββββ β’ Conversation ability
β
β + Modelfile
βββββββββββββββββββββββ
β System Prompt β Your resume data
β (Your Data) β β’ Education
ββββββββββββ¬βββββββββββ β’ Experience
β β’ Skills
β β’ Projects
β
βββββββββββββββββββββββ
β Example Convos β Q&A pairs
β (Training) β β’ "What skills?" β "C++, Python..."
ββββββββββββ¬βββββββββββ β’ "Research?" β "GNN security..."
β
β
βββββββββββββββββββββββ
β Custom Model β darya-assistant
β (Specialized) β β’ Knows about you
βββββββββββββββββββββββ β’ Answers naturally
Performance Optimization
Speed Factors
Response Time = Model Size + Context Length + Hardware
Fast (1-2s):
- Small model (3B parameters)
- Short context (4096 tokens)
- Good hardware (8GB+ RAM)
Slow (5-10s):
- Large model (70B parameters)
- Long context (8192 tokens)
- Limited hardware (4GB RAM)
Memory Usage
Model Size β RAM Needed
3B params β 4GB RAM β
Your setup
7B params β 8GB RAM
13B params β 16GB RAM
70B params β 64GB RAM
Security & Privacy
βββββββββββββββββββββββββββββββββββββββββββ
β Your Computer β
β β
β ββββββββββββββ ββββββββββββββββ β
β β Browser β ββββ β Ollama β β
β β (Website) β β (Local AI) β β
β ββββββββββββββ ββββββββββββββββ β
β β
β All data stays here β
β
β No external API calls β
β
β No tracking β
β
βββββββββββββββββββββββββββββββββββββββββββ
β No connection to cloud
β No data sent to OpenAI
β No analytics or tracking
Deployment Options
Option 1: Local Only (Current)
Your Mac β Ollama β Website
(localhost)
Pros: Free, private, fast Cons: Only works on your machine
Option 2: Server Deployment
User β Your Server β Ollama β Response
(VPS/Cloud)
Pros: Accessible anywhere Cons: Server costs, setup complexity
Option 3: Hybrid
Development: Local Ollama
Production: OpenAI API
Pros: Best of both worlds Cons: API costs in production
Technology Stack
Frontend:
βββ HTML5
βββ CSS3 (Custom properties, Grid, Flexbox)
βββ Vanilla JavaScript (ES6+)
βββ Font Awesome (Icons)
Backend:
βββ Ollama (LLM runtime)
βββ Llama 3.2 (Base model)
βββ Custom model (Your data)
Development:
βββ Bash scripts (Automation)
βββ Python HTTP server (Testing)
βββ curl (API testing)
Comparison: Local vs Cloud
βββββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ
β Feature β Local (You) β Cloud (API) β
βββββββββββββββββββΌβββββββββββββββΌβββββββββββββββ€
β Cost β $0 β $10-50/month β
β Privacy β 100% private β Data shared β
β Speed β 1-2 seconds β 2-5 seconds β
β Offline β β
Yes β β No β
β Setup β 5 minutes β 1 minute β
β Customization β Full control β Limited β
β Scalability β 1 user β Unlimited β
β Maintenance β Minimal β None β
βββββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ
Future Enhancements
Possible Additions
1. Voice Input/Output
βββ Web Speech API integration
2. Multi-language Support
βββ Detect language, respond accordingly
3. Context Memory
βββ Remember previous conversations
4. Analytics Dashboard
βββ Track popular questions
5. Admin Panel
βββ Update responses without code
6. Email Integration
βββ Send conversation transcripts
7. Calendar Integration
βββ Schedule meetings directly
8. File Upload
βββ Answer questions about uploaded docs
Monitoring & Debugging
Check System Status
# Is Ollama running?
ollama ps
# List models
ollama list
# Test API
curl http://localhost:11434/api/tags
# View logs (macOS)
tail -f ~/Library/Logs/Ollama/server.log
Browser Debugging
// Open console (F12)
// Check for errors
console.log('Chatbot initialized');
// Test Ollama connection
fetch('http://localhost:11434/api/tags')
.then(r => r.json())
.then(d => console.log('Models:', d));
Summary
Your chatbot uses a 3-tier architecture:
- Frontend (chatbot.js/css) - User interface
- API (Ollama) - AI processing
- Model (darya-assistant) - Your knowledge base
Everything runs locally on your Mac, making it:
- β Free
- β Private
- β Fast
- β Customizable
Questions? Check the other documentation files!