# vibol18/chatbot architecture

> Architecture diagram of the GitHub repository vibol18/chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vibol18/chatbot
- Repository: https://github.com/vibol18/chatbot

## Overview

CodeScan is a local, rule-based coding assistant with both a terminal chatbot and a Flask chat interface. Users submit a question or code; the interface routes it to code detection and checks, style fixing, error-message lookup, or knowledge matching, then returns a reply. The architecture separates intent/routing, language analysis, and response services. The README also describes editable knowledge-base teaching and formatting behavior. The referenced data directory is absent from the supplied tree, and some checker implementations were not excerpted, so those internals are represented only at subsystem level.

Main entry points: [`web/app.py`](https://github.com/vibol18/chatbot/blob/master/web/app.py) (Flask chat API), [`chatbot.py`](https://github.com/vibol18/chatbot/blob/master/chatbot.py) (Terminal chatbot), [`engine/code_analyzer.py`](https://github.com/vibol18/chatbot/blob/master/engine/code_analyzer.py) (Analysis router), [`engine/matcher.py`](https://github.com/vibol18/chatbot/blob/master/engine/matcher.py) (Knowledge matcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_terminal["Terminal chatbot<br/>[chatbot.py]"]
  node_flask["Flask chat API<br/>[app.py]"]
  node_launcher["Web launcher<br/>[app.py]"]
end

subgraph group_routing["Intent and routing"]
  node_intent["Intent classifier"]
  node_snippet["Code snippet detector<br/>[code_analyzer.py]"]
  node_settings["Language and thresholds<br/>[settings.py]"]
end

subgraph group_analysis["Code analysis"]
  node_language["Language detector<br/>[detector.py]"]
  node_analyzer["Analysis router<br/>[code_analyzer.py]"]
  node_checkers["Language checkers"]
  node_brackets["Bracket checker<br/>[bracket_checker.py]"]
end

subgraph group_services["Answer and fix services"]
  node_matcher["Knowledge matcher<br/>[matcher.py]"]
  node_knowledge["Knowledge base data"]
  node_errors["Error lookup<br/>[error_lookup.py]"]
  node_error_data["Error reference data"]
  node_fix_registry["Fixer registry<br/>[__init__.py]"]
  node_fixers["Language formatters"]
end

node_user(("User"))
node_ocr["OCR service"]

node_user -->|"enters question"| node_terminal
node_user -->|"sends chat"| node_flask
node_launcher -->|"launches"| node_flask
node_terminal -->|"classifies intent"| node_intent
node_terminal -->|"tests code"| node_snippet
node_terminal -->|"detects language"| node_language
node_terminal -->|"analyzes code"| node_analyzer
node_terminal -->|"looks up errors"| node_errors
node_terminal -->|"matches question"| node_matcher
node_flask -->|"classifies intent"| node_intent
node_flask -->|"tests code"| node_snippet
node_flask -->|"detects language"| node_language
node_flask -->|"analyzes code"| node_analyzer
node_flask -->|"looks up errors"| node_errors
node_flask -->|"matches question"| node_matcher
node_flask -->|"requests formatter"| node_fix_registry
node_flask -->|"extracts image text"| node_ocr
node_analyzer -->|"detects when absent"| node_language
node_analyzer -->|"routes code"| node_checkers
node_checkers -->|"checks brackets"| node_brackets
node_matcher -->|"uses thresholds"| node_settings
node_errors -->|"loads settings"| node_settings
node_matcher -.->|"loads entries"| node_knowledge
node_errors -->|"loads JSON entries"| node_error_data
node_fix_registry -->|"dispatches formatter"| node_fixers

click node_terminal "https://github.com/vibol18/chatbot/blob/master/chatbot.py"
click node_flask "https://github.com/vibol18/chatbot/blob/master/web/app.py"
click node_launcher "https://github.com/vibol18/chatbot/blob/master/app.py"
click node_intent "https://github.com/vibol18/chatbot/blob/master/engine/intent_classifier.py"
click node_snippet "https://github.com/vibol18/chatbot/blob/master/engine/code_analyzer.py"
click node_language "https://github.com/vibol18/chatbot/blob/master/engine/detector.py"
click node_analyzer "https://github.com/vibol18/chatbot/blob/master/engine/code_analyzer.py"
click node_checkers "https://github.com/vibol18/chatbot/tree/master/checkers"
click node_brackets "https://github.com/vibol18/chatbot/blob/master/checkers/bracket_checker.py"
click node_settings "https://github.com/vibol18/chatbot/blob/master/config/settings.py"
click node_matcher "https://github.com/vibol18/chatbot/blob/master/engine/matcher.py"
click node_errors "https://github.com/vibol18/chatbot/blob/master/engine/error_lookup.py"
click node_fix_registry "https://github.com/vibol18/chatbot/blob/master/fixers/__init__.py"
click node_fixers "https://github.com/vibol18/chatbot/tree/master/fixers"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_terminal,node_flask,node_launcher,node_user toneBlue
class node_intent,node_snippet,node_settings toneAmber
class node_language,node_analyzer,node_checkers,node_brackets toneMint
class node_matcher,node_knowledge,node_errors,node_error_data,node_fix_registry,node_fixers toneRose
class node_ocr toneIndigo
```

## Components

### User interfaces

- [Terminal chatbot](https://github.com/vibol18/chatbot/blob/master/chatbot.py): `chatbot.py`
- [Flask chat API](https://github.com/vibol18/chatbot/blob/master/web/app.py): `web/app.py`
- [Web launcher](https://github.com/vibol18/chatbot/blob/master/app.py): `app.py`

### Intent and routing

- [Intent classifier](https://github.com/vibol18/chatbot/blob/master/engine/intent_classifier.py): `engine/intent_classifier.py`
- [Code snippet detector](https://github.com/vibol18/chatbot/blob/master/engine/code_analyzer.py): `engine/code_analyzer.py`
- [Language and thresholds](https://github.com/vibol18/chatbot/blob/master/config/settings.py): `config/settings.py`

### Code analysis

- [Language detector](https://github.com/vibol18/chatbot/blob/master/engine/detector.py): `engine/detector.py`
- [Analysis router](https://github.com/vibol18/chatbot/blob/master/engine/code_analyzer.py): `engine/code_analyzer.py`
- [Language checkers](https://github.com/vibol18/chatbot/tree/master/checkers): `checkers`
- [Bracket checker](https://github.com/vibol18/chatbot/blob/master/checkers/bracket_checker.py): `checkers/bracket_checker.py`

### Answer and fix services

- [Knowledge matcher](https://github.com/vibol18/chatbot/blob/master/engine/matcher.py): `engine/matcher.py`
- **Knowledge base data**
- [Error lookup](https://github.com/vibol18/chatbot/blob/master/engine/error_lookup.py): `engine/error_lookup.py`
- **Error reference data**
- [Fixer registry](https://github.com/vibol18/chatbot/blob/master/fixers/__init__.py): `fixers/__init__.py`
- [Language formatters](https://github.com/vibol18/chatbot/tree/master/fixers): `fixers`

### Other components

- **User**
- **OCR service**

## Connections

- User → Terminal chatbot: enters question (evidence: `README.md`)
- User → Flask chat API: sends chat (evidence: `web/app.py`)
- Web launcher → Flask chat API: launches (evidence: `app.py`)
- Terminal chatbot → Intent classifier: classifies intent (evidence: `chatbot.py`)
- Terminal chatbot → Code snippet detector: tests code (evidence: `chatbot.py`)
- Terminal chatbot → Language detector: detects language (evidence: `chatbot.py`)
- Terminal chatbot → Analysis router: analyzes code (evidence: `chatbot.py`)
- Terminal chatbot → Error lookup: looks up errors (evidence: `chatbot.py`)
- Terminal chatbot → Knowledge matcher: matches question (evidence: `chatbot.py`)
- Flask chat API → Intent classifier: classifies intent (evidence: `web/app.py`)
- Flask chat API → Code snippet detector: tests code (evidence: `web/app.py`)
- Flask chat API → Language detector: detects language (evidence: `web/app.py`)
- Flask chat API → Analysis router: analyzes code (evidence: `web/app.py`)
- Flask chat API → Error lookup: looks up errors (evidence: `web/app.py`)
- Flask chat API → Knowledge matcher: matches question (evidence: `web/app.py`)
- Flask chat API → Fixer registry: requests formatter (evidence: `web/app.py`)
- Flask chat API → OCR service: extracts image text (evidence: `web/app.py`)
- Analysis router → Language detector: detects when absent (evidence: `engine/code_analyzer.py`)
- Analysis router → Language checkers: routes code (evidence: `engine/code_analyzer.py`)
- Language checkers → Bracket checker: checks brackets (evidence: `checkers/check_php.py`)
- Knowledge matcher → Language and thresholds: uses thresholds (evidence: `chatbot.py`)
- Error lookup → Language and thresholds: loads settings (evidence: `engine/error_lookup.py`)
- Knowledge matcher → Knowledge base data: loads entries
- Error lookup → Error reference data: loads JSON entries (evidence: `engine/error_lookup.py`)
- Fixer registry → Language formatters: dispatches formatter (evidence: `fixers/__init__.py`)
