Skip to content

Commit

Permalink
Fastify support (#325)
Browse files Browse the repository at this point in the history
* Added fastify with routes working

* Fastify support

* E2E tests

* Linting errors

* E2E tests

* Library for fastify and request plugins

* Library for fastify and request plugins

* Fixed some CVEs

* Apply suggestions from code review

Co-authored-by: Raz Luvaton <[email protected]>

* Added OpenAPI doc fixes

* Logger issue

* No static code scan

* No static code scan

* No static code scan

---------

Co-authored-by: Raz Luvaton <[email protected]>
  • Loading branch information
goldbergyoni and rluvaton authored Apr 7, 2024
1 parent a204201 commit 4148ce9
Show file tree
Hide file tree
Showing 108 changed files with 15,735 additions and 102,338 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/app-quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
# Uncomment and replace this with current `os` when windows-run bug is fixed
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
with:
directory: ./src/code-templates/services/order-service/test-reports/coverage
env_vars: OS
fail_ci_if_error: true
fail_ci_if_error: false
flags: app
name: codecov-umbrella
verbose: true
4 changes: 2 additions & 2 deletions .github/workflows/code-generator-quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
# Uncomment and replace with current `os` when windows-run bug is fixed
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
Expand All @@ -39,7 +39,7 @@ jobs:
with:
directory: ./test-reports/coverage
env_vars: OS
fail_ci_if_error: true
fail_ci_if_error: false
flags: generator
name: codecov-umbrella
verbose: true
45 changes: 0 additions & 45 deletions .github/workflows/e2e-default-flags.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: generator-quality-check
name: e2e

on:
push:
Expand All @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [20.x]
# Uncomment and replace with current `os` when windows-run bug is fixed
# os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
Expand All @@ -32,14 +32,14 @@ jobs:
- run: npm ci

- name: Test
run: npm t -- --collectCoverage e2e-non-interactive-prisma-orm.slow.test.ts
run: npm t -- --collectCoverage e2e

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./test-reports/coverage
env_vars: OS
fail_ci_if_error: true
fail_ci_if_error: false
flags: generator
name: codecov-umbrella
verbose: true
5 changes: 1 addition & 4 deletions .github/workflows/scheduled-installer-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ name: scheduled-installer-check

on:
schedule:
- cron: '5,15,25,35,45,55 * * * *'

- cron: "5,25,45 * * * *"

jobs:
scheduled-installer-check:
runs-on: ubuntu-latest
steps:
- name: Install practica
run: npx @practica/create-node-app immediate --install-dependencies
# TODO: Create an issue on failure using:
# https://github.com/marketplace/actions/create-an-issue
8 changes: 0 additions & 8 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ jobs:
command: test
args: --all-projects --severity-threshold=critical --sarif-file-output=~/sarif/sca.sarif

- name: Run Snyk Static Code Analysis
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: code test
args: --severity-threshold=high --sarif-file-output=~/sarif/sast.sarif

- name: list
run: "ls -a ~/sarif"

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20.12.0
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 9229,
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**/*.js"
],
"restart": true
},
{
"type": "node",
"request": "launch",
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

<br/>

### Generate a Node.js app that is packed with best practices AND simplicity in mind. Based off our repo [Node.js best practices](https://github.com/goldbergyoni/nodebestpractices) (80,500 stars)
### Generate a Node.js app that is packed with best practices AND simplicity in mind. Based off our repo [Node.js best practices](https://github.com/goldbergyoni/nodebestpractices) (96,100 stars)

<br />


![Discord](/static/images/discord-logo.png) [Discord discussions](https://discord.gg/SrM68BJPqR) | ![Twitter](/static/images/twitter-icon.png) [Twitter](https://twitter.com/nodepractices) | ![Site](/docs/static/img/site-icon.png) [Documentation site](https://practica.dev/)
![Twitter](/static/images/twitter-icon.png) [Twitter](https://twitter.com/nodepractices) | ![Site](/docs/static/img/site-icon.png) [Documentation site](https://practica.dev/)


<br/>

# A One Paragraph Overview

Although Node.js has great frameworks 💚, they were never meant to be production ready immediately. Practica.js aims to bridge the gap. Based on your preferred framework, we generate example code that demonstrates a full Microservice flow, from API to DB, that is packed with good practices. For example, we include a battle-tested error handler, sanitize API response, hardened dockerfile, thoughtful 3-tier folder structure, great testing templates with DB, and more. This saves a great deal of time and can prevent painful mistakes. All decisions made are [neatly and thoughtfully documented](https://practica.dev/decisions). We strive to keep things as simple and standard as possible and base our work on the popular guide: [Node.js Best Practices](https://github.com/goldbergyoni/nodebestpractices)
Although Node.js has great frameworks 💚, they were never meant to be dev & production ready immediately (e.g., no architecture layers, DB schemas, docker file, etc etc). Practica.js aims to bridge the gap. Based on your preferred framework, we generate example code that demonstrates a full Microservice flow, from API to DB, that is packed with good practices. For example, we include a battle-tested error handler, sanitized API response, hardened dockerfile, thoughtful 3-tier folder structure, great testing templates with DB, and more. This saves a great deal of time and can prevent painful mistakes. All decisions made are [neatly and thoughtfully documented](https://practica.dev/decisions). We strive to keep things as simple and standard as possible and base our work on the popular guide: [Node.js Best Practices](https://github.com/goldbergyoni/nodebestpractices)

**1 min video 👇, ensure audio is activated**

Expand Down Expand Up @@ -63,15 +63,15 @@ Run practica CLI and generate our default app (you can customize it using differ
npx @practica/create-node-app immediate --install-dependencies
```

✨ And you're done! That's it. The code's all been generated.
✨ And you're done! That's it, the code's all been generated. Our default setup includes Fastify for the web layer, Sequelize for the data access and PostgreSQL

We also have a CLI interactive mode:
Prefer express and Prisma? Just pass the right flags to the CLI:

```bash
npx @practica/create-node-app interactive
npx @practica/create-node-app immediate --install-dependencies --web-framework=express --orm=prisma
```

Note that for now, it can generate an app that is based on Express and PostgreSQL only. Other options will get added soon
Prefer other DB? We use standard ORMs, read its docs and switch DB. This is your code, do whatever you like


<br />
Expand All @@ -95,9 +95,9 @@ or run the tests:
npm test
```

Pretty straight forward, right?
Pretty straightforward, right?

You just got a Node.js Monorepo solution with one example component/Microservice and multiple libraries. Based on this hardened solution you can build a robust application. The example component/Microservice is located under: *{your chosen folder name}/services/order-service*. This is where you'll find the API and a good spot to start your journey from.
You just got a Node.js Monorepo solution with one example component/Microservice and multiple libraries. Based on this hardened solution you can build a robust application. The example component/Microservice is located under: *{your chosen folder name}/services/order-service*. This is where you'll find the API and a good spot to start your journey from

<br />

Expand All @@ -114,29 +114,29 @@ You just got a Node.js Monorepo solution with one example component/Microservice

### 1. Best Practices _on top of_ known Node.js frameworks

We don't re-invent the wheel. Rather, we use your favorite framework and empower it with structure and real examples. With a single command you can get an Express/Fastify-based codebase with ~100 examples of best practices inside.
We don't re-invent the wheel. Rather, we use your favorite framework and empower it with structure and real examples. With a single command you can get an Express/Fastify-based codebase with many thoughtful best practices inside

![Built on top of known frameworks](/static/images/on-top-of-frameworks.png)

### 2. Simplicity, how Node.js was intended

Keeping it simple, flat, and based on native Node/JS capabilities is part of this project's DNA. We believe that too many abstractions, high-complexity or fancy language features can quickly become a stumbling block for the team.
Keeping it simple, flat, and based on native Node/JS capabilities is part of this project's DNA. We believe that too many abstractions, high-complexity or fancy language features can quickly become a stumbling block for the team

To name a few examples, our code flow is flat with almost no level of indirection, although using TypeScript - almost no features are being used besides types, for modularization we simply use Node.js modules.
To name a few examples, our code flow is flat with almost no level of indirection, no DI - it's just simple functions calling other functions. Although using TypeScript, almost no features are being used besides types, for modularization we simply use... Node.js modules

![Built on top of known frameworks](/static/images/abstractions-vs-simplicity.png)
![Simplicity!](/static/images/abstractions-vs-simplicity.png)

### 3. Supports many technologies and frameworks

Good Practices and Simplicity is the name of the game with Practica. There is no need to narrow our code to a specific framework or database. We aim to support a majority of popular Node.js frameworks and databases.
Good Practices and Simplicity is the name of the game with Practica. There is no need to narrow our code to a specific framework or database. We aim to support the popular Node.js frameworks and data access approaches

![Built on top of known frameworks](/static/images/tech-stack.png)

<br />

# Practices and Features

We apply more than 100 practices and optimizations. You can opt in or out for most of these features using option flags on our CLI. The following table lists just a few examples out of the [full list of features we provide](https://practicajs.org/features).
We apply dozens of practices and optimizations. You can opt in or out for most of these features using option flags on our CLI. The following table lists just a few examples out of the [full list of features we provide](https://practicajs.org/features).

| **Feature** | **Explanation** | **Flag** | **Docs** |
| ----------- | --------------- | -------- | -------- |
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/the-basics/coding-with-practica.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ Now visit our [online POSTMAN collection](https://documenter.getpostman.com/view

**Note:** The API routes authorize requests, a valid token must be provided. You may generate one yourself ([see here how](../questions-and-answers.md)), or just use the default _development_ token that we generated for you 👇. Put it inside an 'Authorization' header:

```Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NjIwMTY5NjIsImV4cCI6MTY5MzU1Mjk2MiwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.65ACAjHy2ZE5i_uS5hyiEkOQfkqOqdj-WtBm-w23qZQ```
```Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzM4NTIyMTk5NzEsImRhdGEiOnsidXNlciI6ImpvZSIsInJvbGVzIjoiYWRtaW4ifSwiaWF0IjoxNzEyMjUyMjE5fQ.kUS7AnwtGum40biJYt0oyOH_le1KfVD2EOrs-ozclY0```

We have the ground ready 🐥. Let's code now, just remember to run the tests (or POSTMAN) once in a while to ensure nothing breaks

## The 3 layers of a component

A typical component (e.g., Microservice) contains 3 main layers. This is a known and powerful pattern that is called ["3-Tiers"](https://www.techopedia.com/definition/24649/three-tier-architecture). It's an architectural structure that strikes a great balance between simplicity and robustness. Unlike other fancy architectures (e.g. hexagonal architecture, etc), this style is more likely to keep things simple and organized. The three layers represent the physical flow of a request with no abstractions:
Expand Down
Loading

0 comments on commit 4148ce9

Please sign in to comment.