├── .gitignore
├── README.md
├── frontend
├── .env
├── .gitignore
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
└── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ ├── reportWebVitals.js
│ └── setupTests.js
├── lerna.json
├── lib
├── Service1Stack.js
├── Service2Stack.js
├── WebsiteStack.js
└── index.js
├── package.json
├── src
├── packages
│ └── sample-package
│ │ ├── index.js
│ │ └── package.json
├── services
│ ├── service1
│ │ ├── handler.js
│ │ └── package.json
│ └── service2
│ │ ├── handler.js
│ │ └── package.json
└── util
│ └── index.js
├── sst.json
├── test
└── MyStack.test.ts
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 |
15 | # sst build output
16 | .build
17 |
18 | npm-debug.log*
19 | yarn-debug.log*
20 | yarn-error.log*
21 |
22 | # vim
23 | .*.sw*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SST Lerna + Yarn Workspaces Starter [](https://console.seed.run/serverless-stack/lerna-yarn-starter)
2 |
3 | A [Serverless Stack Framework (SST)](https://github.com/serverless-stack/serverless-stack) monorepo starter that uses [Lerna](https://lerna.js.org) and [Yarn Workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).
4 |
5 | - A full-stack serverless app
6 | - Designed to scale for larger teams
7 | - Maintains internal dependencies as packages
8 | - Supports publishing dependencies as private NPM packages
9 | - Uses Yarn Workspaces to hoist packages to the root `node_modules/` directory
10 |
11 | -----
12 |
13 | ## Installation
14 |
15 | Start by cloning this repo
16 |
17 | ``` bash
18 | $ git clone https://github.com/serverless-stack/lerna-yarn-starter my-project
19 | ```
20 |
21 | Enter the new directory
22 |
23 | ``` bash
24 | $ cd my-project
25 | ```
26 |
27 | Install npm packages for the entire project
28 |
29 | ``` bash
30 | $ yarn
31 | ```
32 |
33 | ## How It Works
34 |
35 | The directory structure roughly looks like:
36 |
37 | ```
38 | package.json
39 | /lib
40 | /frontend
41 | package.json
42 | /src
43 | /services
44 | /service1
45 | handler.js
46 | package.json
47 | /service2
48 | handler.js
49 | package.json
50 | /packages
51 | /sample-package
52 | index.js
53 | package.json
54 | /util
55 | ```
56 |
57 | This repo is split into a few parts. Each with a different purpose:
58 |
59 | - `lib/`
60 |
61 | This is where the CDK code for your app lives. It defines the infrastructure of your serverless app.
62 |
63 | - `src/`
64 |
65 | This is where the code for your Lambda function are. It is further organized into services. Where each service is a collection of Lambda functions.
66 |
67 | - `src/services/`
68 |
69 | These are services that are deployed as Lambda functions. Has a `package.json` and an entry point. There are two sample services.
70 |
71 | 1. `service1`: Depends on the `sample-package`.
72 | 2. `service2`: Does not depend on any internal packages.
73 |
74 | - `src/packages/`
75 |
76 | These are internal packages that are used in our services. Each contains a `package.json` and can be optionally published to npm.
77 |
78 | - `src/util/`
79 |
80 | Any common code that you might not want to maintain as a package. Does NOT have a `package.json`.
81 |
82 | - `frontend/`
83 |
84 | A sample frontend React app that is a part of our serverless app.
85 |
86 | The `src/packages/`, `src/services/`, and `frontend/` directories are Yarn Workspaces.
87 |
88 | ### Services
89 |
90 | Each service is a collection of Lambda functions with a similar purpose. They are meant to be managed on their own. They each have their own `package.json` and the versions of the dependencies should be kept separate from the other services. SST internally uses [esbuild](https://github.com/evanw/esbuild) to optimally package each Lambda function in a service.
91 |
92 | This is good for keeping your Lambda packages small. But Yarn Workspaces also ensures that it hoists all your npm packages to the project root.
93 |
94 | ### Packages
95 |
96 | Since each package has its own `package.json`, you can manage it just like you would any other npm package.
97 |
98 | To add a new package:
99 |
100 | ``` bash
101 | $ mkdir src/packages/new-package
102 | $ yarn init
103 | ```
104 |
105 | Packages can also be optionally published to npm.
106 |
107 | To use a package:
108 |
109 | ```bash
110 | $ yarn add new-package@1.0.0
111 | ```
112 |
113 | Note that packages should be added by specifying the version number declared in their `package.json`. Otherwise, Yarn tries to find the dependency in the registry.
114 |
115 | ### Util
116 |
117 | If you need to add any other common code in your repo that won't be maintained as a package, add it to the util directory. It does not contain a `package.json`. This means that you'll need to install any npm packages as dependencies in the root.
118 |
119 | To install an npm package at the root.
120 |
121 | ``` bash
122 | $ yarn add -W some-npm-package
123 | ```
124 |
125 | While it's convenient to add all the common code to the util, it has a downside. If a team updates the util, all the services that are dependent on it will need to test this change before deploying. In contrast, a package can be locked to a specific version and can be upgraded when the team chooses to.
126 |
127 | ## Deployment
128 |
129 | SST will handle all the dependencies internally and deploy all the services (and the frontend) in order.
130 |
131 | ## Deploying Through Seed
132 |
133 | [Seed](https://seed.run) supports deploying SST monorepo projects that use Lerna and Yarn Workspaces out of the box.
134 |
135 | -------
136 |
137 | This repo is maintained by [Serverless Stack](https://serverless-stack.com/).
138 |
--------------------------------------------------------------------------------
/frontend/.env:
--------------------------------------------------------------------------------
1 | SKIP_PREFLIGHT_CHECK=true
2 |
--------------------------------------------------------------------------------
/frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `yarn start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13 |
14 | The page will reload if you make edits.\
15 | You will also see any lint errors in the console.
16 |
17 | ### `yarn test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `yarn build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `yarn eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35 |
36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39 |
40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `yarn build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.11.4",
7 | "@testing-library/react": "^11.1.0",
8 | "@testing-library/user-event": "^12.1.10",
9 | "react": "^17.0.2",
10 | "react-dom": "^17.0.2",
11 | "react-scripts": "4.0.3",
12 | "web-vitals": "^1.0.1"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test",
18 | "eject": "react-scripts eject"
19 | },
20 | "eslintConfig": {
21 | "extends": [
22 | "react-app",
23 | "react-app/jest"
24 | ]
25 | },
26 | "browserslist": {
27 | "production": [
28 | ">0.2%",
29 | "not dead",
30 | "not op_mini all"
31 | ],
32 | "development": [
33 | "last 1 chrome version",
34 | "last 1 firefox version",
35 | "last 1 safari version"
36 | ]
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/frontend/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sst/lerna-yarn-starter/ac012a6c728a270b6d685bfe160a62028e460b80/frontend/public/favicon.ico
--------------------------------------------------------------------------------
/frontend/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |