How coaidev/coai works
Based on our analysis of the file structure and README content, Chat Nio is a comprehensive, full-stack AIGC solution designed to serve both web clients and API consumers. It combines a feature-rich React-based frontend (including support for multi-device and PWA) with a robust Golang-based backend that manages authentication, AI model integrations, billing, channel management, and administrative functions. In addition, there are multiple “adapter” modules that encapsulate integrations to various AI service providers (e.g., OpenAI, Azure OpenAI, Midjourney, etc.) to support a wide range of models and functionalities.
• Frontend Application:
• Backend Application:
– Use the Golang code (main.go, and folders such as “manager”, “auth”, “channel”, “connection”, “globals”, “middleware”, “utils”) as one major block. This layer is implemented with Gin and handles the API endpoints, business logic, and channel/scheduling for AI requests.
• Adapter Modules:
• Administrative / Management Services:
• Data Persistence & Caching:
• Additional Modules:
– The “addition” folder includes extra functionalities (article generation, card services, web search, etc.) that may be drawn as independent modules that interact with the backend.
• External Services & Integrations:
• API Gateway / Proxy:
– Note that the system supports OpenAI API compatible endpoints (/v1/chat/completions, /v1/images, etc.), so show that there is a proxy layer in the backend for API distribution.
Relationships and Interactions
• Link the backend with the adapter modules – indicate that certain components in the backend (such as routers and managers) call out to specific adapters. For example, a chat request may flow from the backend’s “manager” layer to one of the “adapter” implementations (Azure, OpenAI, etc.), each of which then follows its own chain of processing (e.g., chat.go, processor.go).
• If applicable, show that the admin panel (internal route under frontend or via separate protected endpoints) communicates with backend management APIs.
Architectural Patterns and Design Principles
• Modularization: Emphasize that the project is divided into clear logical modules (frontend, backend, adapters, admin) with separation of concerns.
• API Proxying & Gateway: Note that the backend is structured to support both UI-based interactions and OpenAI-compatible API calls, which is central to its design.
• Microservice/Adapter Pattern: Even though it’s a monorepo, the “adapter” folder demonstrates an adapter pattern helping integrate various external AI engines.
• PWA & Desktop: The frontend is designed both as a web app and a desktop application (via Tauri), so indicate this dual-consumer support.
• Scalability & Caching: Show caching layers (Redis) and load-balanced channels in the channel management modules to underline scalability.
Specify Technologies, Frameworks, and Integration Points
• Frontend: React, Redux, Tailwind CSS, Vite, PWA, and Tauri for desktop.
• Backend: Golang, Gin framework, Redis, MySQL.
• Adapters: Custom Golang modules for different AI providers (Azure, OpenAI, Bing, Claude, etc.).
• Infrastructure: Docker, Docker Compose, a variety of CI/CD workflows, and deployment scripts.
• Others: WebSockets (for real-time communication) and support for file parsing, Markdown rendering, etc.