odedia / examples

Examples that demonstrate how to use Nile as a control plane for infrastructure SaaS

Home Page:https://www.thenile.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nile

Table of Contents

What is Nile

Developing a SaaS product can have a lot of complexity in lifecycle management and codifying best practices. These SaaS architectures have to address really hard problems, including:

Nile provides a tenant-aware, serverless database that is used to build SaaS control planes and solves a lot of these problems out of the box. Think about all the problems above, and how they all lie just under the surface of a SaaS webapp front-end. Check out https://demo-db-saas.thenile.dev (login as one of the predefined users), which is a mocked example of a SaaS that we built on top of Nile to demonstrate the ease with which you can deliver a SaaS infrastructure service (follow the webapp playbook for details).

control plane nile

This collection of examples demonstrates how to use Nile in a variety of ways. The examples can also be run sequentially to build on top of one another, in which case, we recommend running them in the order presented here to build up your SaaS as you go. Or jump to the webapp to run an end-to-end example for multi-tenancy, event handling, a metrics API, and a front-end for self-service provisioning.

Community

  1. Join the Slack community for SaaS developers who are learning from and sharing with each other advice on how to build spectacular services in the cloud.

  2. Subscribe to the SaaS Developer Community Youtube channel to hear experts in the field talk about how they solve SaaS problems.

  3. Learn more about the SaaS space from the Nile blog.

  4. If you have any questions, go to the Nile website and reach out to us!

Getting started

To get started:

  1. Setup your Nile workspace and environment
  2. Run the Quickstart to configure a minimal control plane in Nile.

You can then follow on with any of the other examples for different use cases.

Setup

Nile workspace and developer credentials

  • ✅ Log into Nile Admin Dashboard

    Navigate your web browser of choice to the Nile Admin Dashboard and click Continue with Google to login via SSO. (Don't want SSO? Go to the Nile website, enter your email address, and click Talk to us, then someone from Nile will contact you to setup up an email and password for you)

  • ✅ Create a Nile workspace

    If you don't already have a Nile workspace, create it now. From the dashboard, click Create a workspace, and in the textbox enter the name of a new workspace. This represents your control plane where your SaaS application lives.

  • ✅ Get your workspace access token

    From the dashboard, get your workspace access token. This token enables you to programmatically run the examples in this repo.

Your local environment

  • ✅ Clone the GitHub repository

    From a terminal window, clone the theniledev/examples repo and change into the new directory.

    git clone git@github.com:TheNileDev/examples.git
    cd examples
  • ✅ Create a local .env file

    To run any example, you need a local .env file with your Nile configuration. At the top-level of the examples, copy the .env.defaults file to a new file .env, and then edit the values in the .env file to match what you created in the dashboard. In particular, set the values of your Nile workspace and credentials to match what you have in the Nile Admin Dashboard.

    cp .env.defaults .env     # edit file (set NILE_WORKSPACE, and {NILE_WORKSPACE_ACCESS_TOKEN} or {NILE_DEVELOPER_EMAIL and NILE_DEVELOPER_PASSWORD})
  • ✅ Verify Node version (Javascript examples only)

    For the Javascript examples, validate your environment has the minimum required Node version v18.0.0 or higher. If you are running earlier versions, you may encounter errors such as ReferenceError: fetch is not defined. (If you use nvm, run nvm use).

Quickstart

Start with the quickstart to configure a base Nile control plane. This provides a simple setup to learn the concepts but also serves as the foundation for the other examples below.

quickstart

Examples by Feature

Multi-tenancy

Tenants have access to specific organizations that have isolated sets of resources. Users are allowed to access only the entity instances in the organizations to which they have been added.

  • Multi-tenancy | JS SDK | Setup the Nile control plane with multiple tenants and users

multi-tenancy

Data Plane

These examples show how to synchronize, e.g. reconcile, your data plane and control plane in real time with Nile events. As instances are created or destroyed from the control plane, the example reconciler creates or destroys data plane deployments. Even if you're using another deployment tool like Kubernetes or Terraform, similar principles apply as they do for Pulumi.

data-plane

Authorization

Attribute-based access control (ABAC) is an authorization model that gives you fine-grained authorization capabilities. You can configure these in the control plane so that they are aligned to your business's security policies.

validate permissions

Metrics

Nile provides a metrics API and matching UI components. This allows you to add real-time data features to your application, for example, each end user of your SaaS can see their real-time resource consumption and the cost incurred to date. Read more on the importance of metrics and consumption-based billing in the blog post Launching an Infrastructure SaaS Product, An Example Walkthrough.

metrics

Webapp

Launch a front-end web application that is customizable on a per-tenant basis. The webapp includes Nile React components for metrics.

  • Webapp | JS SDK | Builds a self-service frontend that integrates with Nile on the backend

image

Other

Here are additional examples that you can refer to.

  • Python + Flask Todo List Webapp | Python REST | Take a basic Todo List webapp written in Python and Flask and turn it to a PLG SaaS product with Nile APIs

Examples by Language

Note: the languages and examples shown are an indication just of which examples have been developed, not of what's available. Please see the Nile API and SDK documentation for details.

javascript Javascript

These examples use the nile-js SDK.

python Python

These examples use the nile-py SDK.

Advanced

Change Entity Type

The default scenario in these examples is a company that provides a database as SaaS. But you can modify the NILE_ENTITY_NAME parameter in your .env file (see Setup) to change it to be any other type of service offering, one of:

Run in Gitpod (Experimental)

Try out the examples in Gitpod.

Known limitation: webapp won't work

Testing

The examples are validated via GitHub Actions, a flexible CI/CD tool that executes the examples against Nile. For more details, view this repo's workflow.

GitHub Actions workflow

About

Examples that demonstrate how to use Nile as a control plane for infrastructure SaaS

https://www.thenile.dev

License:MIT License


Languages

Language:TypeScript 68.5%Language:Python 18.5%Language:JavaScript 7.2%Language:EJS 3.0%Language:HTML 1.4%Language:CSS 0.7%Language:Dockerfile 0.7%Language:Shell 0.0%Language:Batchfile 0.0%