The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * The building blocks of an `@alchemy.run/domain` model, as drawn in diagrams. |
| 3 | * Each kind has one colour, one icon and one shape, used everywhere. |
| 4 | */ |
| 5 | |
| 6 | export type Kind = |
| 7 | | "command" |
| 8 | | "aggregate" |
| 9 | | "event" |
| 10 | | "view" |
| 11 | | "query" |
| 12 | | "projection" |
| 13 | | "stream" |
| 14 | | "policy" |
| 15 | | "saga" |
| 16 | | "rejection" |
| 17 | | "external" |
| 18 | | "api" |
| 19 | | "client"; |
| 20 | |
| 21 | /** How a kind's box is drawn. */ |
| 22 | export type Shape = |
| 23 | | "arrow" // a request on its way: a box pointing right |
| 24 | | "arrowBack" // an answer on its way back: a box pointing left |
| 25 | | "boundary" // a consistency boundary: a double outline |
| 26 | | "record" // a fact on paper: a folded corner |
| 27 | | "pill" // a read model: rounded ends |
| 28 | | "box" // a plain box |
| 29 | | "stack" // a log of entries: stacked boxes |
| 30 | | "octagon" // a rule: cut corners |
| 31 | | "outside"; // outside the model: a dashed outline |
| 32 | |
| 33 | export interface KindStyle { |
| 34 | readonly name: string; |
| 35 | readonly hue: string; |
| 36 | readonly shape: Shape; |
| 37 | /** Icon paths in a 24×24 box, stroked. */ |
| 38 | readonly icon: ReadonlyArray<string>; |
| 39 | } |
| 40 | |
| 41 | export const KINDS: Record<Kind, KindStyle> = { |
| 42 | command: { |
| 43 | name: "Command", |
| 44 | hue: "#4f9fd8", |
| 45 | shape: "arrow", |
| 46 | // Sent to the model, like a paper plane. |
| 47 | icon: ["M21 3L10 14", "M21 3l-6.5 18-4.5-7-7-4.5z"], |
| 48 | }, |
| 49 | aggregate: { |
| 50 | name: "Aggregate", |
| 51 | hue: "#e3b341", |
| 52 | shape: "boundary", |
| 53 | icon: ["M12 3l8 4.5v9L12 21l-8-4.5v-9z", "M4 7.5l8 4.5 8-4.5", "M12 12v9"], |
| 54 | }, |
| 55 | event: { |
| 56 | name: "Event", |
| 57 | hue: "#f0782f", |
| 58 | shape: "record", |
| 59 | icon: ["M13 2L4 14h7l-1 8 9-12h-7z"], |
| 60 | }, |
| 61 | view: { |
| 62 | name: "View", |
| 63 | hue: "#7fb069", |
| 64 | shape: "pill", |
| 65 | icon: [ |
| 66 | "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z", |
| 67 | "M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6z", |
| 68 | ], |
| 69 | }, |
| 70 | query: { |
| 71 | name: "Query", |
| 72 | hue: "#e6d3a8", |
| 73 | shape: "arrowBack", |
| 74 | icon: ["M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z", "M20 20l-4-4"], |
| 75 | }, |
| 76 | projection: { |
| 77 | name: "Projection", |
| 78 | hue: "#3fb8af", |
| 79 | shape: "box", |
| 80 | icon: [ |
| 81 | "M4 6c0-1.7 3.6-3 8-3s8 1.3 8 3-3.6 3-8 3-8-1.3-8-3z", |
| 82 | "M4 6v12c0 1.7 3.6 3 8 3s8-1.3 8-3V6", |
| 83 | "M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3", |
| 84 | ], |
| 85 | }, |
| 86 | stream: { |
| 87 | name: "Stream", |
| 88 | hue: "#9aa7c7", |
| 89 | shape: "stack", |
| 90 | // Entries flowing one way, like Kinesis: parallel lines into one arrowhead. |
| 91 | icon: ["M3 7h11", "M3 12h17", "M3 17h11", "M17 9l3 3-3 3"], |
| 92 | }, |
| 93 | policy: { |
| 94 | name: "Policy", |
| 95 | hue: "#a78bdb", |
| 96 | shape: "octagon", |
| 97 | icon: [ |
| 98 | "M12 3v18", |
| 99 | "M6 21h12", |
| 100 | "M5 7h14", |
| 101 | "M5 7l-3 7a3 3 0 0 0 6 0z", |
| 102 | "M19 7l-3 7a3 3 0 0 0 6 0z", |
| 103 | ], |
| 104 | }, |
| 105 | saga: { |
| 106 | name: "Saga", |
| 107 | hue: "#c6d84a", |
| 108 | shape: "box", |
| 109 | // Steps joined into one process. |
| 110 | icon: ["M3 3h7v7H3z", "M14 14h7v7h-7z", "M6.5 10v4a3 3 0 0 0 3 3H14"], |
| 111 | }, |
| 112 | rejection: { |
| 113 | name: "Rejection", |
| 114 | hue: "#e5484d", |
| 115 | shape: "box", |
| 116 | icon: ["M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z", "M9 9l6 6", "M15 9l-6 6"], |
| 117 | }, |
| 118 | external: { |
| 119 | name: "External system", |
| 120 | hue: "#d97aa8", |
| 121 | shape: "outside", |
| 122 | icon: ["M9 2v6", "M15 2v6", "M6 8h12v4a6 6 0 0 1-12 0z", "M12 18v4"], |
| 123 | }, |
| 124 | api: { |
| 125 | name: "Api", |
| 126 | hue: "#ece8df", |
| 127 | shape: "box", |
| 128 | // What the model publishes to the outside world. |
| 129 | icon: [ |
| 130 | "M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z", |
| 131 | "M3 12h18", |
| 132 | "M12 3c3 3 3 15 0 18", |
| 133 | "M12 3c-3 3-3 15 0 18", |
| 134 | ], |
| 135 | }, |
| 136 | client: { |
| 137 | name: "Client", |
| 138 | hue: "#c3ccd6", |
| 139 | shape: "outside", |
| 140 | // An app or service outside the model, calling it through an Api. |
| 141 | icon: ["M4 5h16v11H4z", "M2 19h20"], |
| 142 | }, |
| 143 | }; |
| 144 | |
| 145 | export const KIND_ORDER = Object.keys(KINDS) as ReadonlyArray<Kind>; |