p1d: enhance CLI Scaffolder — generated main.py example, protocol/db selection guides

swadhinbiswas committed 3 months ago
911d04d
1 parent 7003476
commit 911d04d
1 file changed
+74 -6
▼docs_site/src/content/docs/getting-started/cli-scaffolder.md
+74-6
5
5
6
6
JustAPI features an interactive CLI project generator (`justapi create`) to scaffold complete applications with your choice of database and API architecture.
7
7
8
+## Installation
9
+
10
+Ensure you have the CLI installed:
11
+
12
+```bash
13
+cargo install justapi-cli
14
+justapi --version
15
+```
16
+
8
17
## Interactive Mode
9
18
10
19
Run `justapi create` without arguments to launch the TTY interactive wizard:
14
23
```
15
24
16
25
The wizard will prompt you to select:
26
+
17
27
1. **Database Engine:** SQLite, PostgreSQL, MySQL, DuckDB, ClickHouse, MongoDB, or Redis.
18
28
2. **API Protocol:** REST (OpenAPI), GraphQL (GraphiQL), gRPC (Protobuf), or JSON-RPC 2.0.
19
29
20
30
## Command Line Flags
21
31
22
-You can bypass the interactive wizard using `--db` and `--api-type` flags:
32
+Bypass the interactive wizard for scripting or quick scaffolding:
23
33
24
34
```bash
25
35
# REST API with DuckDB analytical engine
41
51
my_app/
42
52
├── app/
43
53
│ ├── __init__.py
44
-│ └── main.py # Pre-configured JustAPI application
54
+│ └── main.py # Pre-configured JustAPI application
45
55
├── migrations/
46
-│ └── 0001_initial.sql # Database schema migrations
47
-├── docker-compose.otel.yml # OpenTelemetry & Jaeger observability stack
48
-├── .env.example
49
-└── README.md
56
+│ └── 0001_initial.sql # Database schema migration
57
+├── docker-compose.otel.yml # OpenTelemetry, Jaeger, Prometheus, Grafana
58
+├── .env.example # Environment variable template
59
+└── README.md # Project documentation
50
60
```
61
+
62
+### `main.py` (Generated Example)
63
+
64
+When you select REST + PostgreSQL, the generated `main.py` looks like:
65
+
66
+```python
67
+from justapi import JustAPIApp
68
+
69
+app = JustAPIApp(title="my_app", version="0.1.0")
70
+
71
+app.set_database("postgres://user:pass@localhost:5432/my_app")
72
+
73
+
74
+@app.get("/")
75
+def root(request):
76
+ return {"service": "my_app", "status": "running"}
77
+
78
+
79
+@app.get("/health")
80
+def health(request):
81
+ return {"status": "ok"}
82
+```
83
+
84
+## Protocol Selection Guide
85
+
86
+| Protocol | Best For | Docs URL |
87
+|---|---|---|
88
+| **REST** | General-purpose APIs, CRUD, microservices | `/docs` (Swagger) |
89
+| **GraphQL** | Complex data queries, real-time subscriptions | `/graphql` (GraphiQL) |
90
+| **gRPC** | High-performance internal services, streaming RPC | `protobuf` binary protocol |
91
+| **JSON-RPC 2.0** | Lightweight RPC, wallet/web3 APIs | `/jsonrpc` |
92
+
93
+## Database Selection Guide
94
+
95
+| Database | Best For | Driver |
96
+|---|---|---|
97
+| **PostgreSQL** | Production OLTP, complex queries | Rust `sqlx-postgres` |
98
+| **MySQL** | Scalable relational workloads | Rust `sqlx-mysql` |
99
+| **SQLite** | Development, embedded, single-server | Rust `sqlx-sqlite` |
100
+| **DuckDB** | Analytical queries, Parquet, CSV | Python `duckdb` |
101
+| **ClickHouse** | High-volume column-store analytics | Python `clickhouse-driver` |
102
+| **MongoDB** | Document storage, flexible schemas | Python `pymongo` |
103
+| **Redis** | Caching, rate-limiting, pub/sub | Python `redis` |
104
+
105
+## Development Server
106
+
107
+After scaffolding, start the dev server with hot reload:
108
+
109
+```bash
110
+cd my_app
111
+justapi serve --reload
112
+```
113
+
114
+## Next Steps
115
+
116
+- [First Steps](/getting-started/first-steps/) — Build your first API endpoint
117
+- [Database Integration](/tutorials/database-integration/) — Connect and query databases
118
+- [Multi-Protocol APIs](/advanced/multi-protocol-apis/) — REST, GraphQL, gRPC, JSON-RPC
51
119