This document provides architectural guidance and development standards for AI agents working on the PhotonRPC project. Adherence to these principles is mandatory for all interactions.
PhotonRPC is a high-performance RPC runtime implemented in C++20, designed as a communication substrate for distributed control planes (e.g., metadata services, coordinators, and schedulers). It features a custom application-layer protocol, a non-blocking network library based on the Epoll + Reactor pattern, and deep integration with Google Protobuf for serialization.
- Language: C++20 (strictly enforced)
- Build System: CMake (>= 3.15)
- Networking: Epoll-based single-threaded Reactor (Roadmap: Multi-Reactor and Coroutines)
- Serialization: Google Protobuf (v3)
- Logging: Asynchronous logging via
spdlog(MIT License) - Configuration: XML parsing via
tinyxml2(zlib License) - Testing: Google Test (GTest) for units, Python scripts for integration tests
- Formatting: Clang-Format (refer to
.clang-formatin root)
include/photonrpc/&src/: Core logic and public headers.common/: Foundation components (XMLconfig,loggerwrapper).net/: High-performance network library (Reactor, Poller, Channel, Acceptor, TcpConnection, TcpServer, Buffer).rpc/: RPC framework (RpcServer, RpcClient, RpcChannel). Uses Protobuf reflection for service routing.
protobuf/: Protocol definitions (rpc_message.proto).conf/: Configuration files (e.g.,photonrpc.xml).test/: Unit tests (test_buffer.cc,test_codec.cc), performance benchmarks (benchmark.cc), and integration tests (integration_test/).third_party/: Source code for external dependencies (googletest,spdlog,tinyxml2).
- Naming: Generally follows Google C++ Style Guide with specific project overrides:
- Classes:
CamelCase(e.g.,RpcServer). - Methods:
CamelCasestarting with uppercase (e.g.,StartServer,HandleRequest). - Member Variables:
snake_casewith a trailing underscore (e.g.,tcp_server_,service_map_).
- Classes:
- Memory Management: Use smart pointers (
std::unique_ptr,std::shared_ptr) to manage resources and avoid memory leaks. - Modern C++: Leverage C++20 features to ensure idiomatic and efficient code.
- Control Plane Focus: Prioritize low latency, predictability, and explainability over complex or "black-box" abstractions.
- Decoupling: The
net/layer must remain protocol-agnostic (focusing on byte-streams and event driving). Therpc/layer handles protocol framing, serialization, and service dispatch. - Error Handling: Utilize the logging system (
spdlog) for feedback acrossDEBUG,INFO, andERRORlevels.
- Output Paths: Executables must reside in
bin/, static libraries inlib/. - Verification: Every code change must be accompanied by a new or updated test case.
- Build Script: Always run
auto_build.bashin the project root to verify compilation and basic integration before finalizing changes.
AI Instruction: Before reading or modifying project files, verify the structure and standards defined above. A task is considered complete only when
auto_build.bashpasses and all relevant tests (GTest & Python) are successful.