Describing your domain

Concepts, intents and relationships

Semantic types give meaning to single values, like a FirstName or an OrderId. Models describe the data structures that real systems return.

Taxi has three more declarations for describing your domain at a higher level:

DeclarationWhat it namesExample
conceptA kind of thing, described by the values it hasA Person has a FirstName and a LastName
intentAn action, described by what goes in and what comes outPurchase takes a product request and returns a confirmation
relationshipA named link from one kind of thing to anotherA Person worksFor a LegalEntity

A fourth keyword, satisfies, connects your models and operations to them.

​
A quick example

type PersonId inherits String
type FirstName inherits String
type LastName inherits String
type LegalEntityId inherits String
type LegalEntityName inherits String
type HireDate inherits Date

// The things in the domain
concept Person      { PersonId, FirstName, LastName }
concept LegalEntity { LegalEntityId, LegalEntityName }

// How they connect
relationship worksFor: Person -> LegalEntity?

// An action
write intent Hire(Person, LegalEntityId, HireDate): PersonId

// One system's data, declared against the concepts
model HrEmployer satisfies LegalEntity {
   id: LegalEntityId
   name: LegalEntityName
}

model HrEmployee satisfies Person, worksFor {
   id: PersonId
   first: FirstName
   last: LastName
   employer: HrEmployer?
}

parameter model NewHire {
   personId: PersonId
   first: FirstName
   last: LastName
   employerId: LegalEntityId
   startDate: HireDate
}

service HrApi {
   operation employee(PersonId): HrEmployee
   write operation hire(NewHire): PersonId satisfies Hire
}

Here’s what each part does:

  • concept Person says that a person has a PersonId, a FirstName and a LastName. It doesn’t say how that data is laid out.
  • model HrEmployee satisfies Person says that the HR system’s employee record is a Person. The compiler checks that it has the values Person needs.
  • relationship worksFor names the link from a person to their employer. HrEmployee declares that it holds that link, in its employer field.
  • write intent Hire names the action of hiring someone. HrApi::hire declares that it performs it, and the compiler checks that its inputs and output fit.

​
Why use them?

Models describe the shape of one system’s data. Different systems describe the same thing in different shapes. A person might be a nested JSON object in one API, and a flat CSV row in another.

Concepts, intents and relationships let you describe your domain once, then declare how each system fits it. The compiler checks each declaration, so mismatches are caught when you compile, not when you run a query.

In queries, you can then ask for things by what they mean. Using the schema above:

find { Person } as {
   name: FirstName
   employer: LegalEntityName? = worksFor::LegalEntityName
}

This query doesn’t name a system, a model or a field path. The compiler works out where worksFor is held.

For readers who know OWL

If you've used OWL or other ontology languages: a concept is close to a class, and a relationship is close to an object property. Taxi's version is checked by the compiler against the models you already have, rather than being a separate description of them.

​
Everything is declared

A model only satisfies a concept, or holds a relationship, if it says so with satisfies. An operation only performs an intent if it says so.

The compiler doesn’t infer these by looking at structure. A model with exactly the fields a concept needs, but no satisfies, isn’t treated as that concept. Inferring matches from structure may come in a later release, for concepts and relationships.

​
Concepts can't be created

A concept has no fields and no data of its own. You can’t use one as a field type, an operation parameter or return type, or a given value. Anything that “returns a person” returns a model that satisfies Person.

The compiler reports CONCEPT_NOT_CONSTRUCTIBLE when a concept is used where a value would be created. See Concepts for the full list.

​
Queries

TaxiQL has three new query forms:

QueryWhat it doesRead more
find { Person }Finds data from a model that satisfies PersonConcepts
call HireCalls the operation that performs the Hire intentIntents
worksFor::LegalEntityNameFollows a relationship inside a projectionRelationships

Query execution is coming

The Taxi compiler supports these query forms today: they compile, and they're type-checked against your schema. Support for running them is still being built in the query engine.

​
Next steps

  • Concepts: declaring concepts, and models that satisfy them
  • Intents: declaring actions, and operations that perform them
  • Relationships: declaring links between concepts, and following them in queries
Previous
Annotations
Next
Concepts