How rfym21/qwen2api works
Project type and purpose
• Qwen2API is a full-stack application consisting of:
• A Vue.js single-page frontend (under public/)
• A Node.js/Express backend API (under src/)
• Its purpose is to expose a chat-model interface and image upload pipeline over HTTP, with optional Redis/file persistence and Docker deployment.
File structure
• Top-level:
• Dockerfile, docker-compose.yml (and docker-compose-redis.yml) for containerized deployment
• .env.example for runtime configuration
• data/ for local JSON persistence template
• Frontend: under public/
• public/src/ holds Vue components, routes, assets
• public/index.html, vite.config.js, tailwind.config.js
• Backend: under src/
• src/server.js is the Express entry point
• src/router/ defines REST endpoints (accounts.js, chat.js, images.js, …)
• src/lib/ contains service layer modules (account management, Redis client, image upload, request wrappers)
• src/config.js centralizes configuration values
README for additional insights
• Environment variables drive API prefix, port, API key, Redis URL, account list, data save mode
• Key endpoints:
• GET /v1/models
• POST /v1/chat/completions
• POST /v1/images/generations (legacy)
• Supports three persistence modes: none, local file, Redis
a. Main components
• Client Browser (users)
• Frontend SPA (Vue.js)
• Backend HTTP Server (Express)
• Internal Service Layer (modules under src/lib)
• Data Layer:
• File System (data/ folder)
• Redis (optional, via REDIS_URL)
• External AI Model Service (Qwen API or Hugging Face inference)
b. Relationships & interactions
1. Browser ↔️ Frontend SPA (HTTP/WS)
2. SPA → Backend API (HTTP calls to /v1/*)
3. Backend Router → Service Layer modules (account.js, request.js, upload.js…)
4. Service Layer → External Model Service (chat completions, image generation)
5. Service Layer → Data Layer (persist messages/images to file or Redis)
6. Optional: Backend ↔️ Redis for caching tokens, conversation state
c. Architectural patterns & design principles
• Separation of concerns: routing, business logic (lib), configuration
• Pluggable persistence: file vs. Redis determined by DATA_SAVE_MODE
• Single entry point (server.js) routing to modular routers
• Stateless request handling with optional state in Redis
d. Key technologies & frameworks
• Vue 3 + Vite + Tailwind CSS for frontend
• Node.js + Express for backend
• Upstash Redis (TLS) or local Redis instance
• Docker & Docker Compose for deployment
• dotenv/config for environment management
Detail without over-splitting
• Router and service module as a component only if it has distinct responsibilities
• How environment variables (API_KEY, REDIS_URL, DATA_SAVE_MODE) toggle behavior in the backend