Controllers & Business Logic
Relevant source files
The following files were used as context for generating this wiki page:
The Controllers and Business Logic layer of the Bridge AI platform serves as the intermediary between the client-side user interface and the backend service integrations, including AI models and external news APIs. This layer is responsible for processing user requests, enforcing security measures like rate limiting and authentication, and orchestrating data flow between the application and third-party services like OpenAI and Groq.
The architecture follows a modular approach where specific routes are mapped to controller functions or inline asynchronous handlers. Key functional areas include AI-driven networking assistance, automated article summarization, and user session management. Sources: BACKEND/src/app.js:1-32, BACKEND/src/routes/user.routes.js:1-30
AI Chatbot Logic
The Chatbot controller utilizes the LangChain framework to interface with the Groq AI model. It is designed as an AI networking assistant capable of finding professionals and suggesting engagement strategies.
Query Processing Flow
The controller receives a userQuery from the request body. It uses a structured prompt template consisting of a system instruction and the human message. The system instruction defines the bot's persona as an "AI networking assistant." Once the model generates a response, the controller uses regex to extract professional names and programmatically generates social media links (LinkedIn and Twitter) for those individuals.
The diagram above illustrates the sequential processing of a chatbot message from initial validation to external API invocation and data post-processing. Sources: BACKEND/src/controllers/chatbot.controller.js:100-145
Key AI Components
| Component | Implementation | Description |
|---|---|---|
| Model | llama3-8b-8192 | The specific LLM used for generating networking advice. |
| Framework | LangChain | Used for prompt templating and model invocation. |
| Link Generator | generateLinks() | Utility to create social links from extracted names. |
Sources: BACKEND/src/controllers/chatbot.controller.js:90-108
Article & Content Management
The business logic for articles involves a hybrid approach using a News API for data retrieval and OpenAI for content processing. Unlike standard CRUD operations, this module fetches live data based on user queries (defaulting to "entrepreneurship") and enhances it using AI.
Summarization Logic
The system implements a getSummary function that sends article descriptions or content to OpenAI's GPT-4 model. The logic limits the summary to 100 tokens to ensure conciseness.
The sequence diagram details how the backend orchestrates calls between a news provider and an AI provider before returning data to the frontend. Sources: BACKEND/src/routes/articles.routes.js:13-65
Security & User Management Logic
The user management logic is decentralized across controllers and route-level middleware. Business rules for security are enforced through JWT verification and rate limiting.
Rate Limiting and Validation
Specific business constraints are applied to sensitive routes to prevent abuse:
- Registration: Limited to 100 requests per 15 minutes to prevent bulk account creation.
- Logout: Limited to 100 requests per 15 minutes and requires a valid JWT.
- Authentication: Managed through
loginUserandrefreshAccessTokenfunctions.
Sources: BACKEND/src/routes/user.routes.js:7-30
API Structure
The application centralizes its business logic entry points in app.js, routing requests to specialized modules.
| Endpoint | Controller/Route File | Purpose |
|---|---|---|
/api/v1/users | user.routes.js | Authentication and profile management. |
/api/v1/chatbot | chatbot.routes.js | AI-powered professional networking. |
/api/v1/articles | articles.routes.js | Summarized news fetching. |
/api/v1/products | producthunt.routes.js | Product showcase and voting. |
Sources: BACKEND/src/app.js:25-31
Conclusion
The Controllers and Business Logic layer of the project effectively integrates multiple AI providers (OpenAI, Groq) with standard web backend practices. By utilizing LangChain for structured AI interactions and implementing robust middleware for security, the system provides a specialized networking and information platform for entrepreneurs. The logic ensures that raw data from external APIs is transformed into actionable insights through AI summarization and link generation.