Update docs - Add more discussion of change-sets (alterAlngular) and philosophy
[civicrm-core.git] / ext / afform / docs / philosophy.md
1 # Philosophy, Beliefs, Assumptions
2
3 Afform is generally grounded in a few beliefs..
4
5 ## Leap by extension
6
7 Afform represents a major conceptual change in how core forms are developed. It is incubated as an extension that can
8 be enabled or disabled to taste. The aim is for oother extension using `afform` can incrementally override/replace
9 particular forms in core.
10
11 ## Features and user-experiences evolve in funny workflows
12
13 If we could sit down and define one true, correct version of a "Donation" form, then our lives as Civi devlopers would
14 be easy: draw a mockup, write code, ship, and retire. But we can't -- because Civi users and integrators engage with
15 the system creatively. They aim to optimize conversion-rates, to integrate with donor journerys, to question how each
16 detail makes sense in their situation, etc. That means switching between open-ended donation amounts, sliders, radios,
17 etc; revising the language and layout; maybe adding an informational question or newsletter opt-in.
18
19 I believe that features and user-experiences evolve in funny workflows -- because the actual stories behind major
20 improvements have not fit into a single mold. A main ambition of `afform` is to allow multiple workflows in developing
21 a common type of deliverable (*the forms*). Thus, the architecture anticipates scenarios for developers defining forms
22 concretely; for users defining forms concretely; for using GUIs or text-editors or IDEs or SCMs; for using
23 cross-cutting hooks and selectors. Compatibility with multiple workflows is a primary feature of the design.
24
25 This is *not* an argument for maximal customization or maximal decentralization. As participants in an ecosystem, we
26 must still communicate and exercise judgment about the best way to approach each problem. But there are legitimate
27 instances for each workflow; given that each will be sought, we want them to be safe and somewhat consistent.
28
29 What distinguishes `afform` from the original form architecture (Civi's combination of HTML_Quickform, Smarty and
30 Profiles)? Each of those workflows has been given some consideration upfront with the aim of providing a *consistent,
31 unified model* -- so that the same data-structure can be pushed through any of those common workflows.
32
33 ## Incremental and measurable strictness
34
35 JavaScript, PHP, and HTML are forgiving, loosely-typed systems. This can be viewed as a strength (wrt to learnability
36 and prototyping), and it can be viewed as a weakness (allowing a number of common mistakes to go unidentified until a
37 user runs into them).
38
39 Personally, I think that strongly-typed languages are better for large, multi-person projects -- providing a fallback
40 to protect against some common mistakes that arise people don't fully communicate or understand a change. However,
41 adopting a strongly-typed system is a major change, and it's not perfect, and I can respect the arguments in favor of
42 loosely-typed systems.
43
44 A compromise is to phase-in some static analysis incrementally. For `afform`, this means that the main deliverables
45 (HTML documents+changesets) should be encoded in an inspectable form -- it must be possible for the system to enumerate
46 all documents+changesets and audit them (i.e. identifying which form elements -- CSS classes and Angular directives --
47 are officially supported or unsupported). This, in turn, means that we can provide warnings and scores to identify
48 which customizations are more maintainable or more experimental/suspect.
49
50 ## Don't reinvent the wheel; do use a wheel that fits
51
52 The general philosophy and architecture in `afform` could be used with almost any form system that has a clear
53 component hierarchy (such as AngularJS's HTML notation, Symfony Form's object graph, or Drupal Form API's array-trees).
54
55 It specifically uses AngularJS. Why? In order of descending importance:
56
57 * It can work across a wide range of existing deployment environments (D7, D8, WordPress, Backdrop, Joomla, Standalone).
58 * It already exists.
59 * I have experience with it.
60 * The main Angular tutorials aimed at generalist web developers are reasonably slick.
61 * The connection between the code you write and what's displayed in the browser is fairly concrete.
62
63 It's by no means a perfect wheel. Other wheels have strengths, too. I checked the top-line requirement and grabbed
64 the closest wheel that fit.
65
66 ## Fidelity to upstream
67
68 The upstream AngularJS project canonically represents a form as an HTML file on disk; thus, `afform` does the same.
69 The upstream project uses `ng-if` for a conditional element; thus, an `afform` instance should do the same. The
70 upstream project uses "directives" for composable building blocks; and `afform`, the same.
71
72 This convention (a) helps to reduce bike-shedding, (b) helps us get some benefit out of re-using an existing wheel, and
73 (c) practices what we preach with regard to "consistency" across the various workflows.
74
75 ## Generally comparable platform requirements
76
77 If you can install CiviCRM on a server today, then you should be able to install `afform` and a personalized mix of
78 extensions which build on it. This means that the main workflows facilitated by `afform` can require PHP (and even
79 MySQL), but they can't require (say) Redis or Ruby or NodeJS.