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.
- Main language: TypeScript
- Deployment framework: SST.dev
- Frontend: React.js & Next.js
- Code bundling: ESbuild
- Package manager: PNPM
- Linting: ESlint & Prettier
- API protocol: tRPC
- Business workflows engine: AWS Step Functions
- CI/CD: GitHub Actions
- Static Application Security Testing (SAST) -
eslint-plugin-security
& @microsoft/eslint-plugin-sdl - Unit Tests - Vitest
- Structured Logging: AWS Lambda Powertools Logger
- Conventional Commits - Commitlint
- ... and more
.
βββ 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 is quite simple in this case. Only AWS_PROFILE
is necessary value.
AWS_PROFILE=purple-technology
There are some settings which need to be changed in order to make this boilerplate project work.
.github/workflows/*
- replace all
CHANGE_ME
values role-session-name
- identifier of the applicationrole-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.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'
You can use pre-defined ResourceStack
for this.
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.
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.
SST has a lot of great quirks and features like use
, bind
etc.
Read their docs.