domain-query-language / dql-server-php-defunct

A server side application that can receive and process DQL statements, leading to a fully working, event sourced, domain.
MIT License
0 stars 1 forks source link

Problem: This is taking a long time to write #161

Open barryosull opened 8 years ago

barryosull commented 8 years ago

Writing the parser and the interpreter is taking a long, long time, as it's a very complex process.

Let's discuss if there are other ways to implement this, to get a prototype working without having to write a full system.

barryosull commented 8 years ago

Let's break down the system into it's core processes, what operations should be performed?

What are the various processes?

Datastructure validation:

Validate that a datastructure has the correct structure and that the data it contains passes validation Really two parts

DDD entities affected:

Languages: (none)

Libraries: Respect validation

Links: https://en.wikipedia.org/wiki/Data_validation

Datastructure querying:

Query a datastructure, extracting a subset of that structure and performing aggregation operations on it (SELECT/MapReduce)

DDD entities affected:

Languages:

Libaries:

Links: https://en.wikipedia.org/wiki/Tree_(data_structure)#Traversal_methods

Datastructure modification:

Modify a datastructure, changing its shape in some way, usually involves adding/updating/removing value objects/entitites Can involve basic arithmetic. (We could move this into the query side, since it's job is to query the dataset) Takes entities/valueobjects from an event and updates the root entitiy

We can simplify this by making the modifications, then passing the entire entity back through the validator, to ensure it's valid. This makes type checking easier, though it also means that type checking is done at runtime, not compile/interpretation time.

DDD entities affected:

Composition

Command handlers need to compose invariants and events together to represent a command It involves outlining the order of the calls, and what data is passed into each component. Properties of the commands will need to be accessed, then passed into the events to be broadcast. Queries may be used at this stage to access data that will be broadcast.

_DDD entities affected: _

Thoughts

Programming concepts we don't have

It's all about restricting the amount of operations you can perform, ensuring that you can the language lets you do what you need, and nothing else.

We can possibly simplify things by interpreting parts of the code, using existing systems to take care of it. Eg. Validation functions are just written in javascript/php (using a validation lib), this means we don't have to write an interpreter for all that code, some one else has done the work for us. We also lock it down, so that certain functions are not allowed, eg, making AJAX calls, system calls, etc . . .

barryosull commented 8 years ago

In regards to the above, let's map out things that will make this easier.

Datastructure validation:

Scalar value validation Write the validators using a library and a particular code type latitude: numeric()->between(-90, 90)

Better than the existing version, as it allows full use of respect straight out of the box

Tree structure validation Already have this working a JSON, could switch to YAML, but there's no real point We can store them as either JSON, or Yaml, with a smart system to figure out which is which? Too much work, choose one and stick to it Let's go with YAML, it's the easier one to use and parse

Composite latitude: latitude, longitude: longitude

Entity id: uuid, name: name, address: address

Command person: person

Event person: person

Invariant query: created, check: v::boolean()

We pretty much have this working already, so we can extract this into it's own simpler system.

Datastructure querying:

In aggregate Use standard PHP code for this, as PHP is pretty good at accessing a data structure Anonymous PHP functions that take data, and the state object, then traverse it, performing standard operations We could also pass in the PHP implementation of PHPJS, to make this much easier.

Inter aggregate SQL files for this, that contain prepared SQL statements with named parameters

Datastructure modification:

PHP is already pretty good at modifying a datastructure, this code can just be written as standard PHP for now We should make it a function that takes in a datastructure, an event, and return the datastructure The system will know the root entity, so we can feed the structure back to the validator, and ensure that the new sturcture is valid

Composition:

This is already working, don't think we need to do any more.

Design

As the system is getting complex, I think it needs to be refactored so each component is self contained. The interpreter patterns works for fully self contained languages, but we have actually built multiple interpreters that tie together.

We could redesign the system so that there are tiered interpreters, tied together at a higher level. This would lead to a better design overall, easier to understand, test, and change.

barryosull commented 8 years ago

Thinking about it, there is also a translation layer. One that converts data from one context into data from another context. It's not quite the same as the modification later, as it's job is to translate one DTO into another, possibly with some querying, there is no modification of data structures, only the building of new ones.