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.

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.hlb.V1Component: <class 'torque.hlb.V1Component'>
torque.postgres.V1Component: <class 'torque.postgres.V1Component'>
torque.basics.V1Task: <class 'torque.basics.V1Task'>
torque.basics.V1TCPService: <class 'torque.basics.V1TCPService'>
torque.basics.V1HttpService: <class 'torque.basics.V1HttpService'>

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

torque component create backend_srv torque.basics.V1HttpService -p path=backend_srv -p port=80 && \
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_srv.5lf:
    type: torque.basics.V1HttpService
    parameters:
      path: backend_srv
      port: '80'
      build:
        command:
        - docker
        - build
        - -t
        - $IMAGE
        - .
      run: {}
      environment: {}
  lb:
    type: torque.hlb.V1Component
    parameters: {}
  db:
    type: torque.postgres.V1Component
    parameters: {}

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_srv \
  --type torque.basics.V1PostgresLink \
  -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_srv 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_srv lb \
  --type torque.basics.V1IngressLink \
  -p path=/backend_srv \
  -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.mjg:
    type: torque.basics.V1PostgresLink
    source: db
    destination: backend_srv.5lf
    parameters:
      database: example
      user: test_user
  link.861:
    type: torque.basics.V1IngressLink
    source: backend_srv.5lf
    destination: lb
    parameters:
      path: /backend_srv
      host: api

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.