|
1 | 1 | cdd-python-all |
2 | | -============== |
| 2 | +============ |
| 3 | + |
3 | 4 | [](https://opensource.org/licenses/Apache-2.0) |
4 | 5 | [](https://offscale.io/wasm_web_demo) |
5 | 6 | [](https://github.com/offscale/cdd-python-all/actions) |
6 | | -[](#) |
| 7 | +[](#) |
7 | 8 | [](#) |
8 | 9 |
|
9 | | ----- |
| 10 | +**Compiler Driven Development (CDD)** is a development approach designed to eradicate the disconnect between: API specifications; server implementations; client SDKs; and command-line tooling. |
10 | 11 |
|
11 | | -OpenAPI ↔ Python. This is one compiler in a suite, all focussed on the same task: Compiler Driven Development (CDD). |
| 12 | +Unlike traditional code generators—that treat outputs as disposable or read-only—CDD provides a **complete, standalone compiler** for each supported language. These compilers are fully CST-aware (Concreate Syntax Tree is a whitespace+comment aware Abstract Syntax Tree), allowing true bidirectional synchronization between existing hand-edited source code and OpenAPI specifications. |
12 | 13 |
|
13 | | -Each compiler is written in its target language, is whitespace and comment sensitive, and has both an SDK and CLI. |
| 14 | +--- |
14 | 15 |
|
15 | | -The core philosophy of Compiler Driven Development (CDD) is synchronization without compromise. Where traditional generators silo your API boundaries into read-only files, this compiler natively merges changes into your codebase via a robust, [whitespace and comment aware] Abstract Syntax Tree (AST) driven parser & emitter. It bridges the gap between design and implementation, allowing you to seamlessly generate SDKs from a spec or extract a spec from existing code. By keeping your APIs, SDKs, and tests in continuous, automated alignment, it drastically improves both delivery speed and software reliability. |
| 16 | +## 🏗️ The Standalone Compiler Architecture |
16 | 17 |
|
17 | | -The CLI—at a minimum—has: |
| 18 | +Traditional tools use naïve templating—if you regenerate, your custom code is overwritten. |
18 | 19 |
|
19 | | -- `cdd-python-all --help` |
20 | | -- `cdd-python-all --version` |
21 | | -- `cdd-python-all from_openapi to_sdk_cli --mcp -i spec.json` |
22 | | -- `cdd-python-all from_openapi to_sdk -i spec.json` |
23 | | -- `cdd-python-all from_openapi to_server -i spec.json` |
24 | | -- `cdd-python-all to_openapi -f path/to/code` |
25 | | -- `cdd-python-all to_docs_json --no-imports --no-wrapping -i spec.json` |
26 | | -- `cdd-python-all serve_json_rpc --port 8080 --listen 0.0.0.0` |
| 20 | +The CDD ecosystem is fundamentally different. It utilizes language-specific, standalone compilers capable of full AST parsing, semantic diffing, and surgical patching. |
27 | 21 |
|
28 | | -## SDK Example |
| 22 | +**The Core Guarantee:** Every part of the generated codebase is fully editable. |
| 23 | +You are encouraged to open the generated routing files, model definitions, and CLI structures, and directly inject your business logic. |
29 | 24 |
|
30 | | -```py |
31 | | -from cdd import generate_sdk, Config |
| 25 | +- **When your specification changes**, the CDD compiler reads your code, builds an AST, diffs it against the new spec, and safely patches in new endpoints or fields without touching your custom logic. |
| 26 | +- **When your codebase changes**, the compiler reverse-engineers your structural updates back into a 100% accurate, authoritative OpenAPI specification. |
32 | 27 |
|
33 | | -if __name__ == '__main__': |
34 | | - config = Config(input_path='spec.json', output_dir='src/models') |
35 | | - generate_sdk(config) |
36 | | - print("SDK generation complete.") |
37 | | -``` |
| 28 | +--- |
38 | 29 |
|
39 | | -## Installation |
| 30 | +## 🔄 The Bidirectional Synchronization Loop |
40 | 31 |
|
41 | | -```bash |
42 | | -python3 -m pip install -e . |
43 | | -``` |
| 32 | +```mermaid |
| 33 | +flowchart TD |
| 34 | + OAS["📄 OpenAPI v3 Spec"] <--> CDD{"⚙️ CDD Compiler"} |
44 | 35 |
|
45 | | -## Development |
46 | | - |
47 | | -You can use standard tooling commands or the included cross-platform Makefiles to fetch dependencies, build, and test: |
48 | | - |
49 | | -```bash |
50 | | -python3 -m pip install -e . |
51 | | -python3 -m pytest |
52 | | -# or |
53 | | -make deps |
54 | | -make build |
55 | | -make test |
56 | | -# or on Windows |
57 | | -.\make.bat deps |
58 | | -.\make.bat build |
59 | | -.\make.bat test |
60 | | -``` |
| 36 | + CDD <--> Codebase |
61 | 37 |
|
62 | | -See [PUBLISH.md](PUBLISH.md) for packaging and releasing. |
| 38 | + subgraph Codebase ["💻 Application Codebase"] |
| 39 | + direction TB |
63 | 40 |
|
64 | | -## Features |
| 41 | + subgraph Outputs ["📦 Primary Outputs"] |
| 42 | + direction TB |
| 43 | + CLI["⌨️ CLI Tooling"] |
| 44 | + SDK["📦 Client SDK"] |
| 45 | + Server["🖥️ Server"] |
65 | 46 |
|
66 | | -The `cdd-python-all` compiler leverages a unified architecture to support various facets of API and code lifecycle management. For a deep dive into the compiler's design, see [ARCHITECTURE.md](ARCHITECTURE.md). |
| 47 | + %% Force vertical stacking inside the subgraph |
| 48 | + CLI ~~~ SDK ~~~ Server |
| 49 | + end |
67 | 50 |
|
68 | | -- **Compilation**: |
69 | | - - **OpenAPI → `Python`**: Generate idiomatic native models, network routes, client SDKs, and boilerplate directly from OpenAPI (`.json` / `.yaml`) specifications. |
70 | | - - **`Python` → OpenAPI**: Statically parse existing `Python` source code and emit compliant OpenAPI specifications. |
71 | | - - **Model Context Protocol (MCP)**: Generate and run MCP clients and servers, exposing your APIs seamlessly to AI models. |
72 | | -- **AST-Driven & Safe**: Employs static analysis instead of unsafe dynamic execution or reflection, allowing it to safely parse and emit code even for incomplete or un-compilable project states. |
73 | | -- **Seamless Sync**: Keep your docs, tests, database, clients, and routing in perfect harmony. Update your code, and generate the docs; or update the docs, and generate the code. |
| 51 | + subgraph Core ["🔗 Core Architecture"] |
| 52 | + direction TB |
| 53 | + Models["🔗 Data Models"] |
| 54 | + Routes["🔀 API Routes"] |
| 55 | + Tests["🧪 Tests"] |
74 | 56 |
|
75 | | -**Uncommon Features:** |
| 57 | + %% Force vertical stacking inside the subgraph |
| 58 | + Models ~~~ Routes ~~~ Tests |
| 59 | + end |
76 | 60 |
|
77 | | -`cdd-python-all` supports standard CDD features. |
| 61 | + Mocks["🎭 API Mocks / Fakes"] |
78 | 62 |
|
79 | | -## CLI Options |
| 63 | + %% Simple dependency flow down the page |
| 64 | + Outputs --> Core |
| 65 | + Tests --> Mocks |
| 66 | + end |
80 | 67 |
|
81 | | -```text |
82 | | -Usage: cdd-python-all [OPTIONS] <COMMAND> |
| 68 | + style OAS fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px |
| 69 | + style CDD fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px |
| 70 | + style Codebase fill:#fafafa,stroke:#9e9e9e,stroke-width:2px,stroke-dasharray: 5 5 |
| 71 | + style Outputs fill:#e8f5e9,stroke:#43a047,stroke-width:2px |
| 72 | + style Core fill:#fff3e0,stroke:#f57c00,stroke-width:2px |
83 | 73 | ``` |
84 | 74 |
|
| 75 | +The CDD lifecycle supports continuous evolution from any starting point: |
| 76 | +1. **Generate**: Scaffold servers, SDKs, or CLIs from a central specification. |
| 77 | +2. **Edit**: Developers write real, unconstrained code directly in the generated files. |
| 78 | +3. **Extract**: Reverse-compile the edited code to produce an updated OpenAPI spec. |
| 79 | +4. **Sync**: Apply new specification changes seamlessly into the existing, hand-edited codebase. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 🌐 The Global Language Ecosystem |
| 84 | + |
| 85 | +Every supported language operates on the same core CDD philosophies but is powered by a dedicated, native compiler tailored to that language's specific AST, idioms, and package management. |
| 86 | + |
| 87 | +All implementations share a standardized CLI interface (`cdd [subcommand]`), acting as a universal toolchain. |
| 88 | + |
| 89 | +| Repository | Language | Client; Client CLI; Server | Extra features | Standards | CI Status | |
| 90 | +|---|---|---|---|---|---| |
| 91 | +| [`cdd-c`](https://github.com/SamuelMarks/cdd-c) | C (C89) | Client; Client CLI; Server | FFI | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-c/actions/workflows/ci.yml) | |
| 92 | +| [`cdd-cpp`](https://github.com/SamuelMarks/cdd-cpp) | C++ | Client; Client CLI; Server | Upgrades Swagger & Google Discovery to OpenAPI 3.2.0 | Google Discovery; Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-cpp/actions/workflows/ci.yml) | |
| 93 | +| [`cdd-csharp`](https://github.com/SamuelMarks/cdd-csharp) | C# | Client; Client CLI; Server | CLR | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-csharp/actions/workflows/ci.yml) | |
| 94 | +| [`cdd-go`](https://github.com/SamuelMarks/cdd-go) | Go | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-go/actions/workflows/ci.yml) | |
| 95 | +| [`cdd-java`](https://github.com/SamuelMarks/cdd-java) | Java | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-java/actions/workflows/ci.yml) | |
| 96 | +| [`cdd-kotlin`](https://github.com/offscale/cdd-kotlin) | Kotlin (ktor for Multiplatform) | Client; Client CLI; Server | Auto-Admin UI | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/offscale/cdd-kotlin/actions/workflows/ci.yml) | |
| 97 | +| [`cdd-php`](https://github.com/SamuelMarks/cdd-php) | PHP | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-php/actions/workflows/ci.yml) | |
| 98 | +| [`cdd-python`](https://github.com/offscale/cdd-python) | Python | N/A (server building blocks) | CLI ↔ SQL ↔ Pydantic ↔ docs ↔ JSON-schema | N/A | [](https://github.com/offscale/cdd-python/actions) | |
| 99 | +| [`cdd-python-all`](https://github.com/offscale/cdd-python-all) | Python | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/offscale/cdd-python-all/actions/workflows/ci.yml) | |
| 100 | +| [`cdd-ruby`](https://github.com/SamuelMarks/cdd-ruby) | Ruby | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-ruby/actions/workflows/ci.yml) | |
| 101 | +| [`cdd-rust`](https://github.com/SamuelMarks/cdd-rust) | Rust | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/offscale/cdd-rust/actions/workflows/ci.yml) | |
| 102 | +| [`cdd-sh`](https://github.com/SamuelMarks/cdd-sh) | Shell (/bin/sh) | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-sh/actions/workflows/ci.yml) | |
| 103 | +| [`cdd-swift`](https://github.com/SamuelMarks/cdd-swift) | Swift | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/SamuelMarks/cdd-swift/actions/workflows/ci.yml) | |
| 104 | +| [`cdd-ts`](https://github.com/offscale/cdd-ts) | TypeScript | Client; Client CLI; Server | Auto-Admin UI; Angular; React; Vue; fetch; Axios; Node.js | Swagger 2.0 & OpenAPI 3.2.0 | [](https://github.com/offscale/cdd-ts/actions/workflows/ci.yml) | |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## 🛠️ Universal CLI Toolchain |
| 109 | + |
| 110 | +A true ecosystem requires standardized tooling. Once a developer learns the CDD toolchain, they can synchronize architecture across the entire polyglot stack. |
| 111 | + |
| 112 | +### Global Arguments |
| 113 | + |
| 114 | +- `--help`: Print help information. |
| 115 | +- `--version`: Print version information. |
| 116 | +- `--input, -i` (or `-f`): Target file, directory, or OpenAPI spec. |
| 117 | +- `--output, -o`: Destination path for generation or sync. |
| 118 | + |
| 119 | +### Core Subcommands |
| 120 | + |
| 121 | +#### `from_openapi to_sdk_cli` |
| 122 | +Generate a client SDK and a corresponding command-line interface (CLI) from an OpenAPI specification. |
| 123 | +- `--input, -i <spec>`: Path to the OpenAPI specification file. |
| 124 | + |
| 125 | +#### `from_openapi to_sdk` |
| 126 | +Generate a client SDK from an OpenAPI specification. |
| 127 | +- `--input, -i <spec>`: Path to the OpenAPI specification file. |
| 128 | + |
| 129 | +#### `from_openapi to_server` |
| 130 | +Generate server boilerplate, models, and routing logic from an OpenAPI specification. |
| 131 | +- `--input, -i <spec>`: Path to the OpenAPI specification file. |
| 132 | + |
| 133 | +#### `to_openapi` |
| 134 | +Parse the existing codebase and extract an authoritative OpenAPI specification. |
| 135 | +- `--input, -i <path>` (or `-f <path>`): Path to the source code directory or file to parse. |
| 136 | + |
| 137 | +#### `to_docs_json` |
| 138 | +Convert an OpenAPI specification into a localized, documentation-optimized JSON format. |
| 139 | +- `--input, -i <spec>`: Path to the OpenAPI specification file. |
| 140 | +- `--no-imports`: Disable import statements in the generated documentation. |
| 141 | +- `--no-wrapping`: Disable line wrapping in the generated documentation. |
| 142 | + |
| 143 | +#### `serve_json_rpc` |
| 144 | +Launch a JSON-RPC server for editor and tool integrations. |
| 145 | +- `--port <port>` (or `-p`): Port to listen on (e.g., `8080`). |
| 146 | +- `--listen <address>` (or `-l`): Address to bind to (e.g., `0.0.0.0`). |
| 147 | + |
| 148 | +#### `mcp` |
| 149 | +Run the Model Context Protocol server via stdio. |
| 150 | + |
| 151 | +#### `sync` |
| 152 | +Sync a directory containing client.py, mock_server.py, test_client.py, cli_main.py |
| 153 | +- `--dir <dir>`: Path to directory containing Python files to sync. |
| 154 | +- `--truth {class,sqlalchemy,function,openapi}`: Designate a single source of truth for synchronization. |
| 155 | + |
| 156 | +### Detail Features Beyond Common Subset |
| 157 | + |
| 158 | +- **Model Context Protocol (MCP)**: Native support to generate an MCP server and adapter (`--mcp`), and run the MCP server over stdio. |
| 159 | +- **Directory Synchronization**: Uniquely features a `sync` command to harmonize `client.py`, `mock_server.py`, `test_client.py`, and `cli_main.py` with configurable sources of truth (`class`, `sqlalchemy`, `function`, `openapi`). |
| 160 | +- **Comprehensive Scaffolding**: Optionally generates GitHub Actions pipelines and installable Python package scaffolding automatically. |
| 161 | +- **Integration Testing & Mocks**: Emits full integration tests and mock servers during generation (`--tests`). |
| 162 | +- **Batch Processing**: Capable of reading from an entire directory of OpenAPI specifications (`--input-dir`) simultaneously. |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## 🚀 The End of "Spec Drift" |
| 167 | + |
| 168 | +With Compiler Driven Development, specifications and code are no longer loosely coupled artifacts. They are strict, isomorphic reflections of one another, maintained by dedicated standalone compilers. |
| 169 | + |
| 170 | +Choose your language ecosystem above and start treating your architecture as a seamlessly compiled, endlessly editable whole. |
| 171 | + |
85 | 172 | --- |
86 | 173 |
|
87 | 174 | ## License |
|
0 commit comments