$ show coaidev/coai
CoAI (formerly ChatNio) is a full-stack AI chat platform and LLM gateway that provides a unified chat interface and OpenAI-compatible API proxy for 16+ AI model providers (OpenAI, Anthropic Claude, Google Gemini, Midjourney, DeepSeek, etc.). The system is built with a Go backend (Gin framework) and a React/TypeScript frontend (Redux, Tailwind CSS, Radix UI), with MySQL and Redis for persistence and caching. It supports real-time WebSocket chat, streaming responses, conversation management, file upload, web search, image generation, and a plugin system (MCP). The platform includes a comprehensive billing and subscription system with elastic per-token pricing and tiered plans (Basic/Standard/Pro), along with an admin dashboard for user management, channel configuration, analytics (model usage, request volume, revenue, errors), and system settings. It also features invitation codes, redeem codes, affiliate marketing, and multiple payment gateway integrations (Stripe, WeChat Pay, etc.). Architecturally, the backend employs an adapter pattern for AI providers, a channel manager for load balancing and retries, and a WebSocket connection manager with rate limiting. The frontend is heavily componentized with shadcn/ui and includes i18n support (English, Chinese, Japanese, Russian). Deployment is supported via Docker Compose, Zeabur, and a Tauri desktop app. While the codebase is well-structured and feature-rich, it shows signs of technical drift such as copy-pasted processor files across adapters, hardcoded model constants, and a large dependency surface. The open-source version is Apache 2.0 licensed, with a commercial 'CoAI Pro' tier offering additional features.
The LLM identified 4 files worth highlighting for reuse:
Defines the core adapter interface (CreateChatRequest, CreateStreamChatRequest) that all AI provider implementations must satisfy. This clean abstraction allows adding new providers with minimal changes to the rest of the system. The interface is minimal and focused, making it a reusable pattern for any multi-provider API gateway.
Implements a priority-based load balancer with weight randomization for distributing requests across multiple AI channels. Channels are selected based on priority (lower is higher) and weight (higher is more likely), with retry logic and caching. This component is self-contained and can be extracted for any service requiring weighted round-robin or priority-based request distribution.
Manages WebSocket connections with rate limiting (token bucket), message queue, and stack-based processing. Provides Lock/Release for concurrency control and a ReadWorker for streaming responses. The pattern is reusable for any real-time application needing connection lifecycle management and rate enforcement.
Provides generic utility functions for slice operations (Each, Filter, Map, Sort, etc.), JSON marshaling/unmarshaling, and type conversions. These are implemented using Go generics and are fully self-contained, making them directly reusable in any Go project for common data manipulation tasks.