This repository provides(or intend to) working templates with a set of examples for a serverless project, seeking for best practices and tools for a agile development environment and optimized structure for production.
TODO: reference to files in each topic
The power of a provider agnostic framework to manage deployment and infrastructure.
Worked providers
- AWS
AzureGoogle Cloud
Node (javascript & typescript)
Project focused on the javascript environment, with specialized tooling for development and optimization
Monorepo approach to ease sharing code and configuration across project's packages, speeding up development, standardizing code and improving team's collaboration.
Packager/Manager feature for multplie packages, automatically creating links and hoisting all dependencies to a single folder in root's directory.
EVERY CHANGE IN A PACKAGE.JSON FILE REQUIRES TO RUN 'npm install' IN THE MONOREPO ROOT DIRECTORY(serverless may require leaf projects to still run npm install)
A Tool for managing multiple packages. Althought Lerna itself is enough for setting up a monorepo and all it's commands are available for use, in this project it is intended to be used for releases versioning and possible CI purposes.
TODO: study and test CI applications and strategies using lerna version and lerna changed
Streamlined git with hooks
A strict way to version code, organizing the complex multipackage project history. Tools applied to the entire project, used for this purpose:
- Husky: Interceptor for git hooks, injecting custom scripts per stage. Scripts located at
/resources/scripts/.husky/
- Commitzen: Prompt a CLI for commits, making the process easier and ensuring the main format. Activated on
prepare-commit-msg
hook script and config located at rootpackage.json
- Commitlint: Lint commit messages, creating a standard. Applied on
commit-msg
hook script and config located at rootpackage.json
- Lint-staged: Run given commands(E.g.: linting & unit tests) filtering only for staged files, allowing to ignore the remaining untouched packages. Activated on
pre-commit
hook script and config located at rootpackage.json
Docker as development environment
Lightweight container for local development, with AWS-CLI and additional tools for enhanced experience. Check the Dockerfile
Providers configuration are done automatically using volumes, otherwise would be necessary to make the configuration in the host machine. Config files at /resources/config/
Use docker's npm scripts from root package.json
or from Makefile
to set up containers and start terminal shell.
Docker compose service containers
Set of containers providing access to services for local development. Check the docker-compose.yml
file
.
├── .vscode > Configurations for VS Code(recommended IDE)
├── node_modules > Hoisted node_modules folder, centralizing npm packages for the monorepo
├── packages
│ ├── services > Packages group containing real applications, making use of configurations and functionalities from the common packages
│ │ ├── ~template > Base template for javascript projects, may be used as boilerplate for new projects
│ │ ├── ~template-ts > Base template for typescript projects, may be used as boilerplate for new projects
│ │ ├── api-examples > Project containing examples of common API features and configurations
│ │ ├── event-examples > Project containing examples of event triggered functions
│ │ ├── storage-examples > Project containing examples of interactions with data storage services
| | └── ...
│ ├── shared > Packages group with the intent to contain customized common functionalities, improving general development experience
│ │ ├── utils
│ │ │ └── src
| | └── ...
│ └── sls > Packages group containing base common functionalities for configuring Serverless Framework, Projects and Js/Ts Code
│ ├── configurations > Package for common project/code configurations, which can be easly imported and incremented/modified with js
│ ├── definitions > Package for common definitions, encapsulating functionalities concerning Serverless Framework configurations
│ │ ├── plugins > Defining all plugins' configurations and functionalities for easly importing them in projects
│ │ ├── provider > Defining base configurations for cloud providers
│ │ ├── utils > Extra functions to ease Serverless Framework configurations with js
| | └── ...
│ └── lib > Package as common library, encapsulating useful code functionalities for development experience and external services
│ ├── dist > Because it is a local project, must be transpiled on every modification
│ └── src
├── resources > Folder containing configurations and assets concerning all projects or repository
| └── ...
├── docker-compose.yml > Docker environment configuration, which is used to setup the development environment with it's aditional services
├── Dockerfile > Serverless container environment configuration, dispensing the installation of any service on host machine besides docker
├── lerna.json > Simple configuration for lerna to enable it's usage
├── Makefile > File containing common commands to setup the development environment
├── package.json > Base npm config file for common configuration such as workspaces, hooks, base scripts and installing base development packages
└── ...