Nitric Documentation
Build cloud backends that run anywhere, fast.
Nitric is a cloud framework with common resources like APIs, websockets, databases, queues, topics, buckets, and more.
However, Nitric is unique - it doesn't just deploy the resources, it helps you interact with them. It also makes them pluggable, so you can swap services or even whole clouds without changing your code.
It's what's missing between applications and infrastructure automation.
Oh, and it supports basically any language, like JavaScript, TypeScript, Python, Go, you name it.
Services
Services are the heart of Nitric apps, they're the entrypoints to your code. They can serve as APIs, websockets, schedule handlers, subscribers and a lot more. You create services by telling Nitric where to look for your code and how to run it.
name: example
services:
- match: services/*.ts
start: npm run dev:services $SERVICE_PATH
You might have one service that handles everything, or a service for each route. It's up to you.
Resources
Resources are the building blocks of your apps. They're the databases, queues, buckets, etc. that your services interact with. If you want a resource, you just ask for it.
import { bucket } from '@nitric/sdk'
const profiles = bucket('profiles').allow('read', 'write', 'delete')
Nitric collects everything your services request. When you deploy, the deployment plugin you choose creates the resources and services, then links it all together.
That probably sounds like magic, but it's more like a compiler for Infrastructure-as-Code - you can read about it in the Concepts section.
Providers
Nitric is designed to be independent of any platform, so you can run your apps anywhere. You can deploy to AWS, Azure, GCP, or even your own Kubernetes cluster. You can even deploy to multiple clouds at once.
Seriously, is there really a difference between a bucket on AWS and a bucket on Azure? We don't think so. So why should the code be different?
Nitric abstracts away the differences, so you can focus on your app. The part that makes that possible is a plugin, we call a Provider.
provider: nitric/aws@1.1.1
region: us-east-1
We have a few providers built-in with IaC from Pulumi or Terraform, but you can build your own with any tools you prefer and to anywhere you want.
Projects
Projects built with Nitric don't have many restrictions. You can use most languages, most libraries, most tools, most clouds, most services, mostly anything you like. But, you need to have a nitric.yaml
file in the root of your project.
name: example
services:
- match: services/*.ts
start: npm run dev:services $SERVICE_PATH
Nitric uses this to find your services, then it turns each service into a container, runs them in deployment mode to match the resources you requested and gives the result to the Provider - which either generates IaC (like Terraform) or automatically deploys your app.
So, a project structure might look something like this:
example/
โโโ nitric.yaml
โโโ services/
โ โโโ orders.ts
โ โโโ users.ts
โโโ package.json
CLI
Nitric has a CLI to help you create, manage, run and deploy your projects. We recommend installing it with a package manager:
brew install nitrictech/tap/nitric
New
You can create a new project from a template with the new
command.
nitric new
Start
You can run your project locally with the start
command.
nitric start
Start also emulates the resources you requested, so you can test your app locally. And provides a Dashboard UI to interact with the resources.
Deploy
You can deploy your project with the up
command, once you have a stack file (deployment target).
nitric stack new
nitric up
Some providers don't deploy directly, instead they generate IaC files. In those cases you use the IaC tool to deploy (e.g. terraform apply
).
Tear Down
You can tear down your project with the down
command.
nitric down
Local development
Sometimes you just want to run your app locally and we let you do just that. And we don't mean "binds to a cloud environment and syncs your code, but doesn't work without Wifi" local, we mean "runs on your machine, on a desert island" local.
nitric start
hosts entrypoints like APIs, websockets, and schedules, as well as resources like databases, topics, queues, key/value stores and buckets.
It also provides a Dashboard to interact with your resources, so you can trigger schedules without waiting, or topics without a publisher, or upload test files to a bucket. It even produces a real-time architecture diagram of your services and resources.
Extension & Escape Hatches
The services of cloud providers are vast, we can't cover everything and we shouldn't. Many services are unique enough that abstraction would be a disservice. Nitric aims to make common "table stakes" services easy to use, but we never want to limit you.
Runtime
If you need to access a service in a way Nitric doesn't support, you can always use the provider's SDK directly. Code like this will always work:
import { S3Client } from '@aws-sdk/client-s3'
const s3 = new S3Client({ region: 'us-east-1' })
const { Contents } = await s3.listObjectsV2({ Bucket: 'my-bucket' })
Overriding
If you need to change how Nitric deploys a resources or how it interacts with a service at runtime, you can extend or modify a provider.
For example, here's a project that swaps SNS for EventBridge on AWS.
Full Customization
If you need to deploy to a cloud or new set of services that Nitric doesn't support, you can build your own provider. This is a bit more advanced, but it's the ultimate escape hatch.
The included providers are written in Go and built using Terraform or Pulumi, but you can use any language or tool you like.
Additional Resources
If you need to use a service that Nitric doesn't support, you just do that like you always would. Nitric doesn't get in the way of you using the cloud, it just makes it easier.
What now?
If you're still not sure what to make of Nitric, maybe start with the Concepts section, otherwise the best way to learn is to dive into the Guides and start building your first project.