Skip to content

CPP SDK #1471

Open
bhardwajparth51 wants to merge 21 commits intoappwrite:masterfrom
bhardwajparth51:feat/sdk-for-cpp
Open

CPP SDK #1471
bhardwajparth51 wants to merge 21 commits intoappwrite:masterfrom
bhardwajparth51:feat/sdk-for-cpp

Conversation

@bhardwajparth51
Copy link
Copy Markdown
Contributor

@bhardwajparth51 bhardwajparth51 commented Apr 23, 2026

What does this PR do?

Adds a C++ SDK generator targeting C++20. The generated SDK is monolithic and header-only—users can drop include/appwrite into their project and link against cpr and nlohmann/json without any precompilation or complex build step.

Key Features of the C++ SDK:

  • Monolithic Header-only: Simple integration with a single include/appwrite/services.hpp entry point. No separate compilation units or static/dynamic linking required for the SDK itself.
  • Concurrent Dispatch via ThreadPool: API calls are dispatched onto a dedicated ThreadPool. The queue is bounded at 1,024 tasks as intentional backpressure — typical SDK workloads never approach this limit.
  • Modern C++20 Async: The Task<T> type provides a coroutine-compatible interface (co_await), allowing async API calls to feel natural while maintaining readability.
  • Robust Transport Layer: Full support for chunked multi-part uploads, binary responses (callBytes), and automatic x-appwrite-id propagation for resumable-style large file handling.
  • Topological Model Sorting: Automatically resolves circular dependencies in model definitions at generation time, ensuring the monolithic header compiles without forward declaration conflicts.
  • Thread-Safety: The Client uses a copy-on-write config pattern via shared_ptr<const Config> with mutex protection, making it safe for concurrent use across multiple threads.

Test Plan

Verified with 443 passing assertions against the Appwrite Mock API via Cpp20Test.php. The suite covers:

  • Complete REST lifecycle (GET/POST/PUT/PATCH/DELETE).
  • Large file chunked uploads with x-appwrite-id propagation.
  • Binary response handling and error model parsing.
  • Correctness of all Query, Permission, and ID helper builders.

Related PRs and Issues

Contributing Guidelines

Yes

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 23, 2026

Greptile Summary

This PR adds a complete C++20 SDK generator targeting Appwrite, producing a monolithic header-only library with coroutine-based async dispatch, chunked file uploads, and Realtime WebSocket support. All P0/P1 issues from prior review rounds (dangling getHeaders() reference, subIdCounter data race, Subscription use-after-free, subscribe() deadlock, spurious 10 ms sleep, missing RetryPolicy retry coverage) have been addressed in this revision.

Confidence Score: 4/5

Safe to merge; remaining findings are P2 suggestions that do not block production use.

All previously flagged P0/P1 issues are resolved. Two new P2 findings remain: cancellation not honored during retry sleeps in upload_chunks, and Subscription::callback being a detached copy that silently ignores post-call mutations. Neither causes a crash or data loss.

templates/cpp/include/client.hpp.twig (retry cancellation gap), templates/cpp/include/services.hpp.twig (Subscription callback copy semantics)

Important Files Changed

Filename Overview
templates/cpp/include/client.hpp.twig Core Client class with ThreadPool, retry logic, chunked upload, and async dispatch — previously flagged issues resolved; two P2 concerns remain (cancellation not checked during retry sleeps, multipart rebuilt on every retry)
templates/cpp/include/services.hpp.twig Generated service classes and Realtime WebSocket support — previously flagged deadlock, subIdCounter race, and use-after-free resolved; Subscription::callback is copied into both returned struct and dispatch map, meaning post-call mutations silently have no effect
templates/cpp/include/base.hpp.twig Exception hierarchy, Result/Result, Task coroutine type, BinaryResponse, and SocketBackend interface — well-implemented with correct move-only semantics
templates/cpp/include/core.hpp.twig Helper classes (Query, Permission, Role, Id, InputFile, Operator) — well-structured; InputFile::fromPath throws AppwriteException, consistent with the SDK error model
src/SDK/Language/Cpp.php PHP generator — return types, dispatch blocks, input types, and default generation all consistent; TYPE_FILE non-required guard present; DFS topological sort correctly handles model ordering
tests/Cpp20Test.php Integration test suite with 443 assertions covering REST lifecycle, chunked uploads, binary responses, and helper builders

Reviews (9): Last reviewed commit: "fix(cpp): return getHeaders by value to ..." | Re-trigger Greptile

Comment thread templates/cpp/include/client.hpp.twig Outdated
Comment thread templates/cpp/include/client.hpp.twig
Comment thread templates/cpp/include/services.hpp.twig Outdated
Comment thread src/SDK/Language/Cpp.php Outdated
Comment thread templates/cpp/include/services.hpp.twig Outdated
Comment thread templates/cpp/include/services.hpp.twig
Comment thread templates/cpp/include/services.hpp.twig Outdated
Comment thread templates/cpp/include/client.hpp.twig
Comment thread src/SDK/Language/Cpp.php
Comment thread templates/cpp/include/core.hpp.twig
Comment thread templates/cpp/include/client.hpp.twig Outdated
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

@ChiragAgg5k could you run jobs/workflows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant