This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Bella OpenAPI is an AI API gateway that provides unified access to multiple AI services (chat completion, embeddings, ASR, TTS, image generation). It's a production-grade system serving 150M+ daily API calls at Beike (KE Holdings). The project consists of a Java Spring Boot backend (api/) and a Next.js frontend (web/), deployed via Docker.
# Start all services with Docker
./start.sh
# Start with specific configurations
./start.sh --build # Rebuild services
./start.sh --rebuild # Force rebuild without cache
./start.sh --nginx-port 8080 # Use custom port
./start.sh --server https://domain.com # Set server domain
./start.sh --skip-auth # Skip admin authorization
# OAuth configuration
./start.sh --github-oauth CLIENT_ID:SECRET --google-oauth CLIENT_ID:SECRET
# Stop services
./stop.shcd api/
# Build the project
mvn clean compile
mvn clean package -DskipTests
# Generate jOOQ code from database
mvn jooq:generate -pl server
# Build script (compiles and prepares release)
./build.sh
# Run locally with optimized JVM settings
./run.shcd web/
# Development
npm run dev # Start dev server (http://localhost:3000)
npm run build # Build for production
npm run start # Start production server
npm run lint # Run linting- api/sdk/: Protocol definitions, DTOs, client interfaces
- api/spi/: Authentication and session management (OAuth, CAS)
- api/server/: Main Spring Boot application with REST endpoints
The core uses AdaptorManager to route requests to different AI providers:
IProtocolAdaptorinterface for each provider (OpenAI, AWS Bedrock, Alibaba Cloud, etc.)- Adapters organized by endpoint type (completion, embedding, tts, asr)
- Channel-based routing with load balancing and cost optimization
- Endpoint Controller receives HTTP request
- Interceptors handle auth, quotas, safety checks, concurrent limits
- Channel Router selects provider based on load balancing/cost
- Protocol Adapter transforms request to provider format
- Cost Handler calculates and records usage metrics
- Response Processing handles streaming/non-streaming responses
- jOOQ for database access with code generation
- Multi-level caching: Local (Caffeine) + Distributed (Redis/Redisson)
- High-performance logging: Disruptor-based async processing
- Distributed rate limiting: Redis + Lua scripts with sliding window
api/server/src/main/resources/application.yml- Main backend configweb/src/config.ts- Frontend API configurationdocker-compose.yml- Multi-service orchestration- Database initialization:
api/server/sql/*.sql
api/server/src/main/java/com/ke/bella/openapi/endpoints/- REST controllersapi/server/src/main/java/com/ke/bella/openapi/protocol/- Provider adaptersapi/server/src/main/java/com/ke/bella/openapi/intercept/- Request interceptorsapi/server/src/main/resources/lua/- Redis Lua scripts for rate limiting
web/src/app/- Next.js App Router pagesweb/src/app/playground/v1/- API testing interfaces (chat, audio, embeddings)web/src/components/- React components (feature-organized)web/src/lib/api/- API client functions
- Spaces: Provide tenant isolation with separate API keys and configurations
- API Keys: Hierarchical structure with quotas and permissions
- Models: Define available AI models per provider with feature capabilities
- Channels: Provider instances with specific configurations
- Implement
IProtocolAdaptorinterface inapi/server/src/main/java/com/ke/bella/openapi/protocol/ - Add protocol-specific DTOs in
api/sdk/src/main/java/com/ke/bella/openapi/protocol/ - Register adapter with
AdaptorManager - Update frontend components in
web/src/components/if needed
Backend tests need to connect mysql database to run tests, so can't run backend tests in claude.
# Run backend tests
cd api/
mvn test # Run all tests
mvn test -pl server # Run server module tests only
mvn test -Dtest=ChatControllerTest # Run specific test class
# Run frontend tests
cd web/
npm run lint # Run ESLint linting- API tests in
api/server/src/test/resources/ - Test configuration:
api/server/src/test/resources/application-ut.yml - Mock implementations available for each protocol adapter
- Supports dev/test/prod environments with profile-specific configs
- Apollo configuration center integration (optional)
- Extensive proxy and OAuth configuration options
cd api/
mvn jooq:generate -pl server # Generate jOOQ code from database schema- Generated POJOs and Records in
api/server/src/codegen/java/ - Database schema initialization scripts in
api/server/sql/ - Re-run code generation after database schema changes
- Protocol Adapter Problems: Check
AdaptorManagerregistration and provider-specific logs - Rate Limiting Issues: Examine Redis Lua script execution in
api/server/src/main/resources/lua/ - Database Connection Issues: Verify Docker MySQL container health and connection settings
- Frontend Development Mode: Use
cd web/ && npm run devfor hot reload (avoid Docker dev mode)
# In application.yml for debugging
logging.level.org.jooq.tools.LoggerListener: DEBUG # SQL logging
logging.level.com.ke.bella.openapi.intercept: DEBUG # Request/Response logging
jetcache.statIntervalMinutes: 1 # Cache statistics