fix: 确保项目可以启动

This commit is contained in:
2025-12-12 23:50:55 +08:00
parent c61ee69561
commit 4912e48922
21 changed files with 623 additions and 145 deletions

250
CLAUDE.md
View File

@@ -4,83 +4,193 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Overview
This is an AI-integrated OJ (Online Judge) judging system with a microservices architecture. The system allows users to submit code for programming problems, which is then judged automatically. It also includes AI features to assist with problem-solving and code evaluation.
This is a microservices-based Online Judge (OJ) system with AI integration called AIOJ (AI Online Judge). It's built with Spring Boot 3.5.7 and Spring Cloud 2025.0.0, following a modular Maven multi-module architecture.
## Architecture
The project follows a microservices architecture pattern built with Spring Boot and Spring Cloud Alibaba:
### Core Modules:
1. **aioj-backend-common**: Common utilities and dependencies shared across all modules.
2. **aioj-backend-gateway**: API gateway that routes requests to the appropriate microservices.
3. **aioj-backend-judge-service**: Handles code submission, compilation, and judging processes.
4. **aioj-backend-user-service**: Manages user accounts, authentication, and authorization.
5. **aioj-backend-question-service**: Manages programming problems and test cases.
6. **aioj-backend-ai-service**: Provides AI-assisted features such as code analysis and problem-solving.
7. **aioj-backend-auth**: Manages authentication and token issuance.
8. **aioj-backend-upms**: User Management System for administrative operations.
## Database
The system uses SQL databases. Database scripts can be found in the `db/` directory.
## Build System
The project uses Maven for build and dependency management.
### Common Commands:
- Compile the entire project:
```bash
mvn clean compile
```
- Compile a specific module:
```bash
mvn clean compile -pl <module-name>
```
- Package the entire project:
```bash
mvn clean package
```
- Package a specific module:
```bash
mvn clean package -pl <module-name>
```
## Development
### Environment Profiles
The project supports different environments (dev, test, prod) with corresponding configuration files:
- Development: application-dev.yml
- Test: application-test.yml
- Production: application-prod.yml
### Running a Service
To run a specific microservice, use the Spring Boot Maven plugin:
## Common Development Commands
### Building the Project
```bash
cd <module-name>
# Build entire project
mvn clean install
# Build with specific environment profile
mvn clean install -P dev # Development (default)
mvn clean install -P test # Testing
mvn clean install -P prod # Production
# Format code according to Spring standards
mvn spring-javaformat:apply
# Build Docker images using Jib
mvn clean package jib:build
# Or use Maven wrapper
./mvnw clean install
```
### Running Services
Each service runs on different ports:
- Gateway: 8085
- Other services: configured via Nacos
Run individual services from their respective directories:
```bash
cd aioj-backend-gateway
mvn spring-boot:run
# Or with specific profile
mvn spring-boot:run -Dspring.profiles.active=dev
```
Or run the built JAR file:
### Database Setup
1. Create databases using the provided script:
```bash
cd <module-name>/target
java -jar <module-name>-<version>.jar
mysql -u root -p < db/create_db.sql
```
This creates three databases: `aioj_dev`, `aioj_test`, and `aioj_prod`
## Architecture Overview
### Microservices Architecture
The system consists of seven main services:
1. **aioj-backend-gateway** (Port 8085)
- API Gateway using Spring Cloud Gateway
- Routes requests to appropriate services
- Built with WebFlux for reactive programming
2. **aioj-backend-auth**
- OAuth2 authentication and authorization service
- Manages user credentials and tokens
3. **aioj-backend-user-service**
- User management and profiles
- Handles registration, login, profile updates
- Integrates with Redis for session management
4. **aioj-backend-question-service**
- Problem/question management
- Handles problem storage and retrieval
5. **aioj-backend-judge-service**
- Core OJ functionality for code execution
- Supports multiple programming languages
6. **aioj-backend-ai-service**
- AI integration for enhanced features
- Code analysis and automated feedback
7. **aioj-backend-upms** (User Permission Management System)
- Role-based access control
- Permission management
### Common Modules
- **aioj-backend-common**: Shared utilities with sub-modules:
- `core`: Core utilities and configurations
- `log`: Custom logging implementation
- `starter`: Auto-configuration starters
- `mybatis`: Database access layer
- `feign`: HTTP client for service communication
- `bom`: Bill of Materials for dependency management
## Technology Stack
### Core Technologies
- **Java 17**
- **Spring Boot 3.5.7**
- **Spring Cloud 2025.0.0**
- **Spring Cloud Alibaba 2025.0.0.0**
- **Maven** for build management
### Database & Persistence
- **MySQL 9.4.0** as primary database
- **MyBatis-Plus 3.5.14** for ORM
- **Redis** for caching and session management
### Cloud & Infrastructure
- **Nacos** for service discovery and configuration (server: 10.0.0.10:8848)
- **Spring Cloud Gateway** for API routing
- **Docker** with Jib plugin for containerization
- **Sentinel** for circuit breaking
### Security
- **Spring Security 6.5.6** with OAuth2
- JWT token-based authentication
- Role-based access control
### API Documentation
- **Knife4j** (OpenAPI 3) integrated across services
## Configuration Management
### Environment-Specific Configuration
Three environments are supported:
- `dev` (development, default)
- `test` (testing)
- `prod` (production)
Configuration files:
- `bootstrap.yml` - Nacos service discovery configuration
- `application.yml` - Main application configuration
- `application-{env}.yml` - Environment-specific settings
### Nacos Integration
All services use Nacos for:
- Service discovery
- Configuration management
- Centralized properties management
Default Nacos configuration:
```yaml
spring:
cloud:
nacos:
discovery:
server-addr: 10.0.0.10:8848
username: nacos
password: nacos
```
## Technologies Used
## Database Schema
- **Java 17**: Programming language
- **Spring Boot 3.5.7**: Framework for building microservices
- **Spring Cloud Alibaba 2025.0.0.0**: Microservices ecosystem
- **Maven**: Build tool
- **Lombok**: Java library to reduce boilerplate code
### Environment Databases
- Development: `aioj_dev`
- Testing: `aioj_test`
- Production: `aioj_prod`
All databases use UTF-8 character set with `utf8mb4_general_ci` collation.
## Development Guidelines
### Code Formatting
- Uses Spring JavaFormat plugin for consistent code style
- IDE plugin available: https://repo1.maven.org/maven2/io/spring/javaformat/spring-javaformat-intellij-idea-plugin
- Run `mvn spring-javaformat:apply` before commits
### Docker Integration
- Jib plugin configured for container builds
- Target registry: `10.0.0.3/aioj/{service-name}:{version}`
- JVM memory configured: -Xms512m -Xmx512m
### Service Communication
- Uses OpenFeign for inter-service communication
- Load balancing with Spring Cloud LoadBalancer
- Circuit breaking with Sentinel
### Logging
- Custom logging implementation in `aioj-backend-common-log`
- Integrates with Spring Security for context logging
- Uses Hutool utilities for enhanced logging
## Testing
- Spring Boot Test framework included
- Spring Security Test for authentication testing
- Test structure is evolving - check individual modules for test coverage
## Important Notes
1. **Service Dependencies**: Services depend on Nacos for discovery - ensure Nacos is running before starting services
2. **Database Setup**: Run the database creation script before first run
3. **Port Configuration**: Gateway runs on 8085, other services are dynamically registered
4. **Environment Profiles**: Default is `dev` - use appropriate profiles for different environments
5. **Configuration Management**: Most configuration is externalized to Nacos - check Nacos for service-specific settings