Skip to content

Gary-Ascuy/aws-turboless-architecture-template

Repository files navigation

Turboless Architecture Template 🎭

The software architecture of a project is a critical component that determines the scalability, maintainability, and extensibility of the system. A well-designed architecture is essential for managing the complexity of modern software systems, especially for projects with complex business logic. This template provides guidance for designing a robust and scalable software architecture for such projects. "Generated by ChatGPT"

based on https://github.com/antoinewg/turboless

Tags

  • Serverless (NodeJS)
  • DynamoDB
  • Turborepo
  • Esbuild
  • Dependency Injection

Software Dependencies

Get Started

Install Dependencies

# Install package manager

$ npm install -g pnpm
# Install Dependencies

$ pnpm install

Start Application

# Start local dependencies (DynamoDB)

$ docker-compose up
# Start Service

$ pnpm dev

Test Local Api

# Create User (POST)
$ curl -d '{"id":"@garyascuy", "name":"Gary Ascuy"}' \
    -H "Content-Type: application/json" \
    -X POST \
    http://localhost:3666/dev/users

# Get All Users
$ curl http://localhost:3666/dev/users

Add Resources (CRUD) - Tooling

# Creates a new resource called documents

$ cd services/api-v1/
$ pnpm resource:add -- --name documents

Folder Structure

- packages
  - core-functions        # Core Functions Lib
    - src/middleware
    - src/request
    - src/response
  - eslint-config-custom  # Eslint Config
  - tsconfig              # TypeScript Base Configs
  - ...                   # Add here custom packages

- services                # Applications
  - api-v1                # Test Api v1
    - .tools              # Internal Tools/Generator Templates
    - src
      - config            # ConfigService/Inversion of Control Config
      - core              # Base/Helpers for Data/Service/Controller layer
        - controller.layer
        - data.layer
        - service.layer
      - functions         # Functions Implementation
        - users           # Users resource (it contains CRUD for users)
        - documents
        - ...             # Other resources
    - package.json        # Package Config
    - plopfile.js         # Code Generation Config
    - serverless.yml      # Serverless Config
  - api-v2
  - ...                   # Add here other Apis

Functions

- users (function/folder)
  - dto
    - create.dto.schema.ts
    - update.dto.schema.ts
  - entities
    - user.entity.ts
  - api.configuration.ts
  - controller.ts
  - users.repository.ts
  - users.service.ts
  - users.yml

when:

  • dto contains all data transfer objects, also these models are used to configure and validate data in function.
  • entities contains data models
  • api.configuration.ts define limits on Api, data.layer/base.repository.ts allows some kind of queries and it define limits like filters, allow fields for projection, etc.
  • controller.ts define handlers for CRUD, Note: if you want to reduce the size of bundle you can split into files (file by function). this layer only resolve all related with transport like http.
  • users.repository.ts data access layer, it has basic set of operation to work with table/collection, you can add more custom operation according to your requirements but try to keep those generics.
  • users.service.ts business logic layer, it contains all the validations and high level operations, make sure to have all the system logic here.
  • users.yml serverless functions configuration.

TODO

  • Implement projection/pagination/filtering support in base.repository

References