This file provides guidance to an AI coding tool when working with code in this repository.
HugeGraph Server is the graph engine layer of Apache HugeGraph, consisting of:
- REST API Layer (hugegraph-api): RESTful APIs for graph operations, Gremlin/Cypher queries, schema management, and authentication
- Graph Engine Layer (hugegraph-core): TinkerPop 3 implementation, schema management, traversal optimization, task scheduling
- Backend Interface: Abstraction layer for pluggable storage backends
- Storage Backend Implementations: RocksDB (default), HStore (distributed), and legacy backends (MySQL, PostgreSQL, Cassandra, ScyllaDB, HBase, Palo)
Technology: Java 11+, Maven 3.5+, Apache TinkerPop 3.5.1, Jersey 3.0 (REST), gRPC (distributed communication)
# Build all modules (from hugegraph-server directory)
mvn clean install -DskipTests
# Build with tests
mvn clean install
# Build specific module
mvn clean install -pl hugegraph-core -am -DskipTests# Run checkstyle validation
mvn checkstyle:check
# Checkstyle runs automatically during 'validate' phase
# Configuration: ../style/checkstyle.xmlTest profiles (-P flag):
core-test(default): Core graph engine testsunit-test: Unit tests only (memory backend)api-test: REST API teststinkerpop-structure-test: TinkerPop structure compliancetinkerpop-process-test: TinkerPop process compliance
Backend profiles (combine with test profiles):
memory: In-memory backend (default for tests)rocksdb: RocksDB backendhbase: HBase backendmysql,postgresql,cassandra,scylladb,palo: Other backends
# Unit tests (from hugegraph-server/)
mvn test -pl hugegraph-test -am -P unit-test
# Core tests with RocksDB backend
mvn test -pl hugegraph-test -am -P core-test,rocksdb
# API tests with memory backend
mvn test -pl hugegraph-test -am -P api-test,memory
# Run specific test class
mvn test -pl hugegraph-test -am -P core-test,memory -Dtest=YourTestClassName
# TinkerPop compliance tests (for release validation)
mvn test -pl hugegraph-test -am -P tinkerpop-structure-test,memory
mvn test -pl hugegraph-test -am -P tinkerpop-process-test,memoryAll tests are in hugegraph-test/ which depends on all other modules. Tests are organized by:
- Unit tests:
src/test/java/.../unit/ - Core tests:
src/test/java/.../core/ - API tests:
src/test/java/.../api/
Multi-module Maven project with 13 submodules:
hugegraph-server/
├── hugegraph-core # Graph engine, TinkerPop impl, schema, backend interface
├── hugegraph-api # REST API, Gremlin/Cypher endpoints, authentication
├── hugegraph-rocksdb # RocksDB backend (default, embedded)
├── hugegraph-hstore # HStore backend (distributed, production)
├── hugegraph-mysql # MySQL backend (legacy)
├── hugegraph-postgresql # PostgreSQL backend (legacy)
├── hugegraph-cassandra # Cassandra backend (legacy)
├── hugegraph-scylladb # ScyllaDB backend (legacy)
├── hugegraph-hbase # HBase backend (legacy)
├── hugegraph-palo # Palo backend (legacy)
├── hugegraph-dist # Distribution packaging, scripts, configs
├── hugegraph-test # All test suites
└── hugegraph-example # Example code
org/apache/hugegraph/
├── HugeGraph.java # Main graph interface
├── StandardHugeGraph.java # Core implementation
├── HugeFactory.java # Factory for graph instances
├── backend/ # Backend abstraction and implementations
│ ├── store/BackendStore.java # Storage backend interface
│ ├── serializer/ # Data serialization
│ └── tx/ # Transaction management
├── schema/ # Schema management (VertexLabel, EdgeLabel, etc.)
├── structure/ # Graph elements (Vertex, Edge, Property)
├── traversal/ # Gremlin traversal optimization
├── task/ # Async task scheduling and execution
├── auth/ # Authentication and authorization
├── job/ # Job management (rebuild, compact, etc.)
└── meta/ # Metadata management
org/apache/hugegraph/
├── api/ # REST API endpoints
│ ├── graph/GraphAPI.java # Graph CRUD operations
│ ├── schema/ # Schema APIs
│ ├── gremlin/GremlinAPI.java # Gremlin query endpoint
│ ├── cypher/CypherAPI.java # Cypher query endpoint (via OpenCypher)
│ ├── auth/ # Authentication APIs
│ └── job/TaskAPI.java # Job/Task management APIs
├── server/RestServer.java # Jersey/Grizzly REST server
├── auth/ # Auth filters and handlers
└── metrics/ # Metrics collection
All storage backends implement the BackendStore interface from hugegraph-core. New backends can be added as separate modules without modifying core code. Backend selection is via backend property in conf/hugegraph.properties.
Full Apache TinkerPop 3 implementation with:
- Custom traversal strategies in
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/ - Structure and process API implementations
- Gremlin groovy script support via
gremlin-groovyintegration
- Gremlin: Native support via TinkerPop
- Cypher: OpenCypher implementation in
hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/- Translates Cypher to Gremlin using
opencypher-gremlinlibrary
- Translates Cypher to Gremlin using
When working with HStore backend or distributed features:
- Protocol Buffer definitions:
hugegraph-core/src/main/resources/proto/ - Generated code:
target/generated-sources/protobuf/java/ - Regenerate after .proto changes:
mvn clean compile
Authentication is optional and disabled by default:
- Enable:
bin/enable-auth.shor via configuration - Implementation:
hugegraph-api/src/main/java/org/apache/hugegraph/auth/ - Multi-level access control: Users, Groups, Projects, Targets, Permissions
- Core auth logic:
hugegraph-core/src/main/java/org/apache/hugegraph/auth/
After building, server distribution is in hugegraph-dist/target/. Scripts are in hugegraph-dist/src/assembly/static/bin/:
# Initialize backend storage (first time only)
bin/init-store.sh
# Start server (REST API on 8080, Gremlin on 8182)
bin/start-hugegraph.sh
# Stop server
bin/stop-hugegraph.sh
# Gremlin console (interactive)
bin/gremlin-console.sh
# Monitor server status
bin/monitor-hugegraph.sh
# Enable authentication
bin/enable-auth.shLocated in hugegraph-dist/src/assembly/static/conf/:
hugegraph.properties: Main server configuration (backend, storage paths, cache)rest-server.properties: REST API settings (host, port, thread pool, SSL)gremlin-server.yaml: Gremlin server configuration (WebSocket, serializers)log4j2.xml: Logging configuration
- Create API class in
hugegraph-api/src/main/java/org/apache/hugegraph/api/ - Extend
ApiBaseor relevant base class - Use JAX-RS annotations (
@Path,@GET,@POST, etc.) - Add Swagger/OpenAPI annotations for documentation
- Add tests in
hugegraph-test/src/test/java/.../api/
- Create new module:
hugegraph-{backend-name}/ - Add dependency on
hugegraph-core - Implement
BackendStoreinterface - Implement
BackendStoreProviderfor factory - Add backend module to parent
pom.xml<modules>section - Add tests combining with test profiles
- Schema definitions:
hugegraph-core/src/main/java/org/apache/hugegraph/schema/ - Graph structure:
hugegraph-core/src/main/java/org/apache/hugegraph/structure/ - Always consider backward compatibility for stored data
- Update serializers if changing storage format
Transaction management is in hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/:
GraphTransaction: Vertex/Edge operationsSchemaTransaction: Schema operationsIndexTransaction: Index operations- Follow the transaction lifecycle pattern in existing code
- Checkstyle configuration:
../style/checkstyle.xml - Enforced during Maven
validatephase - Import code style into IDE (IntelliJ IDEA recommended)
All Java files must have Apache License header. Verified via maven-checkstyle-plugin.
- Version managed via
${revision}property (currently 1.7.0) - Uses
flatten-maven-pluginfor CI-friendly versioning - Don't hardcode versions in module POMs
hugegraph-api → hugegraph-core → hugegraph-commons (external)
hugegraph-{backend} → hugegraph-core
hugegraph-test → all modules
- Protobuf Java classes: Generated, not manually edited
- Located in
target/generated-sources/ - Excluded from checkstyle/license checks
Backends are loaded via ServiceLoader pattern. The backend property in hugegraph.properties determines which implementation is used. All backend JARs must be on classpath.
- Detailed logging: Edit
hugegraph-dist/src/assembly/static/conf/log4j2.xml - View effective config:
bin/dump-conf.sh - Arthas diagnostics: Built-in (version 3.7.1)
- Backend state inspection:
bin/dump-store.sh - Raft cluster tools (for distributed):
bin/raft-tools.sh