Giter VIP home page Giter VIP logo

serverless-template's Introduction

serverless-template

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 Stack

The power of a provider agnostic framework to manage deployment and infrastructure.

Worked providers

  • AWS
  • Azure
  • Google Cloud

Node (javascript & typescript)

Project focused on the javascript environment, with specialized tooling for development and optimization




Structure

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




Development environment

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 root package.json
  • Commitlint: Lint commit messages, creating a standard. Applied on commit-msg hook script and config located at root package.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 root package.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




Development environment

serverless plugins & vscode debugger

docker containers -> development & local services(localstack?)

configs


General Folders Structure and Project Configuration

.
├── .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
└── ...

Package/Project Specific Structure and Configurations


serverless-template's People

Contributors

esteveslima avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.