Configuration & Constants
Relevant source files
The following files were used as context for generating this wiki page:
The configuration and constants within the EICHackathon project define the operational parameters for both the Node.js backend and the React frontend. These settings manage environment-specific variables, API integrations with external services like OpenAI and NewsAPI, and security configurations for user authentication and data persistence.
The system utilizes a central configuration pattern where sensitive credentials and operational limits (such as token counts and expiry times) are abstracted into environment variables, while application-level defaults (such as default search queries) are hardcoded within the logic to ensure fallback availability.
Backend Environment Configuration
The backend environment relies on dotenv for managing sensitive credentials and integration keys. These constants are critical for the functionality of AI-driven features and secure session management.
AI and News Service Integration
The application integrates with multiple AI models and news aggregators. Configuration for these services involves API keys and specific model identifiers.
| Variable Name | Description | Source |
|---|---|---|
OPENAI_API_KEY | Key for OpenAI GPT-4 summarization services | BACKEND/src/routes/articles.routes.js:9 |
NEWS_API_KEY | Key for NewsAPI to fetch trending articles | BACKEND/src/routes/articles.routes.js:10 |
GROQ_API_KEY | Key for Groq Cloud to power the Llama3 chatbot | BACKEND/src/controllers/chatbot.controller.js:77 |
llama3-8b-8192 | Hardcoded model identifier for ChatGroq | BACKEND/src/controllers/chatbot.controller.js:78 |
Security and Authentication Constants
Authentication is governed by JSON Web Token (JWT) configurations defined in the User model and environment variables.
- Access Token Secret: Used for signing short-lived session tokens.
- Refresh Token Secret: Used for generating long-lived tokens for session persistence.
- Expiry Constants:
ACCESS_TOKEN_EXPIRYandREFRESH_TOKEN_EXPIRYdefine the lifespan of these tokens.
Sources: BACKEND/src/models/User.model.js:62-81
Application Logic Defaults
The system defines several hardcoded constants and default parameters within its controllers and routes to maintain stability when user input is absent.
Article Retrieval Constants
When fetching articles, the system applies a default topic and a limit on the number of results to optimize performance and AI costs.
- Default Query:
"entrepreneurship"is used if no search query is provided. - Slice Limit: The backend limits article processing to the first 5 results from the NewsAPI response.
- Max Tokens: OpenAI summarization is constrained to
100tokens to ensure concise summaries.
Sources: BACKEND/src/routes/articles.routes.js:19-45
Chatbot System Instructions
The AI's personality and functional constraints are defined via constant string templates used as system prompts.
The diagram above shows how the constant systemInstruction ("You are an AI networking assistant...") acts as a logic filter for the AI model processing.
Sources: BACKEND/src/controllers/chatbot.controller.js:82-85
Frontend Endpoint Configuration
The frontend communicates with the backend via hardcoded URI constants. These define the entry points for the different modules of the application.
API Base URLs
The frontend components use the following local development endpoints to interact with the backend:
- Articles API:
http://localhost:8000/api/v1/articles - Chatbot API:
http://localhost:8000/api/v1/chatbot/query - Products API:
http://localhost:8000/api/v1/products
Sources: frontend/front/src/Article/article.jsx:110, frontend/front/src/chatbot/chatbot.jsx:195, frontend/front/src/Products/Productspage.jsx:105
Data Models and Schemas
The configuration of the database layer is handled through Mongoose schemas, which define the structure and constraints of the persistent data.
User Schema Constants
The User model defines specific constraints for user data validation:
| Field | Constraints |
|---|---|
username | Required, Unique, Lowercase, Trimmed, Indexed |
email | Required, Unique, Lowercase, Trimmed |
fullName | Required, Trimmed, Indexed |
password | Required |
The class diagram represents the structure of the User entity as configured in the backend models.
Sources: BACKEND/src/models/User.model.js:5-84
Summary
The "Configuration & Constants" system in EICHackathon provides the necessary bridge between raw code and environmental execution. By centralizing API keys, model parameters, and security tokens, the project maintains a separation between business logic and environment-specific data, while hardcoded defaults in the frontend and backend ensure a consistent user experience.