generated from jetbridge/sst-prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5e35cc
Showing
132 changed files
with
27,916 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
PRISMA_CONNECTION_LIMIT=5 | ||
|
||
# set this to enable a bastion EC2 host you can tunnel through to connect to the database | ||
# create a keypair in your desired account and region and add the name here | ||
# SSH_KEYPAIR_NAME= |
This file contains 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 @@ | ||
IS_PRODUCTION=true |
This file contains 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,30 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:import/recommended', | ||
'plugin:import/typescript', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint', 'import'], | ||
settings: { | ||
'import/parsers': { | ||
'@typescript-eslint/parser': ['.ts', '.tsx'], | ||
}, | ||
'import/resolver': { | ||
node: {}, | ||
typescript: {}, | ||
}, | ||
}, | ||
ignorePatterns: ['.build', 'dist', 'cdk.out'], | ||
rules: { 'comma-dangle': ['error', 'only-multiline'] }, | ||
}; |
This file contains 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,51 @@ | ||
name: Test | ||
|
||
on: push | ||
|
||
jobs: | ||
build-and-test: | ||
env: | ||
DATABASE_URL: 'postgresql://prisma:prisma@localhost/tests' | ||
NODE_OPTIONS: '--max-old-space-size=4096' | ||
|
||
services: | ||
postgres: | ||
image: postgres:12 | ||
env: | ||
POSTGRES_USER: prisma | ||
POSTGRES_PASSWORD: prisma | ||
POSTGRES_DB: tests | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 1s | ||
--health-timeout 1s | ||
--health-retries 60 | ||
ports: | ||
- 5432:5432 | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# Build | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 7 | ||
- name: Install Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
cache: pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
- name: Build backend | ||
run: pnpm build:ci | ||
- name: Lint | ||
run: pnpm lint | ||
- name: Tests | ||
run: pnpm test:ci | ||
- name: Build web | ||
run: pnpm build:web |
This file contains 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,30 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
|
||
# sst build output | ||
.build | ||
.sst | ||
|
||
# environments | ||
.env*.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
!jest.config.js | ||
|
||
# TSC build output | ||
/dist | ||
|
This file contains 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,13 @@ | ||
dist | ||
.build | ||
.next | ||
packages/*/output | ||
node_modules | ||
.idea | ||
.DS_Store | ||
*.map | ||
tsconfig.tsbuildinfo | ||
packages/infra/cdk.out/ | ||
packages/infra/.aws*/* | ||
.sst/* | ||
pnpm-lock.yaml |
This file contains 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,5 @@ | ||
tabWidth: 2 | ||
semi: true | ||
printWidth: 120 | ||
trailingComma: es5 | ||
singleQuote: true |
This file contains 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 JetBridge Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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,106 @@ | ||
# Serverless Stack + Prisma - Starter Kit | ||
|
||
## What is this? | ||
|
||
If you want to build a serverless app with AWS CDK, Lambda, and Postgres, this is the template for you. | ||
|
||
You can click "Use this template" button in GitHub to fork this repo. You can [merge](https://stackoverflow.com/a/69563752) in improvements in this repo to your project over time. | ||
|
||
Clone your copy of this template, then do a search and replace for "myapp" to give it a name. | ||
|
||
## Quickstart | ||
|
||
### Prerequisites | ||
|
||
Assumes you have [Node 16](https://nodejs.org/en/download/current/) installed and AWS credentials [configured](https://serverless-stack.com/chapters/configure-the-aws-cli.html). | ||
|
||
### Setup | ||
|
||
```shell | ||
npm i -g pnpm # install pnpm globally | ||
pnpm i # install dependencies + generate types from DB and GQL schemas | ||
pnpm start # start backend | ||
``` | ||
|
||
## Features | ||
|
||
All features are optional, delete what you don't need. | ||
|
||
Click links to learn more and view documentation. | ||
|
||
- 🌩 [Serverless Stack](https://serverless-stack.com/) - powerful CDK developer experience tools | ||
- 🌤 [AWS CDK](https://aws.amazon.com/cdk/) - cloud-native infrastructure as code | ||
- ፨ [GraphQL API](https://docs.serverless-stack.com/constructs/GraphQLApi) | ||
- ⇅ [AWS AppSync](https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html) - serverless GraphQL AWS service | ||
- ✽ [Code generation](https://www.graphql-code-generator.com/) of [TypeScript](https://www.graphql-code-generator.com/docs/guides/front-end-typescript-only) + [apollo client](https://www.graphql-code-generator.com/plugins/typescript-react-apollo) | ||
- 🌐 [REST API gateway](https://docs.serverless-stack.com/api) | ||
- 🖥 [NextJS](https://nextjs.org/) frontend w/ Material-UI | ||
- 🎨 [Material-UI](https://mui.com/material-ui/getting-started/overview/) - react components and styling solution | ||
- 🔓 [NextAuth.js](https://next-auth.js.org/) - authentication and session management | ||
- 🔓 [AWS Cognito](https://aws.amazon.com/cognito/) - authentication backend | ||
- 💾 [Prisma ORM](https://www.prisma.io/docs/) | ||
- 📚 Prisma engine lambda layer | ||
- 📜 Prisma DB migration CDK script | ||
- 🐳 Database integration test setup with postgres in docker | ||
- 🔋 [Aurora Serverless RDS](https://aws.amazon.com/rds/aurora/serverless/) PostgreSQL | ||
- ⚡️ [Live local lambda development](https://docs.serverless-stack.com/live-lambda-development) (`pnpm start`) | ||
- 🐞 [Lambda debugging](https://docs.sst.dev/live-lambda-development#debugging-with-visual-studio-code) - set breakpoints on your lambda functions and step through in your IDE | ||
- 📦 [pnpm](https://pnpm.io/) - fast and correct package manager | ||
- 🚅 [vitest](https://vitest.dev/) - fast tests | ||
- 🐛 [ES Modules](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) | ||
- 🔧 [ESBuild](https://esbuild.github.io/) - fast code bundling on backend (under the hood) with tree-shaking | ||
- 🫙 [Middy](https://middy.js.org/) - middleware for Lambda functions | ||
- 🛠 [AWS Lambda Powertools](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/) - for [custom metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/), [structured logging](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/), and [tracing](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/). | ||
|
||
## Package scripts | ||
|
||
Please see [package.json](package.json) `scripts` for more. | ||
|
||
### Start live backend dev server with AWS | ||
|
||
```shell | ||
pnpm start | ||
``` | ||
|
||
### Start Nextjs frontend dev server | ||
|
||
```shell | ||
pnpm start:web | ||
``` | ||
|
||
### Start backend and frontend together | ||
|
||
```shell | ||
pnpm fullstack | ||
``` | ||
|
||
### Run/generate DB migrations locally | ||
|
||
```shell | ||
pnpm db:migrate:dev | ||
``` | ||
|
||
### Just watch and perform type-checking | ||
|
||
```shell | ||
pnpm watch | ||
``` | ||
|
||
### Deploy to your AWS environment | ||
|
||
```shell | ||
pnpm deploy | ||
``` | ||
|
||
### Deploy to specific AWS environment (region/profile) | ||
|
||
```shell | ||
pnpm deploy --region eu-west-1 --profile dev | ||
``` | ||
|
||
### All SST/CDK commands | ||
|
||
```shell | ||
pnpm exec sst | ||
pnpm exec cdk | ||
``` |
This file contains 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,2 @@ | ||
# local dev (docker-compose) | ||
DATABASE_URL="postgresql://postgres:pass@localhost:5438/myapp" |
This file contains 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,2 @@ | ||
# local dev (docker-compose) | ||
DATABASE_URL="postgresql://postgres:pass@localhost:5438/tests" |
This file contains 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,2 @@ | ||
/dist/ | ||
node_modules/ |
This file contains 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,63 @@ | ||
{ | ||
"name": "backend", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"lint": "eslint --ext .js,.ts,.tsx src", | ||
"start": " dotenv -e .env.sst.start sst start", | ||
"format": "prisma format", | ||
"migrate": "pnpm run migrate:dev", | ||
"migrate:dev": "pnpm run format && prisma migrate dev", | ||
"migrate:test": "pnpm init:db:test && dotenv -e .env.vitest -- prisma migrate dev --skip-seed --skip-generate", | ||
"init:db:test": "[ -n \"$CI\" ] || (docker-compose exec -T sst-local-db dropdb -U postgres --if-exists tests && docker-compose exec -T sst-local-db createdb -U postgres tests)", | ||
"db:seed": "prisma db seed", | ||
"db:seed:clean": "CLEAN_SEED=true prisma db seed", | ||
"generate": "prisma generate" | ||
}, | ||
"prisma": { | ||
"seed": "./seed-db.sh" | ||
}, | ||
"dependencies": { | ||
"@aws-crypto/client-node": "^3.1.1", | ||
"@aws-lambda-powertools/logger": "^0.8.1", | ||
"@aws-lambda-powertools/metrics": "^0.9.1", | ||
"@aws-lambda-powertools/tracer": "^0.9.1", | ||
"@aws-sdk/client-kms": "~3.145.0", | ||
"@aws-sdk/client-secrets-manager": "~3.145.0", | ||
"@aws-sdk/signature-v4-crt": "^3.130.0", | ||
"@middy/core": "^2.5.7", | ||
"@prisma/client": "4.2.1", | ||
"@prisma/internals": "4.2.1", | ||
"@prisma/migrate": "4.2.1", | ||
"@sentry/serverless": "^7.8.1", | ||
"aws-lambda": "^1.0.7", | ||
"base64url": "^3.0.1", | ||
"common": "workspace:*", | ||
"got": "^12.3.1", | ||
"jose": "^4.8.3", | ||
"memoizee": "^0.4.15" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": ">=7.0.0 <8.0.0", | ||
"@chax-at/transactional-prisma-testing": "^0.5.0", | ||
"@faker-js/faker": "^7.5.0", | ||
"@prisma/generator-helper": "*", | ||
"@types/aws-lambda": "^8.10.70", | ||
"@types/memoizee": "^0.4.7", | ||
"@types/uuid": "^8.3.4", | ||
"aws-sdk-client-mock": "^1.0.0", | ||
"builtin-modules": "3.2.0", | ||
"dotenv": "^16.0.0", | ||
"dotenv-cli": "^5.1.0", | ||
"fishery": "^2.2.2", | ||
"graphql": "^16.5.0", | ||
"graphql-tag": "^2.12.6", | ||
"prisma": "4.2.1", | ||
"uuid": "^9.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.16", | ||
"npm": ">=7.0.0" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/prisma/migrations/20220818222951_init/migration.sql
This file contains 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,27 @@ | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "client" ( | ||
"id" UUID NOT NULL DEFAULT uuid_generate_v4(), | ||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "client_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "user" ( | ||
"id" UUID NOT NULL DEFAULT uuid_generate_v4(), | ||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"username" TEXT NOT NULL, | ||
"name" TEXT, | ||
"email" TEXT, | ||
"avatar_url" TEXT, | ||
|
||
CONSTRAINT "user_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "user_email_key" ON "user"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "user_username_key" ON "user"("username"); |
This file contains 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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
Oops, something went wrong.