Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI for Bootstrapping Patterns #53

Closed
jpgough-ms opened this issue Mar 12, 2024 · 13 comments
Closed

CLI for Bootstrapping Patterns #53

jpgough-ms opened this issue Mar 12, 2024 · 13 comments
Assignees

Comments

@jpgough-ms
Copy link
Member

Feature Request

Description of Problem:

Patterns implemented as JSON Schema help to constrain and define reusable architectures. Developers can use tooling to "autocomplete" patterns, as demonstrated at #52 and at our monthly call.

We would like to propose the creation of a simple command line interface CLI that:

  • Fetches a pattern
  • Validates that it conforms to the CALM schema
  • Runs Linting against the pattern
  • Generates the target pattern instantiation in JSON or YAML
  • Makes it obvious to the developer the fields that they are required to contribute to
@jpgough-ms jpgough-ms changed the title Pattern CLI for Bootstrapping Patterns CLI for Bootstrapping Patterns Mar 12, 2024
@jpgough-ms jpgough-ms mentioned this issue Mar 12, 2024
7 tasks
@willosborne
Copy link
Member

For the final bullet point - it would be great if the linter could pick up fields that weren't filled in and give the user a list of things to do on the CLI. Also, since Spectral has IDE plugins we could even get this information directly into their editor.

We could do this by just filling the blanks with some placeholder like MISSING_VALUE and then just having a spectral rule that looks for any property set to MISSING_VALUE.

@willosborne
Copy link
Member

One consideration here is which language we should use for the bootstrap CLI. In my mind we have two main options, Python and Node (i.e. JS or TypeScript.) I've had a think about some pros/cons - would be good to hear people's thoughts

Python

Pros

  • Great argument parser (click) that also has strong support for subcommands
  • More native libraries for JSON Schema validation than Node
  • Can publish CLI tool to pypi for easy consumption

Cons

  • No native interop with visualisation tool as that is based on JS - would need to call out via subprocess
  • No native interop with Spectral, would need to call out via subprocess

Node / JavaScript

Pros

  • Similar arg parser library based on Python's click (Commander)
  • Native interop with visualization tool @aidanm3341 is working on
  • Native interop with Spectral - can use it from within a Node app
  • Can publish CLI tool to NPM for easy consumption
  • Option for strong typing via TypeScript

Cons

  • Strong typing may be a hindrance in early stages as CALM schema is volatile - more refactoring needed
  • Main option for JSON Schema validation is ajv - if that doesn't work we will need to call out to another CLI tool via subprocess

Other languages

Java:

  • CLI tools are weaker than Node/Python
  • No interop with tools in use,
  • Heavier CLI size due to fat jar
  • CLI install may be more difficult

Go:

  • Less widely used language, so experience may be limited

@aidanm3341
Copy link
Member

We've been discussing this in person and I'm in favour of Node. I've already been working on embedding the new Mermaid visualizer tool in a simple Commander CLI just for the purposes of making it usable and found to be very easy to work with (PR for that incoming soon). So if we go that way, the groundwork will already have been done as well.

@rocketstack-matt
Copy link
Member

I think the only question against Node would be is schema validation tools are week, especially as most of our other tools are currently Node. What do we need to do to close out on the schema validation questions?

@willosborne
Copy link
Member

We need to confirm that we can validate JSON schemas against a metaschema with libraries available in Node.
Given that OpenAPI is a metaschema this should be possible - will take a look at this today.

@Budlee
Copy link
Member

Budlee commented Mar 19, 2024

Golang, negatives I would disagree with?
It's a very viable choice for creating a CLI and is very widely used. There are some fantastic frameworks for CLI development in Go and the flags package is in the std lib which for most cases more than enough to develop a good quality CLI.

@willosborne
Copy link
Member

Another question is how the CLI is going to fetch pattern files. This relates to #69 - the CLI needs to be able to pull patterns not only from this industry-standard repository but also internal repositories for an organisation.

Our suggestion is that we keep this as simple as possible from the pattern CLI's perspective by letting you provide either a HTTP URL (with no auth) or a file reference, and the CLI will load it.

In other words, no CLI or similar abstraction for 'looking up' patterns by name yet; we can always add this later if need be.

Something like the following:

  • calm generate -s FILE/URL (-s for source) to load a schema from a file or URL (can tell based on the presence of a URL scheme)

In future we could add a dictionary of pattern names to file/URL references to the project to allow resolution by a pattern name. This is a separate topic - we can proceed without implement this if people are happy with the above suggestion.

@Budlee
Copy link
Member

Budlee commented Mar 20, 2024

Would you not want to start by looking up a file and then a future improvement will be sourcing from a URL if it's a feature that is required?

@aidanm3341
Copy link
Member

We've been testing out the AJV JSON Schema library and so far it seems promising. For the basic case of validating a pattern instantiation, it works as expected. The case we're interested in is validating the pattern against the meta schema. We've been able to get this to work by fixing what we believe to be some mistakes in the core.json and api-gateway.json, e.g.

  • The required field in core.json should be outside of the properties object, not inside it
  • The way we use the items keyword is required to be called prefixItems as of JSON Schema 2020-12
  • In api-gateway.json, many of the nodes don't have node-type defined, despite it being a required field on a node

I can raise an issue for the above problems unless anyone thinks we're wrong.

Once fixing those issues, we're still running into one problem where all properties on a node are required to have the field nodes for some reason. We'll continue looking into that issue tomorrow, but we are definitely encouraged about this library based on the progress that we made today.

@willosborne
Copy link
Member

Raised a discussion here about approach for instantiation to avoid polluting this thread with multiple concurrent discussions: #71

@rocketstack-matt
Copy link
Member

We've been testing out the AJV JSON Schema library and so far it seems promising. For the basic case of validating a pattern instantiation, it works as expected. The case we're interested in is validating the pattern against the meta schema. We've been able to get this to work by fixing what we believe to be some mistakes in the core.json and api-gateway.json, e.g.

  • The required field in core.json should be outside of the properties object, not inside it
  • The way we use the items keyword is required to be called prefixItems as of JSON Schema 2020-12
  • In api-gateway.json, many of the nodes don't have node-type defined, despite it being a required field on a node

I can raise an issue for the above problems unless anyone thinks we're wrong.

Once fixing those issues, we're still running into one problem where all properties on a node are required to have the field nodes for some reason. We'll continue looking into that issue tomorrow, but we are definitely encouraged about this library based on the progress that we made today.

Happy for you to go ahead and raise a PR for the changes . . . for the pattern that just shows we didn't update it along with the schema changes and shows we have a gap to close around keeping patterns up to date with manifest changes; this isn't a simple validation because they currently reference specific schema versions and even if we were to move to a 'current' version we would need to merge and publish it before it would be spotted that it broke something.

@rocketstack-matt
Copy link
Member

Another question is how the CLI is going to fetch pattern files. This relates to #69 - the CLI needs to be able to pull patterns not only from this industry-standard repository but also internal repositories for an organisation.

Our suggestion is that we keep this as simple as possible from the pattern CLI's perspective by letting you provide either a HTTP URL (with no auth) or a file reference, and the CLI will load it.

In other words, no CLI or similar abstraction for 'looking up' patterns by name yet; we can always add this later if need be.

Something like the following:

  • calm generate -s FILE/URL (-s for source) to load a schema from a file or URL (can tell based on the presence of a URL scheme)

In future we could add a dictionary of pattern names to file/URL references to the project to allow resolution by a pattern name. This is a separate topic - we can proceed without implement this if people are happy with the above suggestion.

Fine with this for a first version, although we should probably raise an issue to track adding a central supported patterns repo as a fairly high priority.

@aidanm3341 aidanm3341 self-assigned this Mar 26, 2024
aidanm3341 added a commit to aidanm3341/architecture-as-code that referenced this issue Mar 26, 2024
rocketstack-matt pushed a commit that referenced this issue Mar 26, 2024
Budlee pushed a commit to Budlee/architecture-as-code that referenced this issue Apr 1, 2024
@rocketstack-matt
Copy link
Member

This issue is complete, specific additions will br tracked in their own issues.

rocketstack-matt added a commit that referenced this issue Apr 7, 2024
* #55 initial prototype of the CALM translator service

* #55 Additional changes to the prototype translator to tidy up the c4 endpoints

* #55 move project to be top level and add a README

* #55 Fix to reference to calm schema from chaninging top level project

* #55 Add dockerfile to containerize the application

* Improvement to code to handle multiple software systems

* #86 Update README

* #86 Remove supress warnings annotation

* Fix translator action

* Fix translator action and checkin breaking test to confirm - test wil be removed before merge.

* Update TestC4ModelTranslatorShould.java

Removing the breaking test now we have proof it failed.

* #35 Add manual spectral action  (#68)

* #35 Add manual spectral validation action

* Fix indentation

* Modify triggers for job

* Validate samples instead of bad document

* Change sample again to trigger build

* PR feedback

* Bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docs (#78)

Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4.
- [Release notes](https://github.com/webpack/webpack-dev-middleware/releases)
- [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md)
- [Commits](webpack/webpack-dev-middleware@v5.3.3...v5.3.4)

---
updated-dependencies:
- dependency-name: webpack-dev-middleware
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* created core cli (#53) (#80)

* #74 - Updating the api-gateway.json pattern to use prefixItems (#79)

* #74 - Updating the api-gateway.json pattern to use the prefixItems keyword instead of items as per JSON Schema 2020-12

* Only run spectral validation on json and yaml files.

* #74 - Adding placeholder values to api-gateway-implementation.json

* Update api-gateway-implementation.json

Remove the parties element which was removed form the schema.

---------

Co-authored-by: Luigi Bulanti <lui.bulanti99@gmail.com>
Co-authored-by: Matthew Bain <66839492+rocketstack-matt@users.noreply.github.com>
Co-authored-by: rocketstack-matt <matt@rocketstack.co>

* #42 removed old visualizer to make room for the new one (#83)

* Fix spectral rules (#81)

* #42 included initial visualization command in CLI (#85)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: rocketstack-matt <matt@rocketstack.co>
Co-authored-by: Matthew Bain <66839492+rocketstack-matt@users.noreply.github.com>
Co-authored-by: Will Osborne <will.osborne@morganstanley.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Aidan McPhelim <aidanmcp@hotmail.co.uk>
Co-authored-by: Luigi Bulanti <luigi.bulanti@morganstanley.com>
Co-authored-by: Luigi Bulanti <lui.bulanti99@gmail.com>
Co-authored-by: jpgough-ms <152306432+jpgough-ms@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants