A sophisticated Node.js chatbot with fuzzy search capabilities, PDF document processing, and multi-source knowledge base integration.
faq-chatbot/
├── .git/ # Git repository
├── .gitignore # Git ignore rules
├── documents/ # PDF documents for knowledge base
│ └── doc01.pdf # TRESA legislation document
├── dev/
│ ├── backend/ # Node.js + Express API server
│ │ ├── .gitignore # Backend-specific ignore rules
│ │ ├── data/ # JSON knowledge base files
│ │ │ ├── faq.json # Frequently asked questions
│ │ │ ├── legal.json # Legal information
│ │ │ └── misc.json # Greetings and miscellaneous
│ │ ├── src/ # Source code (controllers, routes, services, utils)
│ │ │ ├── app.js # Express app configuration
│ │ │ ├── controllers/
│ │ │ │ └── chatController.js
│ │ │ ├── routes/
│ │ │ │ └── chatRoutes.js
│ │ │ ├── services/
│ │ │ │ ├── dataService.js
│ │ │ │ └── searchService.js
│ │ │ └── utils/
│ │ │ ├── formatters.js
│ │ │ └── pdfReader.js
│ │ ├── server.js # Main entry point
│ │ ├── package.json # Dependencies & scripts
│ │ ├── README.md # Backend documentation
│ │ └── nodemon.json # Development configuration
│ └── frontend/ # Vue 3 frontend
│ ├── src/
│ │ ├── components/
│ │ │ └── ChatWidget.vue
│ │ ├── App.vue
│ │ └── main.js
│ ├── index.html
│ ├── vite.config.js
│ └── package.json
├── run-demo.bat # Windows batch script
└── README.md # This file
Quick links:
- Backend README: dev/backend/README.md
- Frontend README: dev/frontend/README.md
- Multi-Source Knowledge Base: FAQ, legal documents, miscellaneous responses, and PDF content
- Intelligent Search Priority: Exact matches → keyword detection → fuzzy search → PDF fallback
- PDF Document Processing: Automatic text extraction and chunking for searchable content
- Enhanced Keyword Matching: Handles synonyms and related terms (e.g., "effective date" → "come into effect")
- Fuzzy Search: Powered by Fuse.js with configurable thresholds
- RESTful API: Clean Express.js API with proper error handling
- Vue 3 Frontend: Modern chat interface with real-time responses
- Graceful Error Handling: Comprehensive error handling and fallback responses
Double-click run-demo.bat or run it from command prompt:
run-demo.batRun the PowerShell script:
.\run-demo.ps1If you prefer to run manually:
-
Backend (Terminal 1):
cd dev\backend npm install npm run dev # For development with hot reload # OR npm start # For production
-
Frontend (Terminal 2):
cd dev\frontend npm install npm run dev
npm run dev- Development mode with hot reload using nodemonnpm run dev:debug- Development mode with debugging enablednpm start- Production mode without hot reloadnpm run clean- Clean temporary files
Process a chat message and return the best matching response.
Request:
{
"message": "TRESA effective date"
}Response:
{
"response": "TRESA came into effect on December 1, 2023, replacing the Real Estate and Business Brokers Act (REBBA).",
"source": "FAQ Database - Keyword Match",
"sourceType": "faq"
}Get server status and data source information.
Response:
{
"status": "running",
"initialized": true,
"dataSources": {
"faq": 10,
"legal": 10,
"misc": 12,
"pdfs": 1,
"totalSearchable": 100
}
}Health check endpoint.
Response:
{
"status": "OK",
"timestamp": "2024-01-01T12:00:00.000Z",
"service": "FAQ Chatbot API"
}- Backend API: http://localhost:3000
- Frontend: http://localhost:5173
- Health Check: http://localhost:3000/health
- API Status: http://localhost:3000/status
This repository contains a Node.js backend and a Vue 3 frontend that together implement a FAQ chatbot with fuzzy search and PDF fallback search.
- Backend:
dev/backend(Express) - Frontend:
dev/frontend(Vue 3) - Release automation:
semantic-release(configured in.releaserc) - CI: GitHub Actions (
.github/workflows) - Commit rules: Conventional Commits enforced by
commitlint+ Husky and a PR check
- Clone and install dependencies at the repo root (monorepo workspaces):
cd D:\Projects\Samples\faq-chatbot
npm install- Start backend and frontend in separate terminals:
Backend:
cd dev/backend
npm install
npm run devFrontend:
cd dev/frontend
npm install
npm run devWe use Conventional Commits to drive releases via semantic-release. The repo already includes these conveniences:
- Commitizen: run
npm run committo get an interactive commit prompt (cz-conventional-changelog). - Commitlint: validates commit messages in CI and locally.
- Husky: local
commit-msghook runscommitlintto block bad commits before pushing.
If you haven't already, run npm install at the repo root to ensure hooks and dev tools are available. Use git commit as usual, or npm run commit for guided commits.
Example valid commit:
chore: Refactor code structure for improved readability and maintainability
- Releases are automated with
semantic-releasefrom themainbranch. Therelease.ymlworkflow runssemantic-releaseonmainand creates GitHub Releases and updatesCHANGELOG.md. - You can run a local dry-run to preview a release without publishing:
npx semantic-release --dry-runNote: npm ci in CI requires package-lock.json to match package.json. If CI reports EUSAGE about npm ci, run npm install locally, commit the updated lockfile, and push.
The deploy workflow (.github/workflows/deploy.yml) runs on manual dispatch only (workflow_dispatch). Behavior:
- Trigger: manually from GitHub Actions (Actions → Deploy → Run workflow). It accepts an optional
taginput. - If
tagis provided: the workflow deploys that tag/ref. - If
tagis empty: the workflow looks up the latest GitHub Release tag and deploys that tag. - The workflow creates a GitHub Deployment record, copies files to your droplet via SCP, runs deploy commands via SSH (pm2 restart / build / nginx copy), then posts deployment status back to GitHub.
If you want automatic deploys on release publish, we can add on: release: types: [published] to the workflow.
pr-commitlint.ymlruns on PRs and checks:- PR title (must follow Conventional Commits)
- All non-merge commits in the PR via
commitlint(merge commits are ignored)
- Husky is initialized via
preparescript inpackage.json(runs onnpm install). - Local hook file
.husky/commit-msgrunscommitlintto validate commit messages. If the commit message is invalid the commit will be blocked. - To add pre-commit formatting/linting, we can add
lint-stagedand a.husky/pre-commithook.
- If CI fails with
npm cilockfile mismatch: runnpm installlocally and commitpackage-lock.json. - To bypass hooks (not recommended):
git commit --no-verify -m "...". - If Husky hooks don't run for other contributors, ensure they run
npm installso thepreparescript sets up Husky helper files.
- Fork the repo and create a feature branch
- Use
npm run commit(Commitizen) or follow Conventional Commits for commit messages - Open a PR; CI will run commitlint and other checks
- Release config:
.releaserc - Release workflow:
.github/workflows/release.yml - Deploy workflow:
.github/workflows/deploy.yml - PR commit checks:
.github/workflows/pr-commitlint.yml - Husky hook:
.husky/commit-msg - Commitlint config:
commitlint.config.js