# How to Structure Serverless Framework Applications?

**URL:** <https://forum.serverless.com/t/how-to-structure-serverless-framework-applications/19842>\
**Category:** Serverless Architectures\
**Tags:** aws, lambda\
**Created:** [December 31, 2023, 9:35am UTC](https://forum.serverless.com/t/how-to-structure-serverless-framework-applications/19842 "2023-12-31T09:35:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ujjwal](https://avatars.discourse-cdn.com/v4/letter/u/e0b2c6/32.png) [@ujjwal](https://forum.serverless.com/u/ujjwal)\
**Post date:** [December 31, 2023, 9:35am UTC](https://forum.serverless.com/t/how-to-structure-serverless-framework-applications/19842/1 "2023-12-31T09:35:19Z")

</div>

So, I’m new to serveless and have been trying to create a serverless backend for my project and scratching my head over the best way to organize things. Initially, I thought of laying it out like this:

```auto
|--src
| |--auth-service
| |--products
| |--customers
|--package.json
|--serverless.yml

```

However, I quickly realized an issue – the `node_modules` folder. For instance, the auth section requires the `bcrypt` package, whereas the customers section does not. Deploying the same node\_modules folder to every function includes unnecessary packages.  
So, I came up with a different game plan:

```auto
|--customers
| |--node_modules
| |--handler.js
| |--package.json
| |--serverless.yml
|--products
| |--node_modules
| |--handler.js
| |--package.json
| |--serverless.yml
|--auth-service
| |--node_modules
| |--handler.js
| |--package.json
| |--serverless.yml

```

Here, the node\_modules folder is not global but is _scoped_ to contain only the packages required by each function.

> With this setup, I have to deploy by running `serverless deploy` within each folder.

- **Question 1)**  
A challenge remains – how do I configure “auth-service” (which has a function checking JWT) as an authorizer for the “customers” and “products” functions within their respective serverless.yml files? My initial thought was to use the ARN for the auth function and set it as the authorizer for all other functions, but I am not sure if this is a good approach

- **Question 2)**  
Is there a better way to structure the project, especially since now deploying resourcing is a pain, for example if I want a dynamodb table, I should’nt be defining it as a resouce inside a particual functions serverless.yml file, right? So is there a way to kind to bundle all these different services, and maybe define resources in centralized place.

---

<div class="post-metadata">

**Author:** ![beenmeckel](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@beenmeckel](https://forum.serverless.com/u/beenmeckel)\
**Post date:** [December 5, 2024, 11:58am UTC](https://forum.serverless.com/t/how-to-structure-serverless-framework-applications/19842/3 "2024-12-05T11:58:04Z")

</div>

My first idea was having an own Lambda project for each of the endpoints I plan to have. I wanted to create all the resources within one stack with cdk [Kodi](https://kodi.software/)
