purple-technology / purple-stack

Serverless monorepo stack powering all Purple Apps πŸ’œπŸš€ and your apps πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Home Page:https://blog.purple-technology.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Purple Stack

9 Landscape Gradient@2x

GitHub top language GitHub last commit GitHub

What is Purple Stack

Purple stack is a development stack designed by Purple LAB for developing full-stack serverless apps.

It's based on our 6+ years of experience with building big Serverless apps on AWS.

You can read more about how Purple Stack was born on our blog.

Tech being used

File structure

.
β”œβ”€β”€ constructs
β”‚   └── # Here go sharable CDK constructs that
β”‚       # you can abstract for multiple services.
β”‚       #
β”‚       # Only individual TS files. No packages.
β”œβ”€β”€ packages
β”‚   └── # Here goes any application code that
β”‚       # you need to share between services.
β”‚       #
β”‚       # Make sure the packages are created
β”‚       # as "npm" packages so that they have
β”‚       # package.json and tsconfig.ts files.
β”œβ”€β”€ services
β”‚   └── # Here goes source code for indivudual
β”‚       # aws services. Inside these folders 
β”‚       # are Lambda handlers and other relevant
β”‚       # source code.
β”‚       #
β”‚       # Make sure the services are created
β”‚       # as "npm" packages so that they have
β”‚       # package.json and tsconfig.ts files.
└── stacks
    └── # Here goes AWS stacks definitions.
        # One folder for each service.
        # Make sure there is always file stack.ts
        # inside each folder.
        #
        # Only individual TS files. No packages.

ENV file

Env file is quite simple in this case. Only AWS_PROFILE is necessary value.

Example

AWS_PROFILE=purple-technology

Setup

There are some settings which need to be changed in order to make this boilerplate project work.

GitHub Actions

.github/workflows/*

  • replace all CHANGE_ME values
  • role-session-name - identifier of the application
  • role-to-assume - usually apps are deployed to "Production" and "Staging" AWS accounts. master branch gets deployed to "Production" and the rest goes to the "Staging" AWS account. Make sure to put there correct deployment roles.
  • How to setup GitHub OpenID Connect on AWS

SST config

sst.config.ts

  • Change app name. Current value: name: 'purple-stack'
  • Change regions. Current value: region: stage === 'master' ? 'eu-central-1' : 'eu-central-1'
  • Eventually enable tracing if you need. Current value: tracing: 'disabled'

Best practices

1. Separate stateful resources to a separate stack

You can use pre-defined ResourceStack for this.

Separate your application into multiple stacks as dictated by deployment requirements

There is no hard and fast rule to how many stacks your application needs. You'll usually end up basing the decision on your deployment patterns. Keep in mind the following guidelines:

  • It's typically more straightforward to keep as many resources in the same stack as possible, so keep them together unless you know you want them separated.

  • Consider keeping stateful resources (like databases) in a separate stack from stateless resources. You can then turn on termination protection on the stateful stack. This way, you can freely destroy or create multiple copies of the stateless stack without risk of data loss.

  • Stateful resources are more sensitive to construct renamingβ€”renaming leads to resource replacement. Therefore, don't nest stateful resources inside constructs that are likely to be moved around or renamed (unless the state can be rebuilt if lost, like a cache). This is another good reason to put stateful resources in their own stack.

Read more here.

2. Don't turn off ESlint and TSconfig rules

The rules are there for a reason. Always make sure to try all possible solutions to comply with the rules before disabling the rule.

Every time you use any in the code a bunny dies.

3. Take advantage of all the features of SST

SST has a lot of great quirks and features like use, bind etc.

Read their docs.

About

Serverless monorepo stack powering all Purple Apps πŸ’œπŸš€ and your apps πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

https://blog.purple-technology.com/

License:MIT License


Languages

Language:TypeScript 89.3%Language:JavaScript 8.2%Language:CSS 2.1%Language:Shell 0.4%