AI-driven marketing strategy workflow engine.
MarketInsight is a project that leverages artificial intelligence to drive marketing strategy workflows. It aims to assist marketers in formulating and executing marketing strategies more efficiently.
- Backend Framework: NestJS (Node.js) for a scalable, modular architecture.
- AI Workflow Management: LangGraph.js for managing complex, stateful LLM agent workflows.
- Asynchronous Processing: BullMQ + Redis for robust task queuing and background job execution.
- Persistence Layer: Prisma ORM with MySQL for structured data storage and historical tracking.
- API Documentation: Swagger/OpenAPI for interactive API exploration and testing.
MarketInsight follows a Producer-Consumer pattern to handle long-running LLM operations without blocking the main API thread:
- Ingestion: Clients submit campaign requests via JWT-protected REST endpoints.
- Persistence & Enqueue: The system validates input, creates a campaign record in MySQL, and enqueues a background job in BullMQ.
- Asynchronous Processing: A dedicated CampaignProcessor worker dequeues jobs and invokes LangGraph agents to execute the campaign workflow.
- Incremental Task Execution: The agent processes tasks sequentially, persisting intermediate outputs and state transitions to the database in real-time. This enables progress tracking, fault recovery, and result replay.
- Result Aggregation & Completion: Upon finishing all tasks, the system aggregates the final strategy report, updates the campaign status, and makes results available for client retrieval via REST API.
- Asynchronous Workflow: Decouples API responses from heavy LLM processing to ensure high availability.
- Stateful Persistence: Comprehensive, timestamped records of agent reasoning, intermediate outputs, and task status transitions are persisted to support auditability, reproducibility, debugging, and historical analysis.
- Multi-Model Extensibility: A modular adapter layer allows seamless integration of various LLM providers (OpenAI, Deepseek, etc.).
- Enterprise-Ready Security: Built-in JWT authentication, strict DTO validation, and comprehensive error handling.
- Node.js (v24.11.1+)
- MySQL 9.5+
- Redis 8.4+
-
Clone the Repository:
git clone https://github.com/qzhao19/MarketInsight.git cd MarketInsight -
Verify Node.js Version:
# If using nvm nvm use # Verify versions node --version # Should be v24.11.1+ npm --version # Should be v10.0+
-
Install Dependencies:
npm install
-
Environment Setup: MarketInsight uses multiple environment configuration files to organize settings by category. Copy the example files and configure them according to your environment:
-
Base Configuration (.env.base): Copy
env/.env.base.exampleto.env.baseand configure basic application settings such asNODE_ENV,PORT,APP_NAME, andAPP_VERSION. -
Database Configuration (.env.db): Copy
env/.env.db.exampleto.env.dband set up your MySQL database connection. Key variables includeDATABASE_URL,DB_HOST,DB_PORT,DB_NAME,DB_USERNAME, andDB_PASSWORD. Ensure the database exists and the user has appropriate permissions. -
LLM Configuration (.env.llm): Copy
env/.env.llm.exampleto.env.llmand configure LLM-related settings, including circuit breaker parameters, rate limiting, retry logic, model parameters (e.g.,DEFAULT_MODEL_NAME,DEFAULT_MODEL_TEMPERATURE), and workflow timeouts. Adjust these based on your LLM provider's requirements and performance needs. -
Secrets and API Keys (.env.secrets): Copy
env/.env.secrets.exampleto.env.secretsand add your sensitive API keys. This includesLLM_API_KEYfor your LLM provider (e.g., DeepSeek or OpenAI),LLM_BASE_URLfor the API endpoint, andSERPER_API_KEYfor web search functionality.
Example configuration for development:
cp env/.env.base.example .env.base cp env/.env.db.example .env.db cp env/.env.llm.example .env.llm cp env/.env.secrets.example .env.secrets # Edit the files with your actual values -
-
Database Migration:
MarketInsight provides an automated database setup script that handles all initialization steps:
# Make the script executable (first time only) chmod +x script/setup-db.sh # Run the automated setup script ./script/setup-db.sh
The script will:
- Verify MySQL and Node.js installations
- Execute
script/setup-db.sqlto create the database and user - Push Prisma schema to the database (
npm run prisma:push) - Generate Prisma client (
npm run prisma:generate)
Manual Setup (Alternative):
If you prefer to run the steps manually:
# 1. Create database and user mysql -u root -p < script/setup-db.sql # 2. Push Prisma schema to database npm run prisma:push # 3. Generate Prisma client npm run prisma:generate
Troubleshooting:
- If MySQL connection fails, verify your credentials in
.env.db - Ensure MySQL server is running:
brew services start mysql(macOS) orsudo systemctl start mysql(Linux) - Check that the database user has appropriate permissions
- Run Unit Tests:
npm test -- tests/*.test.ts
This project is licensed under the MIT License - see the LICENSE file for details.