Repository: jina-ai/serve
Pull request: feat(cli): added option on the new command to create a deployment project or a flow project
I added a feature to allow users to be able to create a deployment themed project from the `new` command on the cli. This would allow users to specify an optional `--type` flag which would allow them to create a project as either a `deployment` or a `flow`. If no `--type` is specified it defaults to a `flow`. If a wrong `--type` is specified it still defaults to a `flow` This will ensure backwards compatibility with current users of the project. Examples of correct commands are:
- `jina new hello-world`
- `jina new hello-world --type flow`
- `jina new hello-world --type deployment`
- `jina new hello-world --type`

For the deployment project type, it still used the yaml format that was used in the `flow` type. It creates a `deployment.yml` file.

<!---Decomposing the complex issue into subtasks can help you build it step-by-step. Thanks for your pull request! :rocket: --->
<!---We know that dev life is hectic, but **please provide a (brief) description** of what your PR does, and how it does it. **Otherwise, your PR cannot be reviewed!** --->
<!---This policy was agreed upon in a past company retro, and makes everyone's life a little easier. Thanks for your collaboration!--->

**Goals:**
<!---https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword--->

- resolves #5755
- Allows more versatility for project creation
- Provides more information that can be used on the documentation
- Retains backwards compatibility

**Future work. **
- Provide information about this feature on the documentation
- Add option to create `flow` or `deployment` in either pythonic or YAMLish syntax



Problem statement:
Add option on the Jina CLI to allow deployment centric projects by adding a `deployment` flag
**Describe the feature**
Add option for `jina new` to be either flow centric or deployment centric

**Your proposal**
Add a flag to the `jina new` command to allow optional creation of deployment centric

Hints from issue discussion:
Hello @asuzukosi,

Thanks for opening this ticket. Any specific UX that you would like this option to have?
Yes, a flag could be added to the `jina new` command `deployment` which would specify that a deployment project is being created and `flow` which would specify that a flow project is being created. It would default to a flow if none are specified to maintain backward compatibility. I would like to work on this if it can be approved.
Sure, you can work on it
Okay, thank you @JoanFM

Commit message: docs(create-app): correct capitalization on flow and deployment

Patch to review:
diff --git a/docs/get-started/create-app.md b/docs/get-started/create-app.md
index 54765ec5f32cc..510bb6bde8372 100644
--- a/docs/get-started/create-app.md
+++ b/docs/get-started/create-app.md
@@ -1,9 +1,12 @@
 # {fas}`folder-plus` Create First Project
 
-Let's build a toy application with Jina. To start, use Jina CLI to make a new project:
+Let's build a toy application with Jina. To start, use Jina CLI to make a new Deployment or a Flow: 
 
+````{tab} Deployment
+
+To create a Deployment project with Jina CLI
 ```bash
-jina new hello-jina
+jina new hello-jina --type=deployment
 ```
 
 This creates a new project folder called `hello-jina` with the following file structure:
@@ -11,12 +14,151 @@ This creates a new project folder called `hello-jina` with the following file st
 ```text
 hello-jina/
     |- client.py
-    |- flow.yml
+    |- deployment.yml
     |- executor1/
             |- config.yml
             |- executor.py
 ```
+- `deployment.yml` is the configuration file for the {class}`~jina.Deployment`.
+- `executor1/` is where you write your {class}`~jina.Executor` code.
+- `config.yml` is the configuration file for the {class}`~jina.Executor`. It stores metadata for your Executor, as well as dependencies.
+- `client.py` is the entrypoint of your Jina project. You can run it via `python app.py`.
+
+There are some other files like `README.md` and `requirements.txt` to provide extra metadata about that {class}`~jina.Executor`. More information {ref}`can be found here<create-executor>`.
+
+Now run it and observe the output of the server and client:
+
+````{tab} Run server
+
+```shell
+jina deployment --uses deployment.yml
+```
+
+```shell
+
+──── 🎉 Deployment is ready to serve! ────
+╭────────────── 🔗 Endpoint ───────────────╮
+│  ⛓     Protocol                    GRPC  │
+│  🏠       Local           0.0.0.0:54321  │
+│  🔒     Private    192.168.200.56:54321  │
+│  🌍      Public    81.223.121.124:54321  │
+╰──────────────────────────────────────────╯
+```
+````
+
+````{tab} Run client
+```bash
+python client.py
+```
+
+```shell
+['hello, world!', 'goodbye, world!']
+```
+````
+
+## Add logic
+
+You can use any Python library in {class}`~jina.Executor`. For example, add `pytorch` to `executor1/requirements.txt` and crunch some numbers. 
+
+In `executor.py`, add another endpoint `/get-tensor` as follows:
+
+```{code-block} python
+---
+emphasize-lines: 13-16
+---
+import numpy as np
+import torch
+
+from jina import Executor, requests, DocumentArray
+
+
+class MyExecutor(Executor):
+    @requests
+    def foo(self, docs: DocumentArray, **kwargs):
+        docs[0].text = 'hello, world!'
+        docs[1].text = 'goodbye, world!'
+
+    @requests(on='/crunch-numbers')
+    def bar(self, docs: DocumentArray, **kwargs):
+        for doc in docs:
+            doc.tensor = torch.tensor(np.random.random([10, 2]))
+```
+
+Kill the last server with `Ctrl-C` and restart the server with `jina flow --uses deployment.yml`.
+
+## Call `/crunch-number` endpoint
+
+Modify `client.py` to call the `/crunch-numbers` endpoint:
+
+```python
+from jina import Client, DocumentArray
+
+if __name__ == '__main__':
+    c = Client(host='grpcs://1655d050ad.wolf.jina.ai')
+    da = c.post('/crunch-numbers', DocumentArray.empty(2))
+    print(da.tensors)
+```
+
+After you save that, you can run your new client:
+
+```bash
+python client.py
+```
+
+```text
+tensor([[[0.9594, 0.9373],
+         [0.4729, 0.2012],
+         [0.7907, 0.3546],
+         [0.6961, 0.7463],
+         [0.3487, 0.7837],
+         [0.7825, 0.0556],
+         [0.3296, 0.2153],
+         [0.2207, 0.0220],
+         [0.9547, 0.9519],
+         [0.6703, 0.4601]],
+
+        [[0.9684, 0.6781],
+         [0.7906, 0.8454],
+         [0.2136, 0.9147],
+         [0.3999, 0.7443],
+         [0.2564, 0.0629],
+         [0.4713, 0.1018],
+         [0.3626, 0.0963],
+         [0.7562, 0.2183],
+         [0.9239, 0.3294],
+         [0.2457, 0.9189]]], dtype=torch.float64)
+```
+
+## Deploy to JCloud
+
+JCloud offers free CPU and GPU instances to host Jina project.
+
+```admonition
+:class: important
+At present, JCloud is only available for Flows. We are currently working on supporting Deployments.
+```
+
+You've just finished your first toy Jina project, congratulations! You can now start your own project.
+
+````
+
+````{tab} Flow
+
+To create a Flow project with Jina CLI:
+```bash
+jina new hello-jina --type=flow
+```
+
+This creates a new project folder called `hello-jina` with the following file structure:
 
+```text
+hello-jina/
+    |- client.py
+    |- flow.yml
+    |- executor1/
+            |- config.yml
+            |- executor.py
+```
 - `flow.yml` is the configuration file for the {class}`~jina.Flow`.
 - `executor1/` is where you write your {class}`~jina.Executor` code.
 - `config.yml` is the configuration file for the {class}`~jina.Executor`. It stores metadata for your Executor, as well as dependencies.
@@ -24,11 +166,10 @@ hello-jina/
 
 There are some other files like `README.md` and `requirements.txt` to provide extra metadata about that {class}`~jina.Executor`. More information {ref}`can be found here<create-executor>`.
 
-
 Now run it and observe the output of the server and client:
 
-
 ````{tab} Run server
+
 ```shell
 jina flow --uses flow.yml
 ```
@@ -55,7 +196,6 @@ python client.py
 ```
 ````
 
-
 ## Add logic
 
 You can use any Python library in {class}`~jina.Executor`. For example, add `pytorch` to `executor1/requirements.txt` and crunch some numbers. 
@@ -131,7 +271,7 @@ tensor([[[0.9594, 0.9373],
 
 ## Deploy to JCloud
 
-JCloud offers free CPU and GPU instances to host Jina project. Let's deploy your first project to JCloud:
+JCloud offers free CPU and GPU instances to host Jina project. Let's deploy your first project to JCloud (Note that JCloud is only available for Flow projects):
 
 ```bash
 jina auth login
@@ -217,3 +357,5 @@ Successfully removed Flow 1655d050ad.
 ```
 
 You've just finished your first toy Jina project, congratulations! You can now start your own project.
+
+````
diff --git a/jina/parsers/create.py b/jina/parsers/create.py
index d85567096d98a..95054c208181f 100644
--- a/jina/parsers/create.py
+++ b/jina/parsers/create.py
@@ -15,4 +15,8 @@ def set_new_project_parser(parser=None):
     parser.add_argument(
         'name', type=str, help='The name of the project', default='hello-jina'
     )
+    
+    parser.add_argument(
+        '--type', type=str, help='The type of project to be created (either flow or deployment)', default='flow'
+    )
     return parser
diff --git a/jina/resources/project-template/client.py b/jina/resources/project-template/deployment/client.py
similarity index 100%
rename from jina/resources/project-template/client.py
rename to jina/resources/project-template/deployment/client.py
diff --git a/jina/resources/project-template/deployment/deployment.yml b/jina/resources/project-template/deployment/deployment.yml
new file mode 100644
index 0000000000000..b199b3fb5fe0a
--- /dev/null
+++ b/jina/resources/project-template/deployment/deployment.yml
@@ -0,0 +1,8 @@
+jtype: Deployment
+version: '1'
+gateway:
+  protocol: [grpc, http, websocket]
+  port: [54321, 54322, 54323]
+with:
+  - uses: executor1/config.yml
+    name: toyExecutor
\ No newline at end of file
diff --git a/jina/resources/project-template/executor1/config.yml b/jina/resources/project-template/deployment/executor1/config.yml
similarity index 100%
rename from jina/resources/project-template/executor1/config.yml
rename to jina/resources/project-template/deployment/executor1/config.yml
diff --git a/jina/resources/project-template/executor1/executor.py b/jina/resources/project-template/deployment/executor1/executor.py
similarity index 100%
rename from jina/resources/project-template/executor1/executor.py
rename to jina/resources/project-template/deployment/executor1/executor.py
diff --git a/jina/resources/project-template/executor1/requirements.txt b/jina/resources/project-template/deployment/executor1/requirements.txt
similarity index 100%
rename from jina/resources/project-template/executor1/requirements.txt
rename to jina/resources/project-template/deployment/executor1/requirements.txt
diff --git a/jina/resources/project-template/flow/client.py b/jina/resources/project-template/flow/client.py
new file mode 100644
index 0000000000000..27303e62c2ce3
--- /dev/null
+++ b/jina/resources/project-template/flow/client.py
@@ -0,0 +1,6 @@
+from jina import Client, DocumentArray
+
+if __name__ == '__main__':
+    c = Client(host='grpc://0.0.0.0:54321')
+    da = c.post('/', DocumentArray.empty(2))
+    print(da.texts)
diff --git a/jina/resources/project-template/flow/executor1/config.yml b/jina/resources/project-template/flow/executor1/config.yml
new file mode 100644
index 0000000000000..8656dc306160e
--- /dev/null
+++ b/jina/resources/project-template/flow/executor1/config.yml
@@ -0,0 +1,3 @@
+jtype: MyExecutor
+py_modules:
+  - executor.py
\ No newline at end of file
diff --git a/jina/resources/project-template/flow/executor1/executor.py b/jina/resources/project-template/flow/executor1/executor.py
new file mode 100644
index 0000000000000..f0ec18fb763a7
--- /dev/null
+++ b/jina/resources/project-template/flow/executor1/executor.py
@@ -0,0 +1,8 @@
+from jina import Executor, requests, DocumentArray
+
+
+class MyExecutor(Executor):
+    @requests
+    def foo(self, docs: DocumentArray, **kwargs):
+        docs[0].text = 'hello, world!'
+        docs[1].text = 'goodbye, world!'
diff --git a/jina/resources/project-template/flow/executor1/requirements.txt b/jina/resources/project-template/flow/executor1/requirements.txt
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/jina/resources/project-template/flow.yml b/jina/resources/project-template/flow/flow.yml
similarity index 100%
rename from jina/resources/project-template/flow.yml
rename to jina/resources/project-template/flow/flow.yml
diff --git a/jina_cli/api.py b/jina_cli/api.py
index b276c1726dc71..4324fefa7b125 100644
--- a/jina_cli/api.py
+++ b/jina_cli/api.py
@@ -197,10 +197,15 @@ def new(args: 'Namespace'):
     import shutil
 
     from jina.constants import __resources_path__
-
-    shutil.copytree(
-        os.path.join(__resources_path__, 'project-template'), os.path.abspath(args.name)
-    )
+    
+    if args.type == 'deployment':
+        shutil.copytree(
+            os.path.join(__resources_path__, 'project-template', 'deployment'), os.path.abspath(args.name)
+        )
+    else:
+        shutil.copytree(
+            os.path.join(__resources_path__, 'project-template', 'flow'), os.path.abspath(args.name)
+        )
 
 
 def help(args: 'Namespace'):
diff --git a/jina_cli/autocomplete.py b/jina_cli/autocomplete.py
index b35feafb72be3..596a6658a3378 100644
--- a/jina_cli/autocomplete.py
+++ b/jina_cli/autocomplete.py
@@ -109,7 +109,7 @@
         'export docker-compose': ['--help', '--network_name'],
         'export schema': ['--help', '--yaml-path', '--json-path', '--schema-path'],
         'export': ['--help', 'flowchart', 'kubernetes', 'docker-compose', 'schema'],
-        'new': ['--help'],
+        'new': ['name', '--type', '--help'],
         'gateway': [
             '--help',
             '--name',


Code review comments:
diff_hunk: @@ -1,34 +1,175 @@
 # {fas}`folder-plus` Create First Project
 
-Let's build a toy application with Jina. To start, use Jina CLI to make a new project:
+Let's build a toy application with Jina. To start, use Jina CLI to make a new Deployment or a Flow: 
 
+````{tab} Deployment
+
+To create a Deployment project with Jina CLI
path: docs/get-started/create-app.md
text: @user1:
Can remove lines like this. They're redundant

diff_hunk: @@ -1,34 +1,175 @@
 # {fas}`folder-plus` Create First Project
 
-Let's build a toy application with Jina. To start, use Jina CLI to make a new project:
+Let's build a toy application with Jina. To start, use Jina CLI to make a new Deployment or a Flow: 
 
+````{tab} Deployment
+
+To create a Deployment project with Jina CLI
 ```bash
-jina new hello-jina
+jina new hello-jina --type=deployment
 ```
 
 This creates a new project folder called `hello-jina` with the following file structure:
 
 ```text
 hello-jina/
     |- client.py
-    |- flow.yml
+    |- deployment.yml
     |- executor1/
             |- config.yml
             |- executor.py
 ```
+- `deployment.yml` is the configuration file for the {class}`~jina.Deployment`.
+- `executor1/` is where you write your {class}`~jina.Executor` code.
+- `config.yml` is the configuration file for the {class}`~jina.Executor`. It stores metadata for your Executor, as well as dependencies.
+- `client.py` is the entrypoint of your Jina project. You can run it via `python app.py`.
+
+There are some other files like `README.md` and `requirements.txt` to provide extra metadata about that {class}`~jina.Executor`. More information {ref}`can be found here<create-executor>`.
+
+Now run it and observe the output of the server and client:
+
+````{tab} Run server
+
+```shell
+jina deployment --uses deployment.yml
+```
+
+```shell
+
+──── 🎉 Deployment is ready to serve! ────
+╭────────────── 🔗 Endpoint ───────────────╮
+│  ⛓     Protocol                    GRPC  │
+│  🏠       Local           0.0.0.0:54321  │
+│  🔒     Private    192.168.200.56:54321  │
+│  🌍      Public    81.223.121.124:54321  │
+╰──────────────────────────────────────────╯
+```
+````
+
+````{tab} Run client
+```bash
+python client.py
+```
+
+```shell
+['hello, world!', 'goodbye, world!']
+```
+````
+
+## Add logic
+
+You can use any Python library in {class}`~jina.Executor`. For example, add `pytorch` to `executor1/requirements.txt` and crunch some numbers. 
+
+In `executor.py`, add another endpoint `/get-tensor` as follows:
+
+```{code-block} python
+---
+emphasize-lines: 13-16
+---
+import numpy as np
+import torch
+
+from jina import Executor, requests, DocumentArray
+
+
+class MyExecutor(Executor):
+    @requests
+    def foo(self, docs: DocumentArray, **kwargs):
+        docs[0].text = 'hello, world!'
+        docs[1].text = 'goodbye, world!'
+
+    @requests(on='/crunch-numbers')
+    def bar(self, docs: DocumentArray, **kwargs):
+        for doc in docs:
+            doc.tensor = torch.tensor(np.random.random([10, 2]))
+```
+
+Kill the last server with `Ctrl-C` and restart the server with `jina flow --uses deployment.yml`.
+
+## Call `/crunch-number` endpoint
+
+Modify `client.py` to call the `/crunch-numbers` endpoint:
+
+```python
+from jina import Client, DocumentArray
+
+if __name__ == '__main__':
+    c = Client(host='grpcs://1655d050ad.wolf.jina.ai')
+    da = c.post('/crunch-numbers', DocumentArray.empty(2))
+    print(da.tensors)
+```
+
+After you save that, you can run your new client:
+
+```bash
+python client.py
+```
+
+```text
+tensor([[[0.9594, 0.9373],
+         [0.4729, 0.2012],
+         [0.7907, 0.3546],
+         [0.6961, 0.7463],
+         [0.3487, 0.7837],
+         [0.7825, 0.0556],
+         [0.3296, 0.2153],
+         [0.2207, 0.0220],
+         [0.9547, 0.9519],
+         [0.6703, 0.4601]],
+
+        [[0.9684, 0.6781],
+         [0.7906, 0.8454],
+         [0.2136, 0.9147],
+         [0.3999, 0.7443],
+         [0.2564, 0.0629],
+         [0.4713, 0.1018],
+         [0.3626, 0.0963],
+         [0.7562, 0.2183],
+         [0.9239, 0.3294],
+         [0.2457, 0.9189]]], dtype=torch.float64)
+```
+
+## Deploy to JCloud
+
+JCloud offers free CPU and GPU instances to host Jina project.
+
+```admonition
+:class: important
+At present, JCloud is only available for Flows. We are currently working on supporting Deployments.
+```
+
+You've just finished your first toy Jina project, congratulations! You can now start your own project.
+
+````
+
+````{tab} Flow
+
+To create a Flow project with Jina CLI:
path: docs/get-started/create-app.md
text: @user1:
Kill this line too

```suggestion
```

@author:
Alright, I'll get to It