This repository was archived by the owner on May 20, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
docs: refresh the nitric intro page #620
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
145158f
doc(homepage): new home/introduction page
jyecusch da0893c
add missing labels
jyecusch ae593bc
Apply suggestions from code review
jyecusch 064b04c
Auto stash before checking out "origin/docs/new-layout"
jyecusch c46632c
Add local dev and extension sections
jyecusch 08edead
draft ifc concepts page
jyecusch 217dce4
intro page edits and link fixes
jyecusch 2b45bb0
format
davemooreuws b88b714
update hr styles
jyecusch a8491bd
fix links with redirects
jyecusch bfea125
review feedback applied
jyecusch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
export const description = | ||
'Introducing the concept of Infrastructure from Code (IfC) and how Nitric uses it to automate infrastructure and deployment.' | ||
|
||
# Infrastructure from Code (IfC) | ||
|
||
Infrastructure from Code (IfC) is an extension of Infrastructure as Code (IaC) that takes runtime application code into consideration and enhances Separation of Concerns (SoC). | ||
|
||
<Note> | ||
Several products describe themselves as "Infrastructure from Code" (IfC), but | ||
they're not all like Nitric. Many are platforms/SaaS products, not a | ||
framework. Those products have different benefits and trade-offs. | ||
</Note> | ||
|
||
Nitric's Infrastructure from Code (IfC) automates the creation of infrastructure from your application code, ensuring a clear separation between application logic and deployment concerns. | ||
|
||
It abstracts the infrastructure layer, allowing developers to define what their application needs without getting bogged down in the specifics of cloud services or infrastructure configurations. | ||
|
||
Sometimes it's easier to explain IfC by exploring the benefits. | ||
|
||
--- | ||
|
||
## Rapid Development | ||
|
||
Nitric significantly reduces or removes cloud-specific code. For example, accessing a file in a cloud storage bucket with nitric is just a few lines of code, while the equivalent code using cloud provider SDKs is much more verbose and error prone: | ||
|
||
<CodeGroup> | ||
|
||
```javascript {{ title:"Nitric SDK" }} | ||
import { bucket } from '@nitric/sdk' | ||
|
||
const profiles = bucket('profiles').allow('read') | ||
|
||
export const getProfilePic = async (filename) => { | ||
return await profiles.file(filename).read() | ||
}) | ||
``` | ||
|
||
```javascript {{ title:"AWS SDK" }} | ||
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3' | ||
|
||
const client = new S3Client({}) | ||
const PROFILES_BUCKET = process.env.PROFILES_BUCKET | ||
|
||
if (!bucket) { | ||
throw new Error('PROFILES_BUCKET environment variable not set') | ||
} | ||
|
||
export const getProfilePic = async (filename) => { | ||
const command = new GetObjectCommand({ | ||
Bucket: PROFILES_BUCKET, | ||
Key: filename, | ||
}) | ||
|
||
const response = await client.send(command) | ||
return await response.Body.transformToByteArray() | ||
} | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
--- | ||
|
||
## Decoupled Applications and Infrastructure | ||
|
||
Nitric keeps application code independent of specific cloud services. Developers focus on designing the application architecture and building features, without first making long-term technology choices. | ||
|
||
For example this same code would work equally well backed by AWS SNS, AWS EventBridge, Google Cloud Pub/Sub, Azure EventGrid, Apache Kafka, or any other messaging service: | ||
|
||
```javascript | ||
import { topic } from '@nitric/sdk' | ||
|
||
const myTopic = topic('my-topic').allow('publish') | ||
|
||
export const publishMessage = async (message) => { | ||
await myTopic.publish(message) | ||
} | ||
``` | ||
|
||
We can change the underlying messaging service through a simple configuration change, without modifying the application code. | ||
|
||
<CodeGroup> | ||
|
||
```yaml {{ label:"nitric.prod.yaml", title:"AWS" }} | ||
provider: nitric/[email protected] | ||
``` | ||
|
||
```yaml {{ label:"nitric.prod.yaml", title:"Azure" }} | ||
provider: nitric/[email protected] | ||
``` | ||
|
||
```yaml {{ label:"nitric.prod.yaml", title:"Google Cloud" }} | ||
provider: nitric/[email protected] | ||
``` | ||
|
||
```yaml {{ label:"nitric.prod.yaml", title:"Anything Else" }} | ||
provider: your_namespace/[email protected] | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
<Note> | ||
The runtime code for cloud services like SNS still exists, it's just isolated | ||
to an independent module. It could be from a [nitric | ||
jyecusch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
provider](https://github.com/nitrictech/nitric/blob/main/cloud/aws/runtime/topic/sns.go) | ||
or [something custom](/reference/providers/custom/building-custom-provider) | ||
built by you or an independent team, such as platform engineers or DevOps | ||
teams. | ||
</Note> | ||
|
||
--- | ||
|
||
## Automate Application Infrastructure Requirements | ||
|
||
Using Infrastructure as Code (IaC) tools like Terraform, Pulumi, or AWS CDK, developers can define the infrastructure requirements for their application. You can even create reusable modules for common infrastructure patterns. For example, you could create a pattern for async messaging, which includes a topic, and a subscription bound to a compute function. | ||
|
||
The problem is that these tools in isolation require manual processes to keep the infrastructure in sync with the application code. Processes that are error-prone and time-consuming. | ||
|
||
Infrastructure lingers in production that's no longer in use, permissions are too broad creating security risks, or too strict causing application failures. Environment variables used to determine resource names can be can be broken by a simple typo. It's a mess. | ||
|
||
Nitric solves this by automatically generating a requirements specification from the application code. This specification describes the resources used by the application, their hierarchy, and how the application intends to use them at runtime. | ||
|
||
If you want to see the spec for your application you can run `nitric spec`: | ||
|
||
```bash | ||
nitric spec | ||
``` | ||
|
||
### No Rogue Resources or Permissions | ||
|
||
Resources and access requirements are defined as close as possible to where they're used - so it's easy to see when they're no longer needed or permissions are too broad. | ||
|
||
```javascript | ||
import { queue } from '@nitric/sdk' | ||
|
||
// Delete this line and the queue disappears from the IaC | ||
const myQueue = queue('my-queue').allow('enqueue') | ||
|
||
// It's easy to tell when `enqueue` is no longer needed | ||
export const enqueueMessage = async (message) => { | ||
await myQueue.enqueue(message) | ||
} | ||
``` | ||
|
||
### No Broken Environment Variables | ||
|
||
The name of a resource is defined **_once_** (in the code), instead of twice (in the code and the IaC). IaC configuration is generated, so it's never out of sync with the application code. | ||
|
||
```javascript | ||
sql('profiles') | ||
``` | ||
|
||
and the framework maps the requirements specification to plugins written with existing IaC tools. These tools are still responsible for provisioning the resources, roles, and permissions. | ||
|
||
### Don't Change App Code for Infrastructure Changes | ||
|
||
You haven't imported the AWS SDK, Google Cloud SDK, or Azure SDK. You haven't written any cloud-specific code. You haven't written any mocks or tests for these cloud services, or anything that makes your code less portable. | ||
|
||
So when changes are needed for performance, cost, or compliance, you can make them instantly. It's just a line of config. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.