# dropbox/dropbox-sdk-rust architecture

> Architecture diagram of the GitHub repository dropbox/dropbox-sdk-rust, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dropbox/dropbox-sdk-rust
- Repository: https://github.com/dropbox/dropbox-sdk-rust

## Overview

##### Project Type and Purpose
- This is a Rust library (“crate”) that provides Dropbox API v2 bindings, with code generated from the official spec via the Stone framework.
- It supports both sync and async routes, pluggable HTTP clients, and ships with default clients and OAuth2 helpers.

##### File‐Structure Analysis
- Top‐level directories:
- src/                ← core SDK modules + generated code
- generator/          ← Python scripts and templates to drive code generation
- examples/           ← sample programs exercising the SDK
- tests/              ← integration and generated serialization tests
- dropbox-api-spec/   ← API spec submodule (input to generator)
- stone/              ← Stone code‐generation engine submodule
- Key modules in src/:
- client_trait.rs & async_client_trait.rs  ← HTTP‐client interfaces
- default_client*.rs                        ← built-in clients (ureq/rustls, reqwest)
- oauth2.rs                                  ← helper code for OAuth2 flows
- error.rs                                  ← error types & handling
- generated/                                 ← auto‐generated routes (sync/async) & types
- Build & deployment files: Cargo.toml, feature flags for sync/async/default_client, generate.py, update_spec.py.

##### README Insights
- Describes two main workflows:
1. Code Generation (generate.py + stone + dropbox-api-spec → src/generated + tests)
2. Runtime Usage (user’s code → instantiate HttpClient → call SDK routes → HTTP calls to Dropbox)
- Explains feature flags, authentication types, default clients, testing approach.

##### Diagramming the Architecture
a. Main Components
- Code‐Generation Pipeline
– dropbox-api-spec (spec JSON)
– stone engine (templates + python)
– generate.py & generator/*.py → src/generated & tests
- Core SDK Runtime
– client_trait (HttpClient, marker traits)
– async_client_trait
– error.rs
– oauth2.rs
- Default HTTP Clients
– sync: ureq + rustls (default_client.rs)
– async: reqwest (default_async_client.rs)
- Generated Routes & Types
– sync_routes & async_routes modules
– types module (structs, enums)
- User Code
– examples/ and any consuming application
- External Services
– Dropbox API endpoints (HTTPS)
b. Relationships & Data Flow
1. Developer runs generate.py → stone + spec → generated Rust code & tests
2. Cargo build/test pulls in src/** modules + generated code
3. At runtime, user code selects a client (implements HttpClient or uses default)
4. User code calls dropbox_sdk::<sync|async>_routes::<namespace>::function(...)
5. Route implementation serializes params → client.send(request) → HTTP over TLS → Dropbox API → JSON response → deserialized into generated types → returned to user
c. Architectural Patterns & Principles
- Code‐generation separates spec → source, keeping generated code in src/generated
- Trait abstraction (HttpClient) to decouple HTTP layer
- Feature flags for modular inclusion of sync/async and namespace subsets
- Sync façade built on top of async traits for code reuse
d. Key Technologies
- Rust & Cargo (features, modules)
- Python + Stone framework for generation
- ureq + rustls, reqwest for HTTP
- serde‐style manual serialization

## Diagram (Mermaid)

```mermaid
graph TD
    %% Build-Time Code Generation Pipeline
    subgraph "Build-Time Pipeline"
        direction TB
        dropbox_api_spec["dropbox-api-spec/*"]:::codegen
        stone["stone/*"]:::codegen
        gen_py["generate.py"]:::codegen
        update_spec_py["update_spec.py"]:::codegen
        update_manifest_py["update_manifest.py"]:::codegen
        subgraph "Generator Scripts & Templates"
            direction TB
            gen_rust_py["generator/rust.py"]:::codegen
            gen_rust_stone_py["generator/rust.stoneg.py"]:::codegen
            gen_test_stone_py["generator/test.stoneg.py"]:::codegen
        end
    end

    %% Generated Code Output
    subgraph "Generated Code" 
        direction TB
        sync_routes["src/generated/sync_routes/*"]:::generated
        async_routes["src/generated/async_routes/*"]:::generated
        types["src/generated/types/*"]:::generated
    end

    %% Tests
    subgraph "Integration & Serialization Tests"
        direction TB
        tests_dir["tests/*"]:::generated
    end

    %% Core SDK Runtime
    subgraph "Core SDK Runtime"
        direction TB
        client_trait["src/client_trait.rs"]:::core
        async_client_trait["src/async_client_trait.rs"]:::core
        client_helpers["src/client_helpers.rs & src/client_trait_common.rs"]:::core
        error_mod["src/error.rs"]:::core
        oauth2["src/oauth2.rs"]:::core
    end

    %% Default HTTP Clients
    subgraph "Default HTTP Clients"
        direction TB
        default_sync["src/default_client.rs & src/default_client_common.rs"]:::core
        default_async["src/default_async_client.rs"]:::core
    end

    %% User Application
    subgraph "User Code Examples"
        direction TB
        demo_sync["examples/demo.rs"]:::user
        demo_async["examples/demo-async.rs"]:::user
        demo_large["examples/large-file-upload.rs"]:::user
    end

    %% External Service
    dropbox_api["Dropbox API (HTTPS)"]:::external

    %% Build-Time Flow
    dropbox_api_spec -->|spec JSON| stone
    stone -->|uses templates| gen_py
    gen_py -->|generates code| sync_routes
    gen_py -->|generates code| async_routes
    gen_py -->|generates types| types
    gen_py -->|generates tests| tests_dir
    update_spec_py -->|updates spec| dropbox_api_spec
    update_manifest_py -->|updates generator manifest| gen_py
    gen_py --> gen_rust_py
    gen_py --> gen_rust_stone_py
    gen_py --> gen_test_stone_py

    %% Runtime Flow
    demo_sync -->|calls routes| sync_routes
    demo_async -->|calls routes| async_routes
    demo_large -->|calls routes| sync_routes
    sync_routes -->|serializes| client_trait
    async_routes -->|serializes| async_client_trait
    client_trait -->|uses| default_sync
    async_client_trait -->|uses| default_async
    client_helpers --> client_trait
    client_helpers --> async_client_trait
    error_mod --> sync_routes
    error_mod --> async_routes
    oauth2 --> demo_sync
    oauth2 --> demo_async
    default_sync -->|JSON over HTTPS| dropbox_api
    default_async -->|JSON over HTTPS| dropbox_api

    %% Click Events
    click dropbox_api_spec "https://github.com/dropbox/dropbox-sdk-rust/tree/master/dropbox-api-spec/"
    click stone "https://github.com/dropbox/dropbox-sdk-rust/tree/master/stone/"
    click gen_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/generate.py"
    click update_spec_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/update_spec.py"
    click update_manifest_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/update_manifest.py"
    click gen_rust_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/generator/rust.py"
    click gen_rust_stone_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/generator/rust.stoneg.py"
    click gen_test_stone_py "https://github.com/dropbox/dropbox-sdk-rust/blob/master/generator/test.stoneg.py"
    click client_trait "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/client_trait.rs"
    click async_client_trait "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/async_client_trait.rs"
    click client_helpers "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/client_helpers.rs"
    click client_helpers "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/client_trait_common.rs"
    click error_mod "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/error.rs"
    click oauth2 "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/oauth2.rs"
    click default_sync "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/default_client.rs"
    click default_sync "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/default_client_common.rs"
    click default_async "https://github.com/dropbox/dropbox-sdk-rust/blob/master/src/default_async_client.rs"
    click sync_routes "https://github.com/dropbox/dropbox-sdk-rust/tree/master/src/generated/sync_routes/"
    click async_routes "https://github.com/dropbox/dropbox-sdk-rust/tree/master/src/generated/async_routes/"
    click types "https://github.com/dropbox/dropbox-sdk-rust/tree/master/src/generated/types/"
    click demo_sync "https://github.com/dropbox/dropbox-sdk-rust/blob/master/examples/demo.rs"
    click demo_async "https://github.com/dropbox/dropbox-sdk-rust/blob/master/examples/demo-async.rs"
    click demo_large "https://github.com/dropbox/dropbox-sdk-rust/blob/master/examples/large-file-upload.rs"
    click tests_dir "https://github.com/dropbox/dropbox-sdk-rust/tree/master/tests/"

    %% Styles
    classDef codegen fill:#FFA500,stroke:#333,stroke-width:1px
    classDef generated fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef user fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
```
