Torpedo

Hexagonal Entity Builder, just FIRE IT!

Why should I use Torpedo?

Torpedo offers a streamlined approach to coding by eliminating redundant tasks and reducing boilerplate code. By using Torpedo, you can significantly boost your productivity, allowing you to dedicate more time and energy to developing the core functionality of your application.

What We Offer

Features

What We Offer

Architecture

Torpedo is a clean, decouple, testable and flexible code generator following hexagonal architecture principle.

Multi stack

Defines your own stack:
REST API or GraphQL or both!
Memory storage or Redis or SQL or MongoDB... or cache strategy!

Self Documentation

Entity documentation is generated automatically based on the yaml spec.

Entity spec

Defines entities specs using yaml file and generate the boiler plate code from these.

Improve your time, avoid the boiler plate!




Entity Data Model Spec

Define your entities based on a yaml spec file and generate voiler plate code from it.


version: "torpedo.darksub.io/v1.0"
kind: entity
entity:
name: "post"
plural: "posts"
description: "The blog post entity"
doc: ".torpedo/entities/docs/post.md" # custom md to extends basic doc.                             

Updates the spec when you need a change and rewrite your code faster with minimal impact.


schema:
  reserved:
    id:
      type: ulid

  fields:
    - name: title
      type: string
      description: "The post title"
      doc: "The post title"

    - name: pubDate
      type: date
      description: "The publication date"
      doc: "The publication date"                           

Defines relationshipts between entities


relationships:
  - name: comments
    type: $rel
    ref: ".torpedo/entities/comment.yaml"
    cardinality: hasMany

  - name: authors
    ref: ".torpedo/entities/author.yaml"
    cardinality: hasMany

Handle input adapters like Http Rest or output adapters like SQL, MongoDB, Redis or Memory


adapters:
  input:
    - type: http

  output:
    - type: sql
      metadata:
        table: "posts"                                 

Use Cases first

Based on the Hexagonal Architecture Torpedo lets developer be focused on the Business Logic.

Isolating the use case code base, unit tests, mocks, 3rd party integrations and more as part of the project structure is a really powerfull way to handle your entities code away from your business logic

Check out the Documentation

usecase

Output Adapters: Storages

Torpedo provides integration out of the box with the most poppular databases.

Entities can be saved into:

  • SQL (MySQL, PostgreSQL, etc.)
  • MongoDB
  • Redis
  • Memory (usefull for testing)

Additionally, provides a two flavours composition storage using Redis as cache layer to improve your reads

  • Redis + SQL
  • Redis + MongoDB

Configuration module

Configuration is not a problem for you anymore with the Torpedo config module.

Integrates out of the box with:

  • Yaml files
  • Azure App Config
  • Azure Key Vault
  • Environment variables interpolation

Application Context - Dependency Injection

The application module provides a full Application life-cycle handler with a context.

This application context handles all depedencies that you need pass throw services, modules, entities, etc.

Implements an easy programatic interface to provide your own depedencies.

Logger provider:


package inject

import "github.com/darksubmarine/torpedo-lib-go/app"

const LOGGER = "LOGGER"

type LoggerProvider struct {
  app.BaseProvider
  level string

}

func NewLoggerProvider(lvl string) *LoggerProvider {
  return &LoggerProvider{level: lvl}
}

func (lp *LoggerProvider) Provide(lf app.IContainer) (interface{}, error) {
  return slog.New(slog.NewJSONHandler(os.Stdout,
                  &slog.HandlerOptions{Level: lp.level})), nil
}                               
                                        

Creates the application and register the logger dependency:


package inject

import "github.com/darksubmarine/torpedo-lib-go/app"

func NewAppContainer() app.IApp {
	return app.
          NewContainer().
          WithNamedProvider(LOGGER, NewLoggerProvider("info"))

}                               
                                          

Torpedo Query Language (TQL)

Because Torpedo let you switch from one database to another one, we have introduced a DSL query language to avoid code migration.

TQL defines a JSON based query language with next capabilities:

  • Filtering
  • Sorting
  • Projection
  • Pagination
For further info see the documentation


curl \
--location 'http://service:8081/api/v1/post/query' \
--header 'Content-Type: application/json' \
--data '{
    "filter": {
        "type":"all",
        "fields": [
            {
                "field": "authorId",
                "operator": "==",
                "value": "fe8e51a3-f897-4a3a-8b2b-87abdeb8d0d5"
            }
        ]
    }
    ,"projection":["id", "body","created","updated"]
}'
                                          
                                                                                  

Download your Torpedo flavour!