The full tech stack to run a chatbot — behind the scenes of an open source bot platform
Tags: chatbots, programming, nlp, tutorial
Published: 2022-07-12 12:46:39


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qb62mj60dx2464hjgu7q.jpg)

We always aim to "educate" aspiring chatbot developers about the<a href="https://xatkit.com/the-software-challenges-of-building-smart-chatbots/" target="_blank" rel="noopener"> software challenges of building and running a good chatbot</a>. Today we want to go a bit further and give you a behind-the-scenes look at all the languages, libraries and frameworks that must play together to run a chatbot.

As the full stack depends on the specific chatbot (especially regarding the <a href="https://github.com/xatkit-bot-platform/xatkit/wiki/Xatkit-Chat-Platform" target="_blank" rel="noopener">communication channels</a> where it will be deployed), we will use our <a href="https://wooxatkitdemo.wpengine.com/" target="_blank" rel="noopener">ecommerce chatbot</a> as an example.

<h2>1. The core chatbot logic</h2>
The core elements of the ecommerce bot (the intents, training sentences and business logic to execute for every matched intent) are implemented with our <a href="https://xatkit.com/fluent-interface-building-chatbots-bots/" target="_blank" rel="noopener"><strong>Java</strong> Fluent API</a> that wraps a set of <a href="https://www.eclipse.org/modeling/emf/" target="_blank" rel="noopener">EMF</a>-based core classes modeling our chatbot specification primitives and the help of <a href="https://projectlombok.org/" target="_blank" rel="noopener">Lombok</a> to simplify the writing of the bot specification.

As the bot is automatically adapted to the data of the eCommerce shop hosting the bot, the bot logic communicates with the <a href="https://woocommerce.com/" target="_blank" rel="noopener">WooCommerce</a> API and stores some shop data into a <strong>SQL</strong> <a href="https://www.postgresql.org/" target="_blank" rel="noopener">PostgreSQL database</a>.

<h2>2. The NLP Engine</h2>
To determine which chatbot intent is the best match for the user textual input, we rely on <a href="https://github.com/axa-group/nlp.js/" target="_blank" rel="noopener">nlp.js</a> (in <strong>JS</strong>) though we are in the process of moving to our new<a href="https://github.com/xatkit-bot-platform/xatkit-nlu-server" target="_blank" rel="noopener"><strong> Python</strong> NLP server</a> for better optimization of the needs of eCommerce conversations. A <a href="https://github.com/xatkit-bot-platform/xatkit/wiki/Processors" target="_blank" rel="noopener">preprocessor language model</a> is also used to improve the chances of a matching.

<h2>3. The front-end</h2>
The eCommerce chatbot is implemented as a <a href="https://wordpress.org/plugins/xatkit-chatbot-for-woocommerce/" target="_blank" rel="noopener">WordPress plugin </a>in <strong>PHP </strong>whose mission is to simply embed in the proper PHP WP pages the <a href="https://github.com/xatkit-bot-platform/xatkit-chat-widget" target="_blank" rel="noopener">Xatkit widget</a> displaying the bot. The widget itself is a <a href="https://reactjs.org/" target="_blank" rel="noopener">react component</a> that talks with the server component managing the core chatbot logic via a <a href="https://en.wikipedia.org/wiki/WebSocket" target="_blank" rel="noopener">websocket</a>.

<h2>4. The configuration and monitoring component</h2>
Any non-trivial bot comes with a dashboard to configure the bot (e.g. removing some predefined conversations, adding new ones, ...) and monitor its results, showing, for instance, the user questions the bot was unable to understand.

Our eCommerce dashboard is a <a href="https://spring.io/" target="_blank" rel="noopener">Spring</a> application relying on <a href="https://www.thymeleaf.org/" target="_blank" rel="noopener">Thymeleaf </a>as server-side Java template engine and <a href="https://get.foundation/" target="_blank" rel="noopener">foundation</a> as responsive front-end framework.

<h2>All in all, chatbots are indeed a complex piece of engineering</h2>
Take a look at all the links above. We have 5 major programming languages (together with their package managers: maven, npm,...). 7 if we count HTML and CSS. Plus a myriad of auxiliary libraries and frameworks that require specialized knowledge, e.g. knowing Java doesn't mean you can master Spring in a breeze. Or even less that you would be able to create Java Fluent APIs.

If you don't have the luxury of having a large team with specialized profiles, maybe it's time to start testing all these <a href="https://livablesoftware.com/smart-intelligent-ide-programming/" target="_blank" rel="noopener">intelligent code assistants</a>. And I'm only half-joking.

Definitely, I feel we need better software engineering tools that help manage the complexity of these type of multi-language projects and their dependencies. For instance, we have (a few) tools for reverse engineering large codebases written in one language and help you understand and evolve it. But I don't know any that can do the same with a number of different repositories (we have over 80, including private ones, in <a href="https://github.com/xatkit-bot-platform" target="_blank" rel="noopener">Xatkit</a> !) in a mix of languages where the dependencies between the components are not as "easy" as looking for imports or references in the package manager definition.

While we wait for these tools to pop up, any tech question on the internals of <a href="https://xatkit.com/" target="_blank" rel="noopener">Xatkit </a>you'd like to know? And if you want to read more about the technologies we have listed above, this twitter thread gives some pointers to good tutorials for them:

{% embed https://twitter.com/g__daniel/status/1545179026666438657 %}