From 32f7b97f216b2be9149ccdf991d523f66be964f7 Mon Sep 17 00:00:00 2001 From: Itay Dar <118370953+ItayTheDar@users.noreply.github.com> Date: Wed, 13 May 2026 14:06:35 +0300 Subject: [PATCH 1/4] docs: design improved cli generation experience --- ...-05-13-cli-generation-experience-design.md | 390 ++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 docs/superpowers/specs/2026-05-13-cli-generation-experience-design.md diff --git a/docs/superpowers/specs/2026-05-13-cli-generation-experience-design.md b/docs/superpowers/specs/2026-05-13-cli-generation-experience-design.md new file mode 100644 index 0000000..f13b392 --- /dev/null +++ b/docs/superpowers/specs/2026-05-13-cli-generation-experience-design.md @@ -0,0 +1,390 @@ +# PyNest CLI Generation Experience Design + +## Purpose + +PyNest should provide a generation CLI that feels excellent for humans and is reliable for agents. Humans should be able to start with a guided prompt and understand exactly what happened. Agents should be able to express the whole desired operation in one command and receive deterministic, machine-readable output. + +This design improves the full generation surface: + +- Creating applications. +- Adding resources, modules, controllers, services, and gateways. +- Terminal output, progress, summaries, errors, and generated starter project presentation. +- Compatibility with existing `pynest generate ...` commands. + +## Current State + +The current CLI exposes: + +```bash +pynest generate application -n my_app +pynest generate resource -n users +pynest generate module -n auth +pynest generate controller -n users +pynest generate service -n users +pynest generate gateway -n chat +``` + +Observed gaps: + +- The application command is functional but not memorable. +- Help text is sparse and does not explain common paths. +- Generation output is mostly file-level `CREATE` lines with little context. +- There is no guided flow for humans. +- There is no JSON output for agents. +- There is no dry-run plan. +- Validation errors are not consistently actionable. +- Generated app metadata is stored at package level as `nest/settings.yaml`; it should live inside the generated project. +- Docs and examples are partially out of date with generated structure. + +## Recommended Approach + +Add a new primary CLI surface and keep the current one as a compatibility layer. + +New primary commands: + +```bash +pynest new [APP_NAME] +pynest add resource NAME +pynest add module NAME +pynest add controller NAME +pynest add service NAME +pynest add gateway NAME +pynest doctor +``` + +Compatibility commands continue to work: + +```bash +pynest generate application -n my_app +pynest generate resource -n users +``` + +The implementation should reuse the existing template classes where practical, but generation should route through a clearer application-generation service that can return a structured result instead of only printing during file writes. + +## Human Experience + +The human-first path is interactive: + +```bash +pynest new +``` + +If the user omits required information and the terminal is interactive, PyNest prompts for it: + +```text +PyNest 0.6.0 + +Create a new PyNest application + +Application name: my-app +Preset: + 1. HTTP API + 2. CLI application +Choose preset [1]: 1 +Database: + 1. None + 2. SQLite + 3. PostgreSQL + 4. MySQL + 5. MongoDB +Choose database [1]: 2 +Use async database access? [y/N]: y + +Creating application my-app +Preset HTTP API +Database sqlite +Async yes + +CREATE my-app/main.py +CREATE my-app/src/app_module.py +CREATE my-app/src/app_controller.py +CREATE my-app/src/app_service.py +CREATE my-app/src/config.py +CREATE my-app/README.md +CREATE my-app/requirements.txt +CREATE my-app/.pynest.yaml + +Application ready + +Next steps + cd my-app + pip install -r requirements.txt + python main.py +``` + +The prompt should be helpful but not noisy: + +- Ask only for missing information. +- Use defaults for the common path. +- Avoid prompting when `--yes` or `--json` is used. +- Do not prompt in non-interactive environments unless explicitly requested with `--prompt`. +- Show the final plan before writing if the operation is risky or overwrites are possible. + +The human command should also support explicit flags: + +```bash +pynest new my-app --preset api --database sqlite --async +``` + +## Agent Experience + +The agent-first path is a complete, explicit command: + +```bash +pynest new my-app --preset api --database sqlite --async --yes --json +``` + +Agents should not need a prompt. They should be able to specify the whole statement in one command. + +Rules for agent-friendly behavior: + +- `--json` implies non-interactive mode. +- `--yes` confirms default-safe choices and suppresses confirmation prompts. +- Missing required values in non-interactive mode should fail with a structured error. +- Output must be deterministic and parseable. +- File paths in JSON should be relative to the current working directory unless an absolute path was explicitly passed. +- Exit codes must distinguish success from validation errors and write failures. + +Example JSON success output: + +```json +{ + "status": "created", + "operation": "new", + "project": "my-app", + "preset": "api", + "database": "sqlite", + "async": true, + "files_created": [ + "my-app/main.py", + "my-app/src/app_module.py", + "my-app/src/app_controller.py", + "my-app/src/app_service.py", + "my-app/src/config.py", + "my-app/README.md", + "my-app/requirements.txt", + "my-app/.pynest.yaml" + ], + "files_updated": [], + "next_steps": [ + "cd my-app", + "pip install -r requirements.txt", + "python main.py" + ] +} +``` + +Example JSON validation error: + +```json +{ + "status": "error", + "error": { + "code": "invalid_database", + "message": "Unknown database 'postgres'. Use one of: postgresql, mysql, sqlite, mongodb.", + "field": "database" + } +} +``` + +## Command Contract + +### `pynest new` + +Creates a new PyNest app. + +Recommended options: + +- `APP_NAME`: optional in interactive mode, required in non-interactive mode. +- `--preset api|cli`: generated app type. Default: `api`. +- `--database none|sqlite|postgresql|mysql|mongodb`: database integration. Default: `none`. +- `--async`: async database access for relational databases. +- `--path PATH`: parent directory for the new app. Default: current directory. +- `--package-manager requirements|uv`: generated dependency files. Default: `requirements`. +- `--prompt`: force interactive prompts. +- `--yes`: accept defaults and proceed without confirmation. +- `--dry-run`: show the generation plan without writing files. +- `--json`: output structured JSON and suppress human formatting. +- `--quiet`: only print essential information. +- `--force`: allow overwriting where explicitly supported. + +### `pynest add` + +Adds code to an existing PyNest app. + +Recommended commands: + +```bash +pynest add resource users +pynest add module auth +pynest add controller users +pynest add service users +pynest add gateway chat +``` + +Recommended shared options: + +- `--path PATH`: target app or source directory. +- `--flat`: generate directly into the target path where applicable. +- `--dry-run` +- `--json` +- `--quiet` +- `--force` + +`pynest add` should discover `.pynest.yaml` by walking up from the current directory. If metadata is missing, it should fall back to sensible defaults and explain how to fix the project. + +### `pynest doctor` + +Checks whether the current directory is a valid PyNest project. + +It should report: + +- Whether `.pynest.yaml` exists. +- App preset. +- Database settings. +- Whether `src/app_module.py` exists. +- Whether generation can safely add modules. + +`doctor --json` should return the same information as structured data. + +## Visual Terminal Design + +Human output should be scannable and calm: + +- Header with PyNest version and operation. +- Aligned key/value plan summary. +- Colored file operations: `CREATE`, `UPDATE`, `SKIP`, `ERROR`. +- Clear final status. +- Exact next steps. +- No decorative banners or excessive symbols. + +Example: + +```text +PyNest 0.6.0 + +Adding resource users +Target src/users +Database sqlite + +CREATE src/users/__init__.py +CREATE src/users/users_module.py +CREATE src/users/users_controller.py +CREATE src/users/users_service.py +CREATE src/users/users_model.py +CREATE src/users/users_entity.py +UPDATE src/app_module.py registered UsersModule + +Resource ready +``` + +Error output should be specific and actionable: + +```text +Could not add resource + +Reason + src/app_module.py was not found. + +Fix + Run this command inside a PyNest app, or pass --path to the app root. +``` + +When `--json` is used, no colored or human prose output should be emitted. + +## Generated Project Presentation + +Generated apps should look clean when opened by a human or an agent: + +- Create `.pynest.yaml` in the generated project root. +- Generate a focused `README.md` with exact install, run, and add-resource commands. +- Generate `.env.example` for database presets. +- Keep starter API code minimal and formatted. +- Keep generated CLI app code minimal and runnable. +- Avoid adding a frontend or heavy visual app unless a future explicit preset asks for it. + +Example `.pynest.yaml`: + +```yaml +version: 1 +preset: api +database: sqlite +async: true +source_root: src +``` + +## Architecture + +Add a small generation result model: + +- Operation name. +- Project or target path. +- Preset/database/async settings. +- Files created. +- Files updated. +- Files skipped. +- Warnings. +- Next steps. + +Template writing should return this result instead of printing directly. A presentation layer should then render either: + +- Human terminal output. +- JSON output. + +This keeps generation behavior testable and avoids coupling file creation to terminal text. + +Suggested internal split: + +- `GenerateService`: command-facing orchestration. +- `ApplicationGenerator`: validates and creates new apps. +- `ComponentGenerator`: validates and adds resources/components. +- `GenerationResult`: structured result object. +- `GenerationPresenter`: human and JSON renderers. +- Existing templates: reused and gradually cleaned up. + +## Compatibility + +Existing commands should remain valid: + +```bash +pynest generate application -n my_app +pynest generate resource -n users +``` + +They can internally call the new services and render the same improved output. + +Compatibility mappings: + +- `generate application -n NAME` -> `new NAME`. +- `generate resource -n NAME` -> `add resource NAME`. +- `generate module -n NAME` -> `add module NAME`. +- `generate controller -n NAME` -> `add controller NAME`. +- `generate service -n NAME` -> `add service NAME`. +- `generate gateway -n NAME` -> `add gateway NAME`. + +## Testing + +Tests should cover: + +- `pynest new my-app --yes` creates the expected file tree. +- `pynest new my-app --database sqlite --async --yes` creates config and metadata. +- `pynest new --prompt` can be driven with Click's test input. +- `pynest new my-app --json --yes` emits valid JSON only. +- `pynest new my-app --dry-run` writes no files. +- Invalid database values produce actionable human errors and structured JSON errors. +- `pynest add resource users --json` reports created and updated files. +- Compatibility commands still work. +- Existing gateway generation tests continue to pass. + +## Rollout + +Implement in focused phases: + +1. Add structured generation result and presenter. +2. Add `pynest new` with interactive, non-interactive, JSON, and dry-run modes. +3. Move app metadata to `.pynest.yaml`. +4. Add `pynest add` commands and route old `generate` commands through the new behavior. +5. Add `pynest doctor`. +6. Update docs and README examples. + +The first implementation should prioritize `new`, `add resource`, JSON, dry-run, and compatibility. `doctor` can follow once metadata discovery is in place. From c22f641d594cb410655a655eed2b4b25aa04c5e4 Mon Sep 17 00:00:00 2001 From: Itay Dar <118370953+ItayTheDar@users.noreply.github.com> Date: Wed, 13 May 2026 20:10:14 +0300 Subject: [PATCH 2/4] feat: improve cli generation experience --- .github/workflows/cli_test.yaml | 26 +- README.md | 68 +- docs/cli.md | 199 ++--- .../2026-05-13-cli-generation-experience.md | 189 +++++ nest/cli/src/app_module.py | 2 + nest/cli/src/generate/generate_controller.py | 95 ++- nest/cli/src/generate/generate_model.py | 29 + nest/cli/src/generate/generate_service.py | 712 +++++++++++++++++- nest/cli/src/generate/generation_cli.py | 213 ++++++ nest/cli/src/generate/generation_result.py | 233 ++++++ tests/test_cli/test_add_command.py | 75 ++ .../test_cli/test_generation_compatibility.py | 97 +++ tests/test_cli/test_generation_result.py | 112 +++ tests/test_cli/test_new_command.py | 191 +++++ 14 files changed, 2072 insertions(+), 169 deletions(-) create mode 100644 docs/superpowers/plans/2026-05-13-cli-generation-experience.md create mode 100644 nest/cli/src/generate/generation_cli.py create mode 100644 nest/cli/src/generate/generation_result.py create mode 100644 tests/test_cli/test_add_command.py create mode 100644 tests/test_cli/test_generation_compatibility.py create mode 100644 tests/test_cli/test_generation_result.py create mode 100644 tests/test_cli/test_new_command.py diff --git a/.github/workflows/cli_test.yaml b/.github/workflows/cli_test.yaml index d03d81d..c543e6a 100644 --- a/.github/workflows/cli_test.yaml +++ b/.github/workflows/cli_test.yaml @@ -30,37 +30,38 @@ jobs: - name: Test CLI Commands run: | + pynest_cmd="$GITHUB_WORKSPACE/.venv/bin/pynest" app_name="${{ matrix.app_type }}App" case "${{ matrix.app_type }}" in "Blank") - uv run pynest generate application -n "$app_name" + "$pynest_cmd" generate application -n "$app_name" ;; "SyncORM") - uv run pynest generate application -n "$app_name" -db sqlite + "$pynest_cmd" generate application -n "$app_name" -db sqlite ;; "AsyncORM") - uv run pynest generate application -n "$app_name" -db sqlite --is-async + "$pynest_cmd" generate application -n "$app_name" -db sqlite --is-async ;; "MongoDB") - uv run pynest generate application -n "$app_name" -db mongodb + "$pynest_cmd" generate application -n "$app_name" -db mongodb ;; "PostgresSync") - uv run pynest generate application -n "$app_name" -db postgresql + "$pynest_cmd" generate application -n "$app_name" -db postgresql ;; "PostgresAsync") - uv run pynest generate application -n "$app_name" -db postgresql --is-async + "$pynest_cmd" generate application -n "$app_name" -db postgresql --is-async ;; "MySQLSync") - uv run pynest generate application -n "$app_name" -db mysql + "$pynest_cmd" generate application -n "$app_name" -db mysql ;; "MySQLAsync") - uv run pynest generate application -n "$app_name" -db mysql --is-async + "$pynest_cmd" generate application -n "$app_name" -db mysql --is-async ;; esac cd "$app_name" - uv run pynest generate resource -n user - uv run pynest generate gateway -n chat -p src + "$pynest_cmd" generate resource -n user + "$pynest_cmd" generate gateway -n chat -p src - name: Verify Boilerplate run: | @@ -79,7 +80,7 @@ jobs: exit 1 fi - declare -a files=("main.py" "requirements.txt" "README.md") + declare -a files=("main.py" "pyproject.toml" "README.md" ".pynest.yaml") declare -a src_level_files=("app_module.py" "app_service.py" "app_controller.py") declare -a module_files=("user_controller.py" "user_service.py" "user_module.py" "user_model.py") @@ -121,14 +122,13 @@ jobs: echo "$gateway_file is missing the expected @WebSocketGateway decorator." exit 1 fi - echo "Boilerplate for ${{ matrix.app_type }} generated successfully." - name: Ping generated WebSocket app if: matrix.app_type == 'Blank' run: | cd "${{ matrix.app_type }}App" - uv run python - <<'PY' + uv run --project "$GITHUB_WORKSPACE" python - <<'PY' import asyncio import importlib.util import json diff --git a/README.md b/README.md index e933201..e15f8ad 100644 --- a/README.md +++ b/README.md @@ -41,19 +41,21 @@ pip install pynest-api ### Start with cli ```bash -pynest generate application -n my_app_name +pynest new my_app_name ``` this command will create a new project with the following structure: ```text -├── app.py +├── .pynest.yaml ├── main.py -├── requirements.txt -├── .gitignore +├── pyproject.toml ├── README.md ├── src │ ├── __init__.py +│ ├── app_module.py +│ ├── app_controller.py +│ ├── app_service.py ``` once you have created your app, get into the folder and run the following command: @@ -65,7 +67,8 @@ cd my_app_name run the server with the following command: ```bash -uvicorn "app:app" --host "0.0.0.0" --port "8000" --reload +uv sync +python main.py ``` Now you can visit [OpenAPI](http://localhost:8000/docs) in your browser to see the default API documentation. @@ -75,7 +78,7 @@ Now you can visit [OpenAPI](http://localhost:8000/docs) in your browser to see t To add a new module to your application, you can use the pynest generate module command: ```bash -pynest generate resource -n users +pynest add resource users ``` This will create a new resource called ```users``` in your application with the following structure under the ```src``` @@ -108,15 +111,55 @@ and their descriptions: #### `generate application` Subcommand -- **Description**: Create a new nest app. +- **Description**: Create a new nest app. This command is still supported for compatibility; prefer `pynest new`. - **Options**: - `--app-name`/`-n`: The name of the nest app (required). - `--db-type`/`-db`: The type of the database (optional). You can specify PostgreSQL, MySQL, SQLite, or MongoDB. - `--is-async`: Whether the project should be asynchronous (optional, default is False). + - `--package-manager`: Use `uv` by default, or `requirements` when explicitly requested. + - `--json`: Output structured JSON for agents and scripts. + - `--dry-run`: Show the generation plan without writing files. + +#### `new` Subcommand + +- **Description**: Create a new PyNest application. It supports guided prompts for humans and one-shot flags for agents. +- **Examples**: + - Guided human flow: `pynest new --prompt` + - Default API app: `pynest new my_app_name` + - Agent-friendly JSON flow: `pynest new my_app_name --preset api --database sqlite --async --yes --json` +- **Options**: + - `--preset`: `api` or `cli` (default: `api`). + - `--database`: `none`, `sqlite`, `postgresql`, `mysql`, or `mongodb` (default: `none`). + - `--async`: Use async database access for relational databases. + - `--path`: Parent directory for the new app. + - `--package-manager`: `uv` or `requirements` (default: `uv`). + - `--prompt`: Force guided prompts. + - `--yes`: Accept defaults and skip prompts. + - `--json`: Output structured JSON only. + - `--dry-run`: Show the plan without writing files. + +### `add` command group + +- **Description**: Add boilerplate code to an existing PyNest application. + +#### `resource` Subcommand + +- **Description**: Add a new module with controller, service, model, and module files. Database apps also get an entity file. +- **Options**: + - `NAME`: The resource name. + - `--path`: Target app or source directory. + - `--json`: Output structured JSON. + - `--dry-run`: Show the plan without writing files. + +Example: + +```bash +pynest add resource users +``` ### `generate` command group -- **Description**: Group command for generating boilerplate code. +- **Description**: Compatibility command group for older PyNest projects and scripts. #### `resource` Subcommand @@ -127,13 +170,16 @@ and their descriptions: #### CLI Examples * create a blank nest application - - `pynest generate application -n my_app_name` + `pynest new my_app_name` * create a nest application with postgres database and async connection - - `pynest generate application -n my_app_name -db postgresql --is-async` + `pynest new my_app_name --database postgresql --async` * create new module - - `pynest generate resource -n users` + `pynest add resource users` + +* run a project health check - + `pynest doctor` ## Key Features diff --git a/docs/cli.md b/docs/cli.md index c435c92..1ee86c0 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -1,179 +1,134 @@ -# PyNest CLI Deep Dive 🔍 +# PyNest CLI -The PyNest CLI is a powerful tool that helps you quickly scaffold, develop, and manage your PyNest applications. This guide will walk you through all the commands and best practices to make the most out of the PyNest CLI. - -## Installation 💻 - -Before using the PyNest CLI, ensure you have it installed. You can install it using pip: +The PyNest CLI scaffolds applications and common application components. The primary command surface is: ```bash -pip install pynest-api +pynest new my_app +pynest add resource users +pynest add gateway chat +pynest doctor ``` -## CLI Commands and Usage 🛠️ -The PyNest CLI provides a variety of commands to help you create and manage your PyNest applications. Below are the detailed descriptions of the available commands and their usage. +Older `pynest generate ...` commands still work for compatibility. -### Generate New Application -Create a new PyNest application. +## Install ```bash -pynest generate application --app-name [--db-type ] [--is-async] -``` -**Options** - -* `--app-name`, `-n`: The name of the new application. (Required) -* `--db-type`, `-db`: The type of database to use (postgresql, mysql, sqlite, mongodb). (Optional) -* `--is-async`: Whether the project should be async or not. This is applicable only for relational databases. (Optional) -* `--is-cli`: Whether the project should be a CLI App. (Optional) - -#### Example -```bash -pynest generate application --app-name my_pynest_app --db-type postgresql --is-async +pip install pynest-api ``` -This example will create a skeleton PyNest application named `my_pynest_app` with PostgreSQL as the database and async support. +## Create An Application -#### File Structure 🗂️ -Here's the typical file structure of a PyNest application generated by the CLI: +For a guided human flow: -```text -my_pynest_app/ -├── src/ -│ ├── __init__.py -│ ├── app_module.py -│ ├── app_controller.py -│ ├── app_service.py -│ ├── config.py -├── main.py -├── requirements.txt -└── README.md +```bash +pynest new --prompt ``` -!Note: The actual file structure may vary based on the modules and components you create - - -### generate command -Generate boilerplate code for various components of the application. - -#### Subcommands - -**Resource** -Generate a new resource with the associated controller, service, model and module files, with respect to the project configurations (e.g. database type). +For a direct command: ```bash -pynest generate resource --name +pynest new my_app ``` -**Options** - +For an agent or script: -* `--name`, `-n`: The name of the new module. (Required) -* `--path`, `-p`: The path where the module should be created. (Optional) - -**Example** ```bash -pynest generate resource --name users +pynest new my_app --preset api --database sqlite --async --yes --json ``` -This will create a new resource named `users` with the associated controller, service, model and module files. - - -**Module** +Useful options: -Generate a new module file, which can be used to group related components of the application. - -```bash -pynest generate module --name -``` +- `--preset api|cli`: choose an HTTP API app or CLI app. Default: `api`. +- `--database none|sqlite|postgresql|mysql|mongodb`: add database scaffolding. Default: `none`. +- `--async`: use async database access for relational databases. +- `--path PATH`: parent directory where the app should be created. +- `--package-manager uv|requirements`: choose generated dependency files. Default: `uv`. +- `--prompt`: force guided prompts. +- `--yes`: accept defaults and skip prompts. +- `--dry-run`: show the plan without writing files. +- `--json`: emit machine-readable JSON only. +- `--quiet`: suppress human output. +- `--force`: overwrite supported files. -**Options** +Generated API apps include: -* `--name`, `-n`: The name of the new module. (Required) -* `--path`, `-p`: The path where the module should be created. (Optional) - -**Example** -```bash -pynest generate module --name auth +```text +my_app/ +├── .pynest.yaml +├── main.py +├── README.md +├── pyproject.toml +└── src/ + ├── __init__.py + ├── app_module.py + ├── app_controller.py + └── app_service.py ``` -This will create a new module named `auth` in the default path. +Database apps also include `src/config.py`, `.env.example`, and database-specific requirements. -**Controller** +PyNest uses `uv` by default and writes `pyproject.toml`. Use `--package-manager requirements` only when you need a legacy `requirements.txt` workflow. -Generate a new controller file, which will handle the routing and responses for a specific resource. +Prompt mode also asks for package management: -```bash -pynest generate controller --name +```text +Package manager: + 1. uv + 2. requirements.txt +Choose package manager [1]: ``` -**Options** +## Add Components -* `--name`, `-n`: The name of the new controller. (Required) -* `--path`, `-p`: The path where the controller should be created. (Optional) +Run these commands inside a PyNest application, or pass `--path` to the app root. -**Example** ```bash -pynest generate controller --name users +pynest add resource users +pynest add module auth +pynest add controller users +pynest add service users +pynest add gateway chat ``` -This will create a new controller named `users` in the default path. +Shared options: -**Service** +- `--path PATH`: target app or source directory. +- `--dry-run`: show the plan without writing files. +- `--json`: emit machine-readable JSON only. +- `--quiet`: suppress human output. +- `--force`: overwrite supported files. -Generate a new service file, which will contain the business logic for a specific resource. +`pynest add` reads `.pynest.yaml` so generated resources match the app preset, database, and async settings. -```bash -pynest generate service --name -``` +`pynest add gateway ` creates a small package under `src//` (`__init__.py`, `_gateway.py`, `_module.py` with the gateway in `providers`), and registers `Module` in `src/app_module.py` — same pattern as `add resource`, without HTTP CRUD files. -**Options** +## Check A Project -* `--name`, `-n`: The name of the new service. (Required) -* `--path`, `-p`: The path where the service should be created. (Optional) - -**Example** ```bash -pynest generate service --name users +pynest doctor ``` -This will create a new service named `users` in the default path. - -**Gateway** - -Generate a new WebSocket gateway file. +`doctor` checks project metadata and source layout. For agents: ```bash -pynest generate gateway --name +pynest doctor --json ``` -**Options** +## Compatibility Commands -* `--name`, `-n`: The name of the new gateway. (Required) -* `--path`, `-p`: The path where the gateway should be created. (Optional) +These commands are still supported: -**Example** ```bash -pynest generate gateway --name chat +pynest generate application -n my_app +pynest generate resource -n users +pynest generate module -n auth +pynest generate controller -n users +pynest generate service -n users +pynest generate gateway -n chat ``` -This creates `chat_gateway.py` with a starter `@WebSocketGateway(namespace="/chat")` class and a `ping` message handler. Add the generated gateway to a module's `providers` list to mount it. - - -## Best Practices 🌟 - -To ensure a clean and maintainable codebase, follow these best practices when using the PyNest CLI: - -* **Consistent Naming Conventions**: Use consistent naming conventions for files and directories. For example, use lowercase with underscores for module names (users_module.py) and camelCase for class names (UsersController)._ - -* **Modular Structure**: Keep your code modular. Each module should encapsulate a specific functionality of your application. - -* **Service Layer**: Keep business logic within services to maintain separation of concerns. Controllers should handle HTTP requests and responses only. - -* **Dependency Injection**: Use dependency injection to manage dependencies between services and controllers. This makes your code more testable and maintainable. - -* **Environment Configuration**: Use environment variables to manage configuration settings, such as database connection strings and API keys. - -The PyNest CLI is a powerful tool that simplifies the development of PyNest applications. By following the best practices and utilizing the commands effectively, you can build scalable and maintainable applications with ease. Happy coding! +Compatibility commands also support `--json` and `--dry-run` where applicable. ---