Crystelf Core is a modern backend service built with NestJS that provides comprehensive API support for the Crystelf project. It integrates WebSocket communication, Redis caching, file management, and automatic updates.
- RESTful APIs: Standardized API interfaces built on NestJS
- Swagger Documentation: Auto-generated API docs at
/docs - Unified Response Format: Standardized API response structure
- Global Exception Handling: Centralized error handling and logging
- WebSocket Support: Real-time communication using
@nestjs/websockets - Client Management: Intelligent WebSocket client connection management
- Message Routing: Flexible message processing and distribution
- Heartbeat Monitoring: Automatic client connection status monitoring
- Redis Integration: High-performance caching and data storage
- File System: Local file management with CDN support
- Data Persistence: Local JSON file data storage
- Automatic Sync: Scheduled data updates
- Token Authentication: API access control via Bearer tokens
- Request Rate Limiting: IP-level request frequency control
- Traffic Control: Granular traffic monitoring and control
- Logging: Detailed request and error logs
- Framework: NestJS v11
- Language: TypeScript
- Runtime: Node.js
- Package Manager: pnpm
- WebSocket:
@nestjs/websockets,ws - Caching:
ioredis - Documentation:
@nestjs/swagger - File Processing:
multer,stream-throttle - Git Operations:
simple-git - Image Processing:
image-type
- Node.js (v18+ recommended)
- Redis server
- pnpm package manager
pnpm install- Copy the environment example file:
cp .envExample .env- Edit
.envwith your configuration:
# Redis Configuration
RD_PORT=6379
RD_ADD=127.0.0.1
# WebSocket Secret
WS_SECRET=your-secret-key
# API Access Token
TOKEN=your-api-token
# OpenList API Configuration
OPENLIST_API_BASE_URL=http://127.0.0.1:5244
OPENLIST_API_BASE_USERNAME=username
OPENLIST_API_BASE_PASSWORD=password
OPENLIST_API_MEME_PATH=//crystelf//meme
OPENLIST_API_CDN_PATH=//crystelf//cdn
OPENLIST_API_BASE_PATH=D:\alist# Development mode
pnpm start:dev
# Production mode
pnpm start:prod
# Using startup script (auto-restart)
./start.shAfter startup:
- API Service: http://localhost:6868/api
- API Documentation: http://localhost:6868/docs
POST /api/bot/getBotId- Get online bot listPOST /api/bot/getGroupInfo- Get group informationPOST /api/bot/reportBots- Broadcast bot status syncPOST /api/bot/sendMessage- Send group messagePOST /api/bot/broadcast- Broadcast to all groups
POST /api/words/getText- Get random textPOST /api/words/reloadText- Reload specified text (auth required)POST /api/words/listWords- Get text list
GET /api/meme- Get random memePOST /api/meme/get- Get random memePOST /api/meme/upload- Upload meme (auth required)
POST /api/system/systemRestart- System restart (auth required)POST /api/system/getRestartTime- Get last restart duration (auth required)
GET /cdn/*- Access CDN resourcesGET /public/files/*- Access public filesGET /public/cdn/*- Access public CDN resources
- Git Integration: Automatically detects and pulls code updates
- Dependency Management: Auto-installs dependencies and builds
- Scheduled Checks: Configurable update checking intervals
- Multi-Repository Support: Handles main repo and submodules
- OpenList Integration: Seamless integration with OpenList service
- Smart Comparison: Intelligent local vs remote file comparison
- Resume Support: Large file transfer with resume capability
- Directory Recursion: Complete directory structure synchronization
- IP Rate Limiting: Request frequency limits based on IP
- Traffic Statistics: Real-time usage statistics
- Smart Throttling: Intelligent speed limiting based on user permissions
- Concurrency Control: Connection limits to prevent resource abuse
- Redis Cache: High-performance Redis caching system
- Local Cache: Fast in-memory caching
- Cache Strategy: Intelligent expiration and cleanup policies
- Data Synchronization: Local and Redis data sync mechanisms
- Token Authentication: Bearer token-based API authentication
- WebSocket Authentication: Secret key authentication for WebSocket connections
- Access Control: Fine-grained API permission control
- Path Validation: Strict file path access verification
- Input Filtering: Comprehensive user input validation
- Error Handling: Secure error message responses
- Audit Logging: Complete operation logs
- Request Logs: Detailed HTTP request access logs
- Error Logs: System errors and exception logs
- Operation Logs: Important system operation records
- Performance Logs: System performance metrics
- System Status: Real-time system health monitoring
- Dependency Checks: External service health verification
- Resource Monitoring: System resource usage tracking
| Variable | Description | Default |
|---|---|---|
| RD_PORT | Redis port | 6379 |
| RD_ADD | Redis address | 127.0.0.1 |
| WS_SECRET | WebSocket auth secret | - |
| TOKEN | API access token | - |
| OPENLIST_API_BASE_URL | OpenList API URL | http://127.0.0.1:5244 |
| OPENLIST_API_MEME_PATH | Meme remote path | //crystelf//meme |
| OPENLIST_API_CDN_PATH | CDN remote path | //crystelf//cdn |
logs/: Log file storageconfig/: Configuration filestemp/: Temporary filesprivate/data/: User data storageprivate/words/: Text file storageprivate/meme/: Meme file storagepublic/: Public files and CDN resources
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Crystelf Core provides stable and efficient backend support for the Crystelf project.