Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 685aa90

Browse files
raksivtjholmdavemooreuwsjyecuschHomelessDinosaur
authored
add architecture sections to docs (#701)
Co-authored-by: Tim Holm <[email protected]> Co-authored-by: David Moore <[email protected]> Co-authored-by: Jye Cusch <[email protected]> Co-authored-by: Ryan Cartwright <[email protected]>
1 parent 2c77d0a commit 685aa90

37 files changed

+3836
-16
lines changed

.puppeteerrc.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const isCI = !!process.env.VERCEL_ENV
2+
3+
if (!isCI) {
4+
// just use the default configuration on non vercel CI environments
5+
return {}
6+
}
7+
8+
/**
9+
* @type {import("puppeteer").Configuration}
10+
*/
11+
module.exports = {
12+
cacheDirectory: '/vercel/.cache/puppeteer',
13+
executablePath:
14+
'/vercel/.cache/puppeteer/chrome/linux-131.0.6778.204/chrome-linux64/chrome',
15+
chrome: {
16+
skipDownload: true,
17+
},
18+
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
19+
}

chrome-dependencies.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
mesa-libgbm
2+
nss
3+
nspr
4+
at-spi2-atk
5+
cups-libs
6+
libdrm
7+
libXcomposite
8+
libXdamage
9+
libXext
10+
libXrandr
11+
libgbm
12+
libxcb
13+
alsa-lib
14+
atk
15+
gtk3
16+
pango
17+
libxkbcommon

cypress/e2e/broken-links.cy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const IGNORED_URLS = [
2727
'https://www.gutenberg.org/cache/epub/42671/pg42671.txt',
2828
'https://stackoverflow.com/help/minimal-reproducible-example',
2929
'https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks',
30+
'https://jwt.io',
31+
'https://portal.azure.com',
3032
]
3133

3234
const isExternalUrl = (url: string) => {

dictionary.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,22 @@ EC2
236236
.jpg
237237
.pdf
238238
preflight
239+
lifecycle
240+
NodeJS
241+
priviledge
242+
APIS
243+
TLS
244+
SRE
245+
ACM
239246
nav
240247
MacOS
241248
quantized
242249
VPC
243250
trivy
244251
Trivy's
245252
KMS
253+
deployable
254+
VMs
246255
[0-9]+px
247256
^.+[-:_]\w+$
248257
[a-z]+([A-Z0-9]|[A-Z0-9]\w+)

docs/apis.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ description: 'Building HTTP APIs with Nitric'
66

77
Nitric has built-in support for web apps and HTTP API development. The `api` resource allows you to create APIs in your applications, including routing, middleware and request handlers.
88

9+
If you're interested in the architecture, provisioning, or deployment steps, they can be found [here](/architecture/apis).
10+
911
## Creating APIs
1012

1113
Nitric allows you define named APIs, each with their own routes, middleware, handlers and security.
@@ -332,7 +334,7 @@ APIs can include security definitions for OIDC-compatible providers such as [Aut
332334

333335
APIs can be configured to automatically authenticate and allow or reject incoming requests. A `securityDefinitions` object can be provided, which _defines_ the authentication requirements that can later be enforced by the API.
334336

335-
The security definition describes the kind of authentication to perform and the configuration required to perform it. For a [JWT](https://jwt.io/) this configuration includes the JWT issuer and audiences.
337+
The security definition describes the kind of authentication to perform and the configuration required to perform it. For a [JWT](https://jwt.io) this configuration includes the JWT issuer and audiences.
336338

337339
<Note>
338340
Security definitions only define **available** security requirements for an

docs/architecture/apis.mdx

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
description: 'Learn how Nitric provisions and manages APIs across AWS, GCP, and Azure using Terraform and Pulumi.'
3+
---
4+
5+
# APIs
6+
7+
## 1. System Context
8+
9+
**Developers** use Nitric to define required APIs and routes/methods within their application.
10+
11+
- App code uses the [API resource](/apis) to define APIs and their routes/methods.
12+
- Developers define the API(s) their application requires, including the specifications and implement logic to handle HTTP requests.
13+
- Authentication, authorization, and middleware can be added to API routes to secure and enhance functionality.
14+
15+
**Operations** use default or overridden IaC (e.g Terraform modules) to provision the necessary resources for their target cloud(s), such as API Gateways.
16+
17+
<details>
18+
<summary>Example AWS Provider</summary>
19+
20+
- **AWS API Gateway v2** serves as the HTTP API management service.
21+
- **AWS Lambda** functions are deployed to handle API requests.
22+
- **AWS IAM** (automated using IaC) provides roles and policies for secure interaction between API Gateway and Lambda functions.
23+
- **AWS ACM** manages TLS certificates for custom domain names.
24+
25+
```mermaid
26+
flowchart TD
27+
Developer["Developer"]
28+
Operations["Operations"]
29+
App["nitric up"]
30+
APIGateway["AWS API Gateway v2<br>(HTTP API)"]
31+
Lambda["AWS Lambda Functions"]
32+
IAM["AWS IAM"]
33+
ACM["AWS ACM<br>(Certificates)"]
34+
35+
Developer -->|Define API| App
36+
Operations -->|Terraform| App
37+
App -->|Create API Gateway| APIGateway
38+
App -->|Deploy Lambda Functions| Lambda
39+
App -->|Configure Permissions| IAM
40+
APIGateway -->|Invoke| Lambda
41+
ACM -->|Provide Certificates| APIGateway
42+
IAM -->|Manage Access| APIGateway
43+
App -->ACM
44+
45+
classDef default line-height:1;
46+
classDef edgeLabel line-height:2;
47+
```
48+
49+
</details>
50+
<details>
51+
<summary>Example GCP Provider</summary>
52+
53+
- **Google API Gateway** serves as the HTTP API management service, routing requests to backend services.
54+
- **Google Cloud Run** services are deployed to handle API requests with serverless execution.
55+
- **Google IAM** provides roles and policies to secure interactions between API Gateway, Cloud Run, and other GCP services.
56+
- **Certificates** (Google-managed or custom) ensure secure HTTPS communication for custom domain names.
57+
- **Google Service Account** is created and configured to allow API Gateway to invoke the Cloud Run backend securely.
58+
59+
```mermaid
60+
flowchart TD
61+
Developer["Developer"]
62+
Operations["Operations"]
63+
App["nitric up"]
64+
APIGateway["Google API Gateway"]
65+
CloudRun["Google Cloud Run"]
66+
IAM["Google IAM"]
67+
Certificates["Certificates<br>(Google Managed or Custom)"]
68+
ServiceAccount["Google Service Account"]
69+
70+
Developer -->|Define API| App
71+
Operations -->|Terraform| App
72+
App -->|Create API Gateway| APIGateway
73+
App -->|Deploy Cloud Run Services| CloudRun
74+
App -->|Configure Permissions| IAM
75+
APIGateway -->|Invoke| CloudRun
76+
Certificates -->|Provide Certificates| APIGateway
77+
IAM -->|Manage Access| APIGateway
78+
App -->ServiceAccount
79+
App -->Certificates
80+
81+
classDef default line-height:1;
82+
classDef edgeLabel line-height:2;
83+
```
84+
85+
</details>
86+
87+
## 2. Sequence
88+
89+
### Build Sequence
90+
91+
Here is the sequence of events that occur when a developer registers an API with Nitric, including the registration of routes, security, and middleware.
92+
93+
```mermaid
94+
sequenceDiagram
95+
participant Worker as App Worker(s)
96+
participant SDK as Nitric SDK
97+
participant Nitric as Nitric CLI
98+
participant Provider as Nitric Provider <br> (plugin)
99+
participant IAC as IaC <br> (e.g. Terraform)
100+
101+
Worker->>SDK: Register API(s)
102+
SDK->>Nitric: Register API(s)
103+
104+
opt Authentication
105+
Worker->>SDK: Register Security
106+
SDK->>Nitric: Register Security
107+
end
108+
109+
Worker->>SDK: Register Route Callback(s)
110+
SDK->>Nitric: Register Route(s)
111+
Worker->>SDK: Register Middleware(s)
112+
113+
Nitric->>Nitric: Generate OpenAPI Spec
114+
Nitric->>Provider: Forward Nitric Spec
115+
Provider->>IAC: Provision API Gateway
116+
Provider->>IAC: Provision IAM
117+
```
118+
119+
### Runtime Sequence
120+
121+
Here is the sequence of events that occur at runtime when a client makes an HTTP request to an API registered and deployed using Nitric.
122+
123+
```mermaid
124+
sequenceDiagram
125+
participant Client as Client
126+
participant APIGateway as API Gateway <br> (e.g. AWS API Gateway)
127+
participant Auth as Auth Provider
128+
participant Nitric as Nitric Runtime <br> (plugin)
129+
participant SDK as Nitric SDK
130+
participant Worker as App Worker
131+
132+
Client->>APIGateway: HTTP Request
133+
opt Authentication
134+
APIGateway->>Auth: Verify Token
135+
APIGateway-->>Client: Unauthorized
136+
end
137+
APIGateway->>Nitric: Forward Request
138+
Nitric->>Nitric: Convert Request Format
139+
Nitric->>SDK: Route HTTP Event
140+
SDK->>Worker: Execute Route Callback
141+
142+
Worker->>Worker: Process Request
143+
Worker-->>Client: Response
144+
```
145+
146+
## 3. Component
147+
148+
### API Module
149+
150+
- Dynamically creates and manages API gateways to expose application functionality through HTTP endpoints and routes.
151+
- Configures API properties, including protocol type, API specifications (e.g., OpenAPI), and metadata for identification and lifecycle management.
152+
- Provisions and associates backend integrations with API routes, supporting multiple targets such as serverless functions, containers, or application services.
153+
- Automates the setup of custom domain names with secure certificates, abstracting provider-specific configurations for HTTPS communication.
154+
- Grants least privilege permissions to enable secure communication between the API gateway and backend services, ensuring robust security practices.
155+
- Supports versioning and staging of APIs, enabling seamless updates and rollbacks without disrupting existing deployments.
156+
- Abstracts the complexities of cloud-native API gateway services, providing a unified interface for developing and deploying HTTP APIs across different providers.
157+
158+
## 4. Code
159+
160+
**Developers** write application code that uses the [API resource](/apis) from the SDK, defining the APIs routes, methods, middleware and auth.
161+
162+
SDK Reference by language:
163+
164+
- [NodeJS SDK](/reference/nodejs/api/api)
165+
- [Python SDK](/reference/python/api/api)
166+
- [Go SDK](/reference/go/api/api)
167+
- [Dart SDK](/reference/dart/api/api)
168+
169+
**Operations** will use or extend the Nitric infrastructure modules, including both Terraform and Pulumi:
170+
171+
- Terraform Modules:
172+
- [AWS API Terraform Module](https://github.com/nitrictech/nitric/blob/main/cloud/aws/deploytf/.nitric/modules/api/main.tf)
173+
- [GCP API Terraform Module](https://github.com/nitrictech/nitric/blob/main/cloud/gcp/deploytf/.nitric/modules/api/main.tf)
174+
- Pulumi Modules:
175+
- [AWS API Pulumi Module](https://github.com/nitrictech/nitric/blob/main/cloud/aws/deploy/api.go)
176+
- [GCP API Pulumi Module](https://github.com/nitrictech/nitric/blob/main/cloud/gcp/deploy/api.go)
177+
- [Azure API Pulumi Module](https://github.com/nitrictech/nitric/blob/main/cloud/azure/deploy/api.go)

0 commit comments

Comments
 (0)