Skip to content
Merged

UI #84

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"permissions": {
"allow": [
"Bash(rg \"TrendingUpOutlined\" -A 2 -B 2)",
"Bash(cd C:UsersAdministratorDocumentsGitHubThorlobe)",
"Bash(npm run build:check)",
"Bash(npm run dev:*)",
"Bash(npm run lint)",
"Bash(npx eslint:*)",
"Bash(npx tsc:*)",
"Bash(npm run build:*)",
"Bash(npm install:*)",
"Bash(npm run:*)",
"Bash(cat:*)",
"Bash(for:*)",
"Bash(do echo \"=== $file ===\")",
"Bash(done)"
],
"deny": []
}
}
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// 使用 IntelliSense 找出 C# 调试存在哪些属性
// 将悬停用于现有属性的说明
// 有关详细信息,请访问 https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md。
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// 如果已更改目标框架,请确保更新程序路径。
"program": "${workspaceFolder}/src/Thor.Service/bin/Debug/net9.0/Thor.Service.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Thor.Service",
"stopAtEntry": false,
// 启用在启动 ASP.NET Core 时启动 Web 浏览器。有关详细信息: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"chatgpt.openOnStartup": false
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/Thor.Service/Thor.Service.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/Thor.Service/Thor.Service.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/src/Thor.Service/Thor.Service.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
213 changes: 213 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Thor is an enterprise-grade AI model management gateway that provides unified API access to manage and orchestrate multiple AI models. It's built with .NET 9 and React, supporting 20+ AI models with comprehensive user management, channel management, billing, and monitoring capabilities.

## Build and Development Commands

### Backend (.NET 9)
```bash
# Main service project
dotnet run --project src/Thor.Service/Thor.Service.csproj --urls "http://localhost:5000"

# Build the entire solution
dotnet build Thor.sln

# Run with specific configuration
dotnet run --project src/Thor.Service/Thor.Service.csproj --configuration Release

# Restore dependencies
dotnet restore

# Run tests (if available)
dotnet test

# Generate database migrations (example for SQLite)
dotnet ef migrations add MigrationName --project src/Provider/Thor.Provider.Sqlite/Thor.Provider.Sqlite.csproj --startup-project src/Thor.Service/Thor.Service.csproj --context Thor.Provider.SqliteThorContext --output-dir Thor
```

### Frontend (React + Vite)
```bash
cd lobe

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Build with TypeScript checking
npm run build:check

# Run linting
npm run lint

# Preview production build
npm run preview
```

### Full Project Build
```bash
# Windows
build.bat

# Linux/macOS
chmod +x build.sh
./build.sh
```

### Database Migrations
```bash
# Generate migrations for all supported databases
migrations.bat

# View migration logs
migrations.log.bat
```

## Code Architecture

### High-Level Structure
- **src/Thor.Service/** - Main ASP.NET Core web service and entry point
- **src/extensions/** - AI model provider integrations (OpenAI, Claude, Gemini, etc.)
- **src/framework/** - Building blocks for caching, events, and infrastructure
- **src/Provider/** - Database providers (SQLite, PostgreSQL, MySQL, SQL Server, DM)
- **src/Thor.Domain/** - Domain models and business logic
- **src/Thor.Core/** - Core services and application logic
- **src/Thor.Abstractions/** - Shared interfaces and DTOs
- **lobe/** - React frontend application

### AI Model Extensions Architecture
The system uses a plugin-based architecture where each AI provider is implemented as a separate extension:
- Each extension in `src/extensions/` provides services for a specific AI platform
- Extensions implement common interfaces for chat, embeddings, and other capabilities
- Providers are registered in `Program.cs` using extension methods (e.g., `.AddOpenAIService()`)

### Database Support
Multi-database support through provider pattern:
- Database type configured via `DBType` environment variable
- Supported: SQLite (default), PostgreSQL, MySQL, SQL Server, DaMeng
- Each provider implements the same interfaces with database-specific optimizations

### Frontend Architecture
- React 18 with TypeScript and Vite build system
- Ant Design UI components with custom theming
- Responsive design following mobile-first principles
- Internationalization support with i18next

## Key Configuration Files

### Backend Configuration
- **src/Thor.Service/appsettings.json** - Main application configuration
- **Directory.Build.props** - Shared MSBuild properties
- **NuGet.Config** - NuGet package source configuration

### Frontend Configuration
- **lobe/package.json** - Frontend dependencies and scripts
- **lobe/vite.config.ts** - Vite build configuration
- **lobe/tsconfig.json** - TypeScript configuration

## Environment Variables

Key environment variables for development and deployment:

```bash
# Database Configuration
DBType=sqlite # sqlite, postgresql, mysql, sqlserver, dm
ConnectionStrings:DefaultConnection=data source=/data/token.db
ConnectionStrings:LoggerConnection=data source=/data/logger.db

# Cache Configuration
CACHE_TYPE=Memory # Memory, Redis
CACHE_CONNECTION_STRING=localhost:6379

# Application Settings
RunMigrationsAtStartup=true
HttpClientPoolSize=100
TZ=Asia/Shanghai
```

## Development Practices

### Code Style
- Follow C# conventions and use built-in analyzers
- Use Mapster for object mapping instead of AutoMapper
- Implement proper async/await patterns throughout
- Use dependency injection extensively via built-in container

### Frontend Guidelines
- Follow Ant Design's design system and use theme tokens instead of hardcoded colors
- Use TypeScript strictly with proper type definitions
- Implement responsive design using Ant Design's breakpoint system
- Follow React hooks best practices and functional component patterns

### Database Operations
- Use Entity Framework Core with proper migrations
- Support multiple database providers through abstraction
- Implement proper transaction handling with Unit of Work pattern
- Use the ILoggerDbContext for logging-related operations

### AI Model Integration
- Each AI provider should implement common interfaces
- Handle rate limiting and error scenarios gracefully
- Support streaming responses where applicable
- Implement proper token counting and billing

## Common Development Tasks

### Adding a New AI Model Provider
1. Create new project in `src/extensions/Thor.{ProviderName}/`
2. Implement required interfaces (chat, embeddings, etc.)
3. Add extension method for service registration
4. Register the service in `Program.cs`
5. Update documentation and model lists

### Database Schema Changes
1. Create migration using appropriate provider context
2. Update all database providers consistently
3. Test migration on different database types
4. Update seed data if necessary

### Frontend Component Development
1. Use Ant Design components as foundation
2. Implement responsive behavior using breakpoints
3. Follow theming system with proper token usage
4. Add proper TypeScript interfaces
5. Test across different viewport sizes

## Testing and Quality

### Running Tests
- Backend tests: `dotnet test` (when test projects exist)
- Frontend linting: `cd lobe && npm run lint`
- Type checking: `cd lobe && npm run build:check`

### Build Verification
- Use `build.bat` or `build.sh` to verify full project builds
- Test database migrations on different providers
- Verify frontend build integration with backend

### Docker Support
- Main service Dockerfile: `src/Thor.Service/Dockerfile`
- Docker Compose configurations available for different scenarios
- Multi-architecture support (AMD64, ARM64)

## Troubleshooting

### Common Issues
- **Frontend build failures**: Clear `lobe/node_modules` and reinstall
- **Database connection issues**: Check `DBType` and connection strings
- **Missing AI provider**: Ensure extension is registered in `Program.cs`
- **CORS issues**: Verify AllowAll CORS policy is properly configured

### Performance Optimization
- Use Redis caching for production deployments
- Enable response compression for static assets
- Configure appropriate HTTP client pool sizes
- Monitor AI provider rate limits and implement fallbacks
Loading
Loading