title: AWS Serverless Framework Mono-Repo Structure Best Practices
body: <p>I'm working on a fairly large AWS serverless project, and I'm not all that familiar with the process so I have a more basic question on how to properly structure the application. </p>
  
  <p>The main AWS services being used are Lambda, Dynamo, S3, Cognito, and IoT.
  There are native iOS and Android apps along with an Angular dashboard and Google Home + Alexa. They all use the native SDKs to authenticate through Cognito, but use Lambda endpoints for all other cloud communication. </p>
  
  <p>There are Lambda endpoints that are exclusive to the <strong>mobile apps</strong>.
  There are Lambda endpoints that are exclusive to the <strong>voice assistants</strong>.
  There are Lambda endpoints that are exclusive to the <strong>angular dashboard</strong>.
  There are Lambda endpoints that are <strong>internal use only</strong>.</p>
  
  <p>I separated my project into <em>modules</em>. I have a module specifically (for example) <code>Locations</code>.
  I have another module specifically for <code>Users</code>.</p>
  
  <p>Each module contains all resources (more-or-less) exclusive to itself. (There are some cross-module dependencies). Here's an example of my workspace:</p>
  
  <pre><code>|- app/
  |--- auth/
  |----- package.json
  |----- serverless.yml
  |--- device/
  |----- package.json
  |----- serverless.yml
  |--- user/
  |----- package.json
  |----- serverless.yml
  |--- voice/
  |----- package.json
  |----- serverless.yml
  |- lib/
  |- package.json
  </code></pre>
  
  <p><strong>A couple of things to notice here:</strong></p>
  
  <ul>
  <li>The <code>app/</code> directory at the root is made up of a collection of
  services. Where a service contains a single <code>serverless.yml</code> file.</li>
  <li>Each service deals with a relatively small and self-contained
  function. These may be broken up even further, depending on the
  CloudFormation stack size. (initially was having a big problem with this!)</li>
  <li>The <code>lib/</code> directory contains any common code that might be used across
  all services.</li>
  <li>In this case, you deploy each module individually</li>
  </ul>
  
  <p>Okay, so this is all well and good but now we are starting to think about environments.
  Environments (or stages) need to be coordinated across all the different services. From what I've read, you simply create duplicate resources (lambda functions, s3 buckets, dynamo tables, etc) for each environment with the <code>stage</code> defined in the name. </p>
  
  <p><em>Example: <code>{service}-{module}-{stage}-{endpoint}</code>, where <code>service</code> is your application name, <code>module</code> is which core service you're working with , <code>stage</code> is your environment (dev, stage, prod), and <code>endpoint</code> would be the name of your lambda function.</em></p>
  
  <p>Is this correct to assume? If so, how does one structure that in their workspace? And I also want to separate each Lambda function into their roles (app, dashboard, voice, etc). This will also make setting up Policies easier. This is where I'm looking for advice/best practices. What is a good workspace/folder structure for this type of application?</p>
  
  <p>Thanks!</p>