"TiddlyWiki Architecture" needs to go into more depth

I spent a couple of days twisting my mind in knots because the "Overview" diagram in the TiddlyWiki Architecture tiddler didn't go into enough detail, the RefreshMechanism tiddler doesn't exist, and the tiddlers listed in the table of contents didn't have enough cross-references. (The light only came on as a result of a lot of code-diving and some tiddler search results.)

Aside from a few rough spots where I'm not yet certain of how things work, I've assembled an amendment for the [TiddlyWiki Architecture](http://tiddlywiki.com/#TiddlyWiki%20Architecture) tiddler which should really help.

If you're receptive, I'm willing to sign the CLA and then convert the non-TODO bits of this into a pull request for a WikiText version.

There are probably inaccuracies, but I did the best I could given the current state of TW5's docs and the lack of any kind of API documentation to provide an auto-generated project-wide function/method index.

----

When programming TiddlyWiki 5 plugins which make changes outside the scope of the included examples, you will need a more in-depth understanding of TiddlyWiki's internal architecture.

## Model

TiddlyWiki's data model is a fairly simple key-value store.

* Each tiddler is simply an object with a `fields` member containing members such as `title`, `text`, `tags` and so on.
* The core `Wiki` class defined in `boot/boot.js` implements simple associative array behaviours like insertion, deletion, iteration, listing keys, and get-by-key.
* The code in `core/modules/wiki.js` then extends the `Wiki` class with functionality such as event dispatch and various cache-backed methods such as `getTiddlersWithTag`.

The active tiddler store can be accessed via `$tw.wiki` as in this example:

```js
$tw.wiki.makeTiddlerIterator($tw.wiki.getTiddlersWithTag('timeline')
    )(function(tiddler, title) {
        // Skip templates
        if (tiddler.fields.tags.indexOf('templates') >= 0) { return; }

        do_something(tiddler);
});
```

**TODO:** Find a properly in-depth explanation of what [Naming of System Tiddlers](http://tiddlywiki.com/#Naming%20of%20System%20Tiddlers) is actually saying and extend this explanation. (eg. Is there any special behaviour assigned to slashes in tiddler names? What special behaviours are attached to which names? What's the difference between a `$:/state/*` tiddler and a `$:/temp/*` tiddler? etc.)

**TODO:** Figure out where the [PermaLinks](http://tiddlywiki.com/#PermaLinks) mechanism is documented and whether it's extensible. (eg. Could an tiddler expand/collapse plugin add its state to the permalink?)

## View

TiddlyWiki's view layer has a *lot* in common with desktop widget toolkits and this is the part which is most likely to trip newcomers up. There are two facets to it:

### Role of the DOM
Because TiddlyWiki may re-render content, plugins should treat the DOM as write-only.

In other words, any state you store in the DOM could vanish at any instant and you need to use TiddlyWiki's internal [StateMechanism](http://tiddlywiki.com/#StateMechanism) instead.

In a desktop application, the base widget class defines a method such as `paint(canvas)` which is called in response to `expose` events or "data has changed" messages; In TiddlyWiki, the `Widget` class in `core/modules/widgets/widgets.js` defines a `render(parent, nextSibling)` method which TiddlyWiki calls in response to various events such as changes in the model.

(The potential inefficiency of this approach is mitigated via a `refresh(changedTiddlers)` method which TiddlyWiki calls to ask your widget whether its current rendering is stale.)

**TODO:** Look up how actual TW5 code binds events.

### Locus of Control

While TiddlyWiki markup is similar in design to HTML templating languages with logic constructs, you can't just ignore it and assemble all your content in raw Javascript because it is used to define most of TiddlyWiki's UI.

In this respect, it's closer to a glue language like Qt Quick or Python with Javascript filling the "create new components" role of C/C++ in widget toolkits like Qt and GTK+.

![tiddlywiki page composition](https://cloud.githubusercontent.com/assets/46915/3560524/30698ea6-0974-11e4-83ad-e3bcc946056a.png)

To familiarize yourself with this, read the [Widgets in WikiText](http://tiddlywiki.com/#Widgets%20in%20WikiText) and [Introduction to Filters](http://tiddlywiki.com/#Introduction%20to%20Filters) tiddlers and then examine the internals for a tiddler like [TaskManagementExample](http://tiddlywiki.com/#Introduction%20to%20Filters).

## Controller

**TODO:** Figure out what kind of hackery TiddlyWiki allows to be performed on the core itself.