Skip to main content

2. Creating Architecture DAG

Architecture DAG (Directed Acyclic Graph) is an abstract representation of your intended architecture dependency graph. Once you created components and links that represent your architecture DAG there will be no infrastructure provisioned yet. The only thing that will change is the .torque/workspace.yaml file.

Installing packages is a one-time operation that brings desired functionality into the workspace: components, links, and providers that you want to use in creating and evolving your architecture DAG.

In this step, you will install some Torque code packages that contain the definitions for required components and links between components.

Components and links are installed as code that implements certain framework entities. They are abstract types that you can use for constructing an architecture DAG (Directed Acyclic Graph) data structure. You can find more details about these concepts in the Torque Framework Concepts chapter.

Our goal is for you to have an architecture DAG with a load balancer, a backend service, and a PostgreSQL database.

Let's install the required packages. Currently, you have to manually install all packages that you need since the feature to automatically install all dependent packages is still in the works.

Inside my_workspace directory:

torque package install git+https://github.com/torquetech/torque-basics-pack.git && \
torque package install git+https://github.com/torquetech/torque-hlb-component.git && \
torque package install git+https://github.com/torquetech/torque-postgres-component.git && \
torque package install git+https://github.com/torquetech/torque-component-environment.git

torque-basics-pack package contains components and links for handling any kind of containerized application services and links between such services. The only requirement for the application code is to have Dockerfile.

Again, the added components and links serve the purpose of creating an abstract architecture DAG. We did not install any capability to deploy or run the components and links, just the capability to describe an architecture DAG.

You can easily check which packages we have available inside the workspace:

torque package list

Command output:

- torque-basics-pack
- torque-component-environment
- torque-hlb-component
- torque-postgres-component
- torque-workspace

☝️ Note: The package torque-workspace is a special package that contains the Torque Framework and was installed when the workspace was initialized with torque init command.

Creating Components

Components are abstract types that you use to create an architecture DAG data structure. They represent application services, where you write your application code, or platform services, like databases, queues, and similar.

Now that you have installed packages, let's explore what components are available.

torque component list-types

Command output:

- torque.basics.V1HttpService
- torque.basics.V1TCPService
- torque.basics.V1Task
- torque.hlb.V1Component
- torque.postgres.V1Component

You are ready to create components in your DAG. Each component is a node in a DAG that Torque generates based on your design.

torque component create backend-service torque.basics.V1HttpService \
-p path=backend-service \
-p port=80 \
--no-suffix && \
torque component create lb torque.hlb.V1Component \
--no-suffix && \
torque component create db torque.postgres.V1Component \
--no-suffix

You have created components for a backend service, load balancer, and a PostgreSQL database. The load balancer is necessary if you want to have your services publicly accessible.

These three components are now three nodes in your DAG.

Running these commands created isolated nodes in the architecture DAG. Now you need to create links between them. Here is what we got inside the .torque/workspace.yaml:

components:
backend-service:
type: torque.basics.V1HttpService
parameters:
path: backend-service
port: '80'
build:
command:
- docker
- build
- -t
- $IMAGE
- .
run: {}
labels: []
lb:
type: torque.hlb.V1Component
parameters: {}
labels: []
db:
type: torque.postgres.V1Component
parameters: {}
labels: []

Linking Components

Links are also abstract types like components, and are used to create edges that connect nodes in the architecture DAG you are building. Links serve the purpose of active propagation of configuration variables from one component to another.

Here's how to link the database to the backend service:

torque link create db backend-service \
--type torque.postgres.V1EnvironmentLink \
-p database=example \
-p user=test_user

torque link create command tells Torque Framework what instance exposes its services and to where. In the example, framework creates a link between the db instance and the backend-service instance. The additional --type argument tells the framework to use the torque.basics.V1PostgresLink link as an intermediary. Links take care of transferring any environment variables and other required information between instances.

To reach these services from the internet, you need to connect them to a load balancer. In this case, you'll use the torque.basics.V1IngressLink link:

torque link create backend-service lb \
--type torque.basics.V1IngressLink \
-p path=/backend-service \
-p host=api

These links instruct the load balancer how to configure the routing table, to define how requests from which URLs or paths should be forwarded to which service.

We can peek into the .torque/workspace.yaml to see how the links are represented in the DAG:

links:
link-6vfn:
type: torque.postgres.V1EnvironmentLink
source: db
destination: backend-service
parameters:
database: example
user: test_user
labels: []
link-vvvi:
type: torque.basics.V1IngressLink
source: backend-service
destination: lb
parameters:
path: /backend-service
host: api
labels: []

You created the entire architecture DAG. To do anything with it you'll need to create a deployment object, but before that, we need an application code that will actually run the backend service.