πŸ—οΈ 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:

  1. Frontend (chatbot.js/css) - User interface
  2. API (Ollama) - AI processing
  3. Model (darya-assistant) - Your knowledge base

Everything runs locally on your Mac, making it:

  • βœ… Free
  • βœ… Private
  • βœ… Fast
  • βœ… Customizable

Questions? Check the other documentation files!