core

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

README

diagramastext backend logic

codecov

The codebase orchestrates transformations of the user's inquiry.

Design

C4 Containers

TBD

References

  • zopfi: The library used to compress and encode the C4 Diagram definition as code as the string request content to generate diagram using PlantUML server.
  • The encoding logic

DNS

Cloudflair is used as DNS. Follow the steps to set it up:

  1. Select us-east-1 as the region
  2. Go to AWS Certificate Manager
  3. Request a certificate
  4. Set CNAME records in Cloudflair to validate ownership
  5. Configure the API GW Custom domain:
resource "aws_api_gateway_domain_name" "this" {
  domain_name     = "api.diagramastext.dev"
  certificate_arn = "arn:aws:acm:us-east-1:xxxxxxxxxxxxx"
}

resource "aws_api_gateway_base_path_mapping" "this" {
  api_id      = aws_api_gateway_rest_api.this.id
  stage_name  = aws_api_gateway_stage.this["production"].stage_name
  domain_name = aws_api_gateway_domain_name.this.domain_name
}
output "gw_domain_name" {
  value       = aws_api_gateway_domain_name.this.cloudfront_domain_name
  description = "API GW domain name required to configure custom DNS, e.g. Cloudflaire"
}
  1. Use output gw_domain_name to configure CNAME record in Cloudflaire. See the illustration below.

dns

Note that the proxy status shall be set to "DNS only".

Acknowledgements

Documentation

Overview

package defines diagram as code using the graph input

Index

Constants

View Source
const (
	ServiceOpenAI  = "OpenAI"
	ServiePlantUML = "PlantUML"
	ServiceStorage = "Storage"
)
View Source
const (
	StageInit            = "init"
	StageRequest         = "request"
	StageResponse        = "response"
	StageSerialization   = "serialization"
	StageDeserialization = "deserialization"
)

Variables

This section is empty.

Functions

func WithHTTPClientOpenAI

func WithHTTPClientOpenAI(c HttpClient) func(o *clientOpenAI)

WithHTTPClientOpenAI overwrite the OpenAI HTTP client.

func WithHTTPClientPlantUML

func WithHTTPClientPlantUML(c HttpClient) func(*optionsPlantUMLClient)

WithHTTPClientPlantUML overwrite the PlantUML HTTP client.

func WithSinkFn

func WithSinkFn(sinkFn func(string)) func(o *clientOpenAI)

WithSinkFn sets sink function to record model's input and output.

Types

type CallID added in v0.0.2

type CallID struct {
	RequestID string
	UserID    string
}

type ClientGraphToDiagram

type ClientGraphToDiagram interface {
	Do(context.Context, DiagramGraph) (ResponseDiagram, error)
}

ClientGraphToDiagram client to convert DiagramGraph to diagram artifact, e.g. svg image.

func NewPlantUMLClient

func NewPlantUMLClient(optFns ...func(*optionsPlantUMLClient)) ClientGraphToDiagram

NewPlantUMLClient initiates the clientPlantUML to communicate with the plantuml server.

type ClientInputToGraph

type ClientInputToGraph interface {
	Do(context.Context, string) (DiagramGraph, error)
}

ClientInputToGraph client to convert user input inquiry to the DiagramGraph.

func NewOpenAIClient

func NewOpenAIClient(cfg ConfigOpenAI, optFns ...func(client *clientOpenAI)) (ClientInputToGraph, error)

NewOpenAIClient initiates the client to communicate with the plantuml server.

type ClientStorage added in v0.0.2

type ClientStorage interface {
	// WritePrompt writes user's input prompt.
	WritePrompt(ctx context.Context, v UserInput) error

	// WriteModelPrediction writes model's prediction result used to generate diagram.
	WriteModelPrediction(ctx context.Context, v ModelOutput) error

	// Close closes the connection.
	Close(ctx context.Context) error
}

ClientStorage defines the client to communicate to the storage to persist core logic transactions.

type DiagramGraph

type DiagramGraph struct {
	Title  string  `json:"title,omitempty"`
	Footer string  `json:"footer,omitempty"`
	Nodes  []*Node `json:"nodes"`
	Links  []*Link `json:"links,omitempty"`
}

DiagramGraph defines the diagram graph.

type Error

type Error struct {
	Service                   string
	Stage                     string
	Message                   string
	ServiceResponseStatusCode int
}

Error defines the core logic error to facilitate errors handling across the product elements.

func (Error) Error

func (e Error) Error() string

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

HttpClient http base client.

type Link struct {
	From       string `json:"from"`
	To         string `json:"to"`
	Direction  string `json:"direction,omitempty"`
	Label      string `json:"label,omitempty"`
	Technology string `json:"technology,omitempty"`
}

Link diagram's definition link.

type MockClientStorage added in v0.0.2

type MockClientStorage struct {
	Err error
}

func (MockClientStorage) Close added in v0.0.2

func (m MockClientStorage) Close(ctx context.Context) error

func (MockClientStorage) WriteModelPrediction added in v0.0.2

func (m MockClientStorage) WriteModelPrediction(ctx context.Context, v ModelOutput) error

func (MockClientStorage) WritePrompt added in v0.0.2

func (m MockClientStorage) WritePrompt(ctx context.Context, v UserInput) error

type ModelOutput added in v0.0.2

type ModelOutput struct {
	CallID
	Response  string
	Timestamp time.Time
}

ModelOutput type defining the model's output.

type Node

type Node struct {
	ID         string `json:"id"`
	Label      string `json:"label,omitempty"`
	Group      string `json:"group,omitempty"`
	Technology string `json:"technology,omitempty"`
	External   bool   `json:"external,omitempty"`
	IsQueue    bool   `json:"is_queue,omitempty"`
	IsDatabase bool   `json:"is_database,omitempty"`
}

Node diagram's definition node.

type ResponseC4Diagram

type ResponseC4Diagram struct {
	SVG string `json:"svg"`
}

ResponseC4Diagram resulting C4 diagram.

func (ResponseC4Diagram) MustMarshal

func (r ResponseC4Diagram) MustMarshal() []byte

type ResponseDiagram

type ResponseDiagram interface {
	// MustMarshal serialises the result as JSON.
	MustMarshal() []byte
}

ResponseDiagram response object.

type UserInput added in v0.0.2

type UserInput struct {
	CallID
	Prompt    string
	Timestamp time.Time
}

UserInput type defining the user's input.

Directories

Path Synopsis
cmd
Package handler defines the client-server communication entrypoint handler.
Package handler defines the client-server communication entrypoint handler.
storage module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL