Chat & Message Schemas
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Chat and Message schemas define the data structure for the communication layer of the Bridge AI platform. This system facilitates interactions between users and an AI networking assistant, powered by the LangChain and Groq frameworks. The schemas ensure organized storage of conversation sessions and individual message exchanges, enabling features like profile extraction and automated outreach strategy generation.
The architecture separates the high-level conversation container (Chat) from the granular message details (Message), establishing a one-to-many relationship. This structure supports persistent chat histories and provides the foundation for the AI-driven networking assistance found in the chatbot.controller.js.
Sources: BACKEND/src/models/Chat.model.js, BACKEND/src/models/message.model.js, BACKEND/src/controllers/chatbot.controller.js:106-111
Data Models and Architecture
Entity Relationships
The backend utilizes Mongoose to model the chat infrastructure. A Chat document serves as a session anchor for a specific user, while multiple Message documents reference a Chat ID to maintain chronological order.
The diagram above illustrates the relationship between users, their chat sessions, and individual messages.
Sources: BACKEND/src/models/Chat.model.js:4-7, BACKEND/src/models/message.model.js:5-21, BACKEND/src/models/User.model.js:5-35
Chat Schema
The Chat model is a lightweight container that links a conversation history to a specific registered user.
| Field | Type | Description | Constraints |
|---|---|---|---|
user | ObjectId | Reference to the User model | Required |
createdAt | Date | Timestamp of session creation | Default: Date.now |
Sources: BACKEND/src/models/Chat.model.js:5-7
Message Schema
The Message model captures the content, metadata, and state of individual exchanges within a chat session. It supports multiple media types and delivery statuses.
| Field | Type | Description | Values / Constraints |
|---|---|---|---|
chat_id | ObjectId | Reference to the parent Chat | Required |
sender | String | Originator of the message | "user", "bot" (Required) |
message | String | Actual text content | Required |
timestamp | Date | Time of message creation | Default: Date.now |
status | String | Current delivery state | "sent", "delivered", "read" |
type | String | Format of the message content | "text", "image", "audio" |
Sources: BACKEND/src/models/message.model.js:5-21
AI Processing Logic
The chatbot.controller.js implements the logic for processing queries within these schemas. It uses ChatGroq with the llama3-8b-8192 model to generate responses that are then stored or displayed via the frontend.
This flow shows how user input is processed by the AI and returned with enriched profile data.
Sources: BACKEND/src/controllers/chatbot.controller.js:102-159, frontend/front/src/chatbot/chatbot.jsx:153-176
Key Functions
- generateLinks(name): Converts a raw name into formatted social media URLs for Twitter and LinkedIn.
- Sources:
[BACKEND/src/controllers/chatbot.controller.js:113-120](https://github.com/Steve-Wayne/EICHackathon/blob/HEAD/BACKEND/src/controllers/chatbot.controller.js#L113-L120)
- Sources:
- processQuery(req, res): The primary handler for incoming chat requests. It utilizes
ChatPromptTemplateto structure messages for the AI model.- Sources:
[BACKEND/src/controllers/chatbot.controller.js:122-161](https://github.com/Steve-Wayne/EICHackathon/blob/HEAD/BACKEND/src/controllers/chatbot.controller.js#L122-L161)
- Sources:
Frontend Implementation
The ChatbotPage component manages the UI state for the chat system, handling the display of both user and bot messages, as well as the simulated typing effect.
State Management
The frontend maintains several state variables to handle the dynamic nature of the chat:
messages: An array of objects following the message schema structure (text,sender).profiles: A collection of extracted professional profiles returned by the backend.isTyping: A boolean flag to manage UI feedback during AI generation.
Sources: frontend/front/src/chatbot/chatbot.jsx:136-146
API Interaction
The frontend communicates with the backend via the /api/v1/chatbot/query endpoint.
const response = await fetch("http://localhost:8000/api/v1/chatbot/query", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userQuery: input }),
});
Sources: frontend/front/src/chatbot/chatbot.jsx:161-165, BACKEND/src/app.js:33
Summary
The Chat and Message schemas provide a robust structure for Bridge AI's networking capabilities. By linking messages to specific chat sessions and users, the system allows for structured data retrieval and AI-driven insights. The integration of metadata like status and type in the message model prepares the architecture for future multi-modal interactions beyond simple text exchanges.