# Organizing Serverless Projects

**URL:** <https://discourse.sst.dev/t/organizing-serverless-projects/350>\
**Category:** Chapter Comments\
**Created:** [July 20, 2018, 11:00pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350 "2018-07-20T23:00:03Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [July 20, 2018, 11:00pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/1 "2018-07-20T23:00:03Z")

</div>

Link to chapter - [https://serverless-stack.com/chapters/organizing-serverless-projects.html](https://serverless-stack.com/chapters/organizing-serverless-projects.html)

---

<div class="post-metadata">

**Author:** ![khrome83](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/khrome83/32/199_2.png) [@khrome83](https://discourse.sst.dev/u/khrome83)\
**Post date:** [August 2, 2018, 11:07am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/2 "2018-08-02T11:07:02Z")

</div>

Great chapter. I could really use examples of a monorepo.

What are best practices if mulitiple services use the same dynamodo or Cognito setup.

How do you deploy multiple services with the same domain? Example - [api.example.com](http://api.example.com)?

I feel a chapter on this would be amazing. People are using monorepos but there are not examples outside of claiming you put severless.yml in different folders.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 3, 2018, 6:17pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/3 "2018-08-03T18:17:51Z")

</div>

Thats a great point. Thanks for feedback. I’m going to write a couple of chapters on these very shortly. But here is the general idea:

- Referencing shared resources across multiple services: [Cross-Stack references](http://www.1strategy.com/blog/2017/03/14/using-cloudformation-cross-stack-references/)
- Multiple services with the same domain: [Shared API Gateway resources](https://serverless.com/framework/docs/providers/aws/events/apigateway/#share-api-gateway-and-api-resources)

---

<div class="post-metadata">

**Author:** ![khrome83](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/khrome83/32/199_2.png) [@khrome83](https://discourse.sst.dev/u/khrome83)\
**Post date:** [August 4, 2018, 1:17am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/4 "2018-08-04T01:17:27Z")

</div>

Thank you so much @jayair this is a good start. Look forward to seeing the chapters. This guide has been indispensable and one of the best technology books/tutorials I have seen in my long career doing web development.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 8, 2018, 5:14pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/5 "2018-08-08T17:14:26Z")

</div>

Thank you! I’m glad you’ve found it helpful!

---

<div class="post-metadata">

**Author:** ![HHK1](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/hhk1/32/482_2.png) [@HHK1](https://discourse.sst.dev/u/HHK1)\
**Post date:** [May 15, 2019, 11:44am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/6 "2019-05-15T11:44:53Z")

</div>

> The `package.json` (and the `node_modules/` dir) are at the root of the repo. However, it is fairly common to have a separate `package.json` inside each service directory.

I think it would be interesting to expand on that a bit. [The example provided](https://github.com/AnomalyInnovations/serverless-stack-demo-mono-api/tree/master/services) is great but does not illustrate how to handle dependencies, and shared code between services which is a fairly common issue

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 27, 2019, 12:16am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/7 "2019-05-27T00:16:23Z")

</div>

That’s a good point. We’ve gotten a couple of requests for this in past. We’ll be updating this with a more detailed example.

---

<div class="post-metadata">

**Author:** ![lucapirrone](https://avatars.discourse-cdn.com/v4/letter/l/6de8d8/32.png) [@lucapirrone](https://discourse.sst.dev/u/lucapirrone)\
**Post date:** [August 4, 2019, 12:14am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/8 "2019-08-04T00:14:59Z")

</div>

How did you tackle the problem? By deploying every single service on aws, the common node\_modules dir is not loaded

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 4, 2019, 12:56am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/9 "2019-08-04T00:56:42Z")

</div>

If anybody is looking for an example of how to handle your `package.json` in a monorepo app, we wrote about it here:

> **[How to structure a real-world monorepo Serverless app](https://seed.run/blog/how-to-structure-a-real-world-monorepo-serverless-app)**
>
> In this post we look at how to organize monorepo Serverless Framework apps in detail. We’ll also look at how to share common code and config and how to structure the serverless.yml file.

I’ll add a link to this in the chapter.

---

<div class="post-metadata">

**Author:** ![taqtical](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@taqtical](https://discourse.sst.dev/u/taqtical)\
**Post date:** [March 20, 2020, 2:21am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/10 "2020-03-20T02:21:36Z")

</div>

Hi. I managed to successfully follow your worderful tutorial with the proposed structure of the two repositories (resources and api). Now I am trying to replicate the structure in a project of my own and a little more complex. My project handles four Dynamo tables. The functions of each table may or may not require the user to be authenticated. On the other hand, there are functions that must be restricted for some particular users, which I do not know if the best way is to manage it though Cognito groups or roles. It is also unclear to me whether it is convenient for the four tables to share the same serverless.yml or rather to keep them independent. But really the most complex thing for me has been understanding how to handle the permissions of the functions for authenticated and unauthenticated users. I’m stuck there.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [March 30, 2020, 11:00pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/11 "2020-03-30T23:00:48Z")

</div>

Well to start with you can create public APIs for your functions that don’t need auth. Remove the `authorizer` option from your `serverless.yml`:

> <https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/serverless.yml#L60>

---

<div class="post-metadata">

**Author:** ![SethThomas](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/seththomas/32/850_2.png) [@SethThomas](https://discourse.sst.dev/u/SethThomas)\
**Post date:** [May 15, 2020, 10:46pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/12 "2020-05-15T22:46:35Z")

</div>

I’ve been following along with the tutorial from the beginning. I’m going through the process of breaking apart concerns into multiple serverless projects, but this chapter appears to make some steps that are not discussed in the tutorial. For example, earlier in the tutorial, we created a handler-lib.js that wraps each lambda function and provided simple error handling. The [serverless stack demo ext API](https://github.com/AnomalyInnovations/serverless-stack-demo-ext-api) repo appears to have gotten rid of this abstraction and included a few others (e.g. [response-lib](https://github.com/AnomalyInnovations/serverless-stack-demo-ext-api/blob/master/libs/response-lib.js)).

Maybe I missed it, but were these changes covered in the tutorial? I like to understand the motivations for code refactors, and this particular change was not discussed.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 17, 2020, 6:39pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/13 "2020-05-17T18:39:38Z")

</div>

It’s the other way around. We added these details to the main guide recently. For the extension we don’t want to overload the concepts so we are keeping the app relatively simple.

---

<div class="post-metadata">

**Author:** ![SethThomas](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/seththomas/32/850_2.png) [@SethThomas](https://discourse.sst.dev/u/SethThomas)\
**Post date:** [May 18, 2020, 3:50pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/14 "2020-05-18T15:50:05Z")

</div>

Understood, that makes sense. There’s a lot of ground to cover in making a tutorial like this.

For example, I’m setting up SNS events in my serverless app. I have been using the [Serverless Stack Demo EXT API](https://github.com/AnomalyInnovations/serverless-stack-demo-ext-api/) as a reference, namely how the Billing service produces SNS messages and the Notify service consumes SNS messages. These examples have been very useful!

The [Organizing Serverless Projects](https://serverless-stack.com/chapters/organizing-serverless-projects.html#an-example) chapter refers to these services, but doesn’t go into detail about how they were created and the decisions made along the way. This was the first time I saw them references in the Serverless Stack demo, and it left me wondering if I skipped or otherwise overlooked that discussion in the guide.

Thanks again for this resource, it’s been tremendously helpful.

---

<div class="post-metadata">

**Author:** ![willjstevens](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/willjstevens/32/487_2.png) [@willjstevens](https://discourse.sst.dev/u/willjstevens)\
**Post date:** [October 28, 2020, 6:40pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/15 "2020-10-28T18:40:43Z")

</div>

Good news to the CloudFormation resource limit [error posted here](https://serverless-stack.com/chapters/organizing-serverless-projects.html#multi-repo)!

```auto
Error --------------------------------------------------

The CloudFormation template is invalid: Template format error: Number of resources, 201, is greater than maximum allowed, 200

```

AWS just announced service limit increases for CF stack resources **up to 500**!!! (up from 200)

> **[AWS CloudFormation now supports increased limits on five service quotas](https://aws.amazon.com/about-aws/whats-new/2020/10/aws-cloudformation-now-supports-increased-limits-on-five-service-quotas/)**

You will need to open a service limit increase support case in your AWS account to do this.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [November 13, 2020, 3:15am UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/16 "2020-11-13T03:15:04Z")

</div>

Yeah that is great news! Let me add a note to the chapter.

---

<div class="post-metadata">

**Author:** ![cheekw](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/cheekw/32/1032_2.png) [@cheekw](https://discourse.sst.dev/u/cheekw)\
**Post date:** [November 21, 2020, 4:11pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/17 "2020-11-21T16:11:03Z")

</div>

Thanks for the amazinng guide. I was wondering how you’re able to access the common “libs/” directory in all the services of the monorepo cause the serverless api that is being deployed exists within “services/notes-api/”

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [November 22, 2020, 7:38pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/18 "2020-11-22T19:38:01Z")

</div>

In our case we use [https://github.com/AnomalyInnovations/serverless-bundle](https://github.com/AnomalyInnovations/serverless-bundle) to Webpack the common code into the bundle. So we aren’t directly copying over these files.

---

<div class="post-metadata">

**Author:** ![jpmaff](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jpmaff](https://discourse.sst.dev/u/jpmaff)\
**Post date:** [July 14, 2022, 4:30pm UTC](https://discourse.sst.dev/t/organizing-serverless-projects/350/19 "2022-07-14T16:30:33Z")

</div>

This is a beneficial guide! I’m building a react native app and wonder how to organize that project best while using serverless. In the demo app for the sst guide, we place our react web app within a front-end folder within the _same_ repo. This is also how the guide for the expo app structures its repo. I wonder if it makes sense to start out this way and eventually split the serverless backend into its own dedicated repo. I know there must be pros and cons to both approaches but I’d appreciate any suggestions!
