How vungocthanhtruc/nlu-ai-bot works
Project Type & Purpose
• It’s clearly a full-stack chat application with Natural Language Understanding powered by LLMs.
• The frontend is built using TypeScript (React) that provides the chat UI (inspired by Figma designs for both Light and Dark themes), while the backend uses FastAPI (Python) for REST endpoints and real-time communication (via websockets).
• Additionally, the project leverages external technologies such as HuggingFace for LLM integration and PostgreSQL for persistent storage.
Analyzing the File Structure
• The top-level structure splits between backend (FastAPI) and frontend (React-based, found under src and public).
• The backend directory is further structured with clear separation for:
• CRUD modules (in the “crud” folder) for handling core operations on chats, rooms, and users.
• Data models (in the “models” folder) and corresponding schemas (in “schemas”) ensuring data validation and structure.
• Routers (in “routers”) that form the API endpoints for various functionalities (chats, rooms, users, dataset).
• A dedicated “websocket” folder that suggests a real-time messaging component.
• The frontend comes with detailed components (e.g., chatFooter, header, mainChat, sidebar) and also includes Redux slices for state management plus a standalone websocket server in the src/websocket directory (likely to simulate or proxy real-time communication).
• Presence of configuration files (like .env, package.json, tsconfig.json, and backend/requirements.txt) indicates dependency and environment management.
Additional Insight from the README
• The README mentions technical details like integrating LLMs, HuggingFace, FastAPI, and PostgreSQL.
• It outlines steps to run both the frontend (npm start) and backend (uvicorn command).
• The reference to a Figma design further confirms the importance of a strong, well-architected frontend.
Components
a. Main Components:
• Frontend Application:
• React-based UI (components for header, chat list, chat footer, sidebar, etc.)
• Redux state management (store, slices) for managing UI state and chat data.
• Static assets (public folder) supporting design (manifest, index.html, etc.)
• Backend Application:
• REST API endpoints using FastAPI, including routers for chats, rooms, users, and dataset.
• Data processing layers including CRUD modules, data models, and schema validations.
• Websocket layer for real-time bidirectional communication.
• Database:
• PostgreSQL used for persisting user, chat, and room data (implied by README).
• External Services:
• Third-party LLM integrations (HuggingFace API/LLMs).
• Possibly additional services/tools (popper, tessera referenced in README notes for Windows).
b. Relationships and Interactions:
• The frontend sends HTTP requests to FastAPI REST endpoints and establishes websocket connections for real-time chat updates.
• FastAPI controllers (routers) interact with the CRUD layer to perform database operations.
• The CRUD layer communicates with PostgreSQL through a database connection module.
• Integration points for LLM processing can be highlighted where backend processing calls external HuggingFace APIs for chat responses.
• The frontend’s Redux store refreshes state based on responses from the backend, ensuring the UI reflects real-time data and updates.
c. Architectural Patterns & Design Principles:
• Separation of Concerns: Clear division between frontend (UI) and backend (API, business logic).
• Modular Design: The backend is broken into routers, CRUD, models, schemas, and websockets, supporting maintainability and scalability.
• Real-Time Communication: Use of websockets to provide immediate feedback within the chat system.
• Integration of external machine learning models (LLMs via HuggingFace) to process and generate chat responses.
d. Relevant Technologies/Frameworks:
• Frontend: React, TypeScript, Redux, CSS modules.
• Backend: Python, FastAPI, Uvicorn.
• Database: PostgreSQL.
• External/Misc: HuggingFace’s LLMs, supporting tools for environment management (.env files), and a node.js–based websocket server for additional support.