CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Bella OpenAPI is a multi-module Maven project that provides an OpenAPI gateway for AI services. It acts as a unified interface supporting multiple AI providers (OpenAI, AWS Bedrock, Alibaba Cloud, Huoshan, etc.) through a pluggable adapter pattern.
Module Architecture
- sdk/: Core SDK with protocol definitions, DTOs, and client interfaces
- spi/: Service Provider Interface module with authentication and session management (CAS/OAuth)
- server/: Main Spring Boot application with REST endpoints and business logic
Build & Development Commands
Basic Maven Commands
# Build all modules
mvn clean compile
# Run tests
mvn test
# Package without tests
mvn package -DskipTests
# Install to local repository
mvn install -DskipTests
Development Scripts
# Build the application
./build.sh
# Run the application (with optimized JVM settings)
./run.sh
# Generate jOOQ code from database schema
mvn jooq:generate -pl server
Key Architecture Patterns
Protocol Adapter Pattern
The core architecture uses the AdaptorManager pattern to route requests to different AI providers:
AdaptorManager
manages protocol adapters for each endpointIProtocolAdaptor
interface defines how to communicate with each provider- Adapters are organized by endpoint type (completion, embedding, tts, asr, etc.)
Multi-Layer Architecture
- Controllers (
endpoints/
): REST API endpoints - Interceptors (
intercept/
): Cross-cutting concerns (auth, quotas, metrics) - Protocol Layer (
protocol/
): Provider-specific adapters - Repository Layer (
db/repo/
): Database access with jOOQ
Database Integration
- Uses jOOQ for database access with code generation
- Generated POJOs and Records in
server/src/codegen/
- Database schema initialization scripts in
server/sql/
Configuration
- Main config:
server/src/main/resources/application.yml
- Multi-environment support with profile-specific configs
- Uses Redis for caching (Redisson) and JetCache for L1/L2 caching
- Apollo configuration center support (optional)
Testing
- Test configuration:
application-ut.yml
- API test files in
server/src/test/resources/
- Mock implementations available for each protocol adapter
Key Directories
server/src/main/java/com/ke/bella/openapi/endpoints/
: REST controllersserver/src/main/java/com/ke/bella/openapi/protocol/
: Provider adaptersserver/src/main/java/com/ke/bella/openapi/intercept/
: Request/response interceptorssdk/src/main/java/com/ke/bella/openapi/protocol/
: Protocol DTOs and interfacesserver/src/main/resources/lua/
: Lua scripts for Redis operations
Request Processing Flow
The typical request flow follows this pattern:
- Endpoint Controller receives HTTP request and validates basic parameters
- Interceptors handle authentication, authorization, quotas, and safety checks
- Channel Router selects appropriate provider/channel based on load balancing and cost
- Protocol Adapter transforms request to provider-specific format
- Cost Handler calculates and records usage metrics
- Response Processing handles streaming/non-streaming responses and metrics collection
Channel and Provider Management
- Channels represent specific provider instances with their own configurations
- Models define available AI models and their capabilities per provider
- API Keys manage authentication and usage quotas per space/user
- Spaces provide multi-tenant isolation with separate configurations
Development Notes
- When adding new AI providers, implement
IProtocolAdaptor
and register withAdaptorManager
- Protocol-specific DTOs go in SDK module, implementation in server module
- Cost calculation and metrics collection are handled through dedicated handlers
- Some endpoints support both streaming and non-streaming responses