A Node.js/TypeScript API for AI-powered chat functionality with WebSocket support, LangChain integration, and PostgreSQL database.
- AI Chat: Interactive chat with AI using LangChain and LangGraph
- WebSocket Support: Real-time communication
- Authentication: JWT-based authentication
- Database: PostgreSQL with Knex.js ORM
- Stream Doctor: Advanced log analysis for video streaming systems
- Docker Support: Containerized deployment
- CLI Interface: Command-line interface for testing
- Node.js 18+
- PostgreSQL (optional, can use in-memory storage)
- Docker and Docker Compose (for containerized deployment)
- Clone the repository:
git clone <repository-url>
cd ai-chat-api- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration- Start the development server:
npm run dev- Build and start the services:
docker-compose up -d --build- Access the API:
- API: http://localhost:3001
- Mock Server: http://localhost:3003
The application includes support for local mock binary logs for testing the Stream Doctor functionality:
- Setup Mock Logs:
# The mock-logs directory is already created with the proper structure
ls -la mock-logs/binlog/
# active/ done/- Add Sample Data:
# Copy your binary log files to the mock directories
cp your_logs/*.bin mock-logs/binlog/active/
cp your_completed_logs/*.bin mock-logs/binlog/done/- Configure Environment:
# In your .env file
LOCAL_LOGS_PATH=./mock-logs- Run with Docker:
docker-compose up -dThe mock logs will be mounted to /var/log/foundation inside the container, allowing the Stream Doctor Graph to analyze them just like real production logs.
Key environment variables for Docker development:
LOCAL_LOGS_PATH: Path to local mock logs directory (default:./mock-logs)STORAGE_TYPE: Database type (memoryorpostgres)PORT: API server port (default:3001)
The project uses Knex.js for managing database migrations.
- Run all pending migrations:
npm run migrate - Create a new migration:
npm run migrate:make migration_name - Rollback the last batch of migrations:
npm run migrate:rollback
Migration files are stored in src/infra/database/migrations.
The project includes seed data for development purposes.
- Run database seeds:
npm run seed
Seed files are stored in src/infra/database/seeds.
To reset the database (useful during development):
npm run db:resetThis will rollback all migrations, reapply them, and seed the database.
Run the development server with hot reloading:
npm run devRun all tests:
npm testRun unit tests:
npm run test:unitRun integration tests:
npm run test:integrationnpm run build
npm startGET /api/health- Server health check
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
GET /api/chats- Get all chats for authenticated userPOST /api/chats- Create a new chatGET /api/chats/:chatId- Get a specific chatPUT /api/chats/:chatId/title- Update chat titleDELETE /api/chats/:chatId- Delete a chatGET /api/chats/:chatId/messages- Get messages for a chat
Connect to WebSocket with authentication token:
ws://localhost:3000?token=your_jwt_token
create_chat- Create a new chatget_chats- Get all chats for the userget_chat_messages- Get messages for a specific chatchat_message- Send a message to the AI
ISC