# johess123/ollama architecture

> Architecture diagram of the GitHub repository johess123/ollama, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johess123/ollama
- Repository: https://github.com/johess123/ollama

## Overview

##### Project type and purpose
- This is a full-stack web application that lets you quickly deploy a local AI chatbot on any webpage, using Flask for the back end, JavaScript for the front end, and a Retrieval-Augmented Generation (RAG) pipeline powered by Ollama, LangChain, and ChromaDB. Its goal is to avoid sending confidential data to external LLM providers while offering easy “one-line” embedding on a webpage.

##### File structure
- Top-level:
- server.py, server_bot.py: Flask application entry points
- static/: contains bot.js (front-end embedding script)
- templates/: HTML templates (index.html to load the chat widget, bot.html for the chat UI)
- Other files (PDFs, tests) are artifacts/demo files, not core to the runtime
- No microservices—this is a monolithic Flask app with a clear front-end/back-end separation.
- No Docker config yet, but README mentions future Docker packaging.

##### Extract key architecture notes from the README
- Core components:
- Ollama (on-prem LLM host via Python SDK)
- LangChain (RAG orchestration, memory)
- ChromaDB (vector store for RAG)
- Flask (HTTP server)
- JavaScript snippet for embedding on client pages
- Optional MySQL: README lists it under “deploy Flask, MySQL, ChromaDB,” so you may include it as a relational store for user/session data if used.

##### Main components & interactions
a. Front-end Web Page
- A user’s browser loads index.html & bot.js
- bot.js establishes a WebSocket or HTTP POST to Flask
b. Flask Back-end (server.py & server_bot.py)
- Receives user messages from bot.js
- Calls the RAG service layer implemented with LangChain
c. RAG Service Layer (LangChain)
- Issues a query to ChromaDB vector database
- Builds context & memory for the conversation
- Sends prompt + context to Ollama LLM via Python SDK
d. ChromaDB (Vector Store)
- Stores embedded documents & their embeddings for similarity search
e. Ollama (Local LLM Host)
- Receives prompt + context over Python SDK
- Returns generated response
f. (Optional) MySQL
- Stores user profiles, session logs, or RAG metadata if implemented
g. Response flows back the same path: Ollama → LangChain → Flask → bot.js → browser UI

##### Architectural patterns & design principles
- Monolithic MVC-style separation:
- Models: ChromaDB, optional MySQL
- Views: Jinja2 templates (index.html, bot.html) & static JS
- Controllers: Flask routes in server.py/server_bot.py
- RAG pipeline pattern: vector store lookup + LLM generation
- Clear separation between client (JavaScript widget) and server (Flask API)

##### Essential elements to capture
- Clear component labels (with file/dir references where helpful)
- Optional section showing “future Docker” as a container around all back-end components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Browser)"
        Browser["User Browser"]:::frontend
        Index["Landing Page Template (index.html)"]:::frontend
        BotUI["Chat UI Template (bot.html)"]:::frontend
        BotJS["Embedding Snippet (bot.js)"]:::frontend
    end

    subgraph "Server (Backend)"
        FlaskServer["Flask Server (server.py)"]:::backend
        BotController["Bot Endpoint & RAG Controller (server_bot.py)"]:::backend
        RAGLayer["RAG Service (LangChain)"]:::backend
        Docs["Project Documentation (README.md)"]:::docs
    end

    subgraph "Data Stores"
        ChromaDB["ChromaDB (Vector Store)"]:::datastore
        MySQL["MySQL (Optional)"]:::datastore
    end

    Ollama["Ollama LLM Host"]:::llm

    Browser -->|"loads"| Index
    Index -->|"includes widget snippet"| BotJS
    Browser -->|"navigates to chat UI"| BotUI

    BotJS -->|"HTTP POST/WebSocket"| FlaskServer
    FlaskServer -->|"routes to /bot"| BotController
    BotController -->|"invokes"| RAGLayer

    RAGLayer -->|"vector query"| ChromaDB
    RAGLayer -->|"SDK call"| Ollama
    RAGLayer -.->|"persist logs (optional)"| MySQL

    Ollama -->|"response"| RAGLayer
    RAGLayer -->|"reply"| BotController
    BotController -->|"response"| FlaskServer
    FlaskServer -->|"HTTP response"| BotJS
    BotJS -->|"render"| Browser

    FlaskServer -.->|"architecture notes"| Docs

    click BotJS "https://github.com/johess123/ollama/blob/master/static/bot.js"
    click BotController "https://github.com/johess123/ollama/blob/master/server_bot.py"
    click FlaskServer "https://github.com/johess123/ollama/blob/master/server.py"
    click Index "https://github.com/johess123/ollama/blob/master/templates/index.html"
    click BotUI "https://github.com/johess123/ollama/blob/master/templates/bot.html"
    click Docs "https://github.com/johess123/ollama/blob/master/README.md"

    classDef frontend fill:#B3DFFF,stroke:#0366d6,color:#000
    classDef backend fill:#C6F6D5,stroke:#2F855A,color:#000
    classDef datastore fill:#FED7D7,stroke:#C53030,color:#000
    classDef llm fill:#E9D8FD,stroke:#805AD5,color:#000
    classDef docs fill:#FEEBC8,stroke:#D69E2E,color:#000
```
