interaqt 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/agent/.claude/agents/code-generation-handler.md +2 -0
  2. package/agent/.claude/agents/computation-generation-handler.md +1 -0
  3. package/agent/.claude/agents/implement-design-handler.md +4 -13
  4. package/agent/.claude/agents/requirements-analysis-handler.md +46 -14
  5. package/agent/agentspace/knowledge/generator/api-reference.md +3378 -0
  6. package/agent/agentspace/knowledge/generator/basic-interaction-generation.md +377 -0
  7. package/agent/agentspace/knowledge/generator/computation-analysis.md +307 -0
  8. package/agent/agentspace/knowledge/generator/computation-implementation.md +959 -0
  9. package/agent/agentspace/knowledge/generator/data-analysis.md +463 -0
  10. package/agent/agentspace/knowledge/generator/entity-relation-generation.md +395 -0
  11. package/agent/agentspace/knowledge/generator/permission-implementation.md +460 -0
  12. package/agent/agentspace/knowledge/generator/permission-test-implementation.md +870 -0
  13. package/agent/agentspace/knowledge/generator/test-implementation.md +674 -0
  14. package/agent/agentspace/knowledge/usage/00-mindset-shift.md +322 -0
  15. package/agent/agentspace/knowledge/usage/01-core-concepts.md +131 -0
  16. package/agent/agentspace/knowledge/usage/02-define-entities-properties.md +407 -0
  17. package/agent/agentspace/knowledge/usage/03-entity-relations.md +599 -0
  18. package/agent/agentspace/knowledge/usage/04-reactive-computations.md +2186 -0
  19. package/agent/agentspace/knowledge/usage/05-interactions.md +1411 -0
  20. package/agent/agentspace/knowledge/usage/06-attributive-permissions.md +10 -0
  21. package/agent/agentspace/knowledge/usage/07-payload-parameters.md +593 -0
  22. package/agent/agentspace/knowledge/usage/08-activities.md +863 -0
  23. package/agent/agentspace/knowledge/usage/09-filtered-entities.md +784 -0
  24. package/agent/agentspace/knowledge/usage/10-async-computations.md +734 -0
  25. package/agent/agentspace/knowledge/usage/11-global-dictionaries.md +942 -0
  26. package/agent/agentspace/knowledge/usage/12-data-querying.md +1033 -0
  27. package/agent/agentspace/knowledge/usage/13-testing.md +1201 -0
  28. package/agent/agentspace/knowledge/usage/14-api-reference.md +1606 -0
  29. package/agent/agentspace/knowledge/usage/15-entity-crud-patterns.md +1122 -0
  30. package/agent/agentspace/knowledge/usage/16-frontend-page-design-guide.md +485 -0
  31. package/agent/agentspace/knowledge/usage/17-performance-optimization.md +283 -0
  32. package/agent/agentspace/knowledge/usage/18-api-exports-reference.md +176 -0
  33. package/agent/agentspace/knowledge/usage/19-common-anti-patterns.md +563 -0
  34. package/agent/agentspace/knowledge/usage/README.md +148 -0
  35. package/package.json +1 -1
@@ -0,0 +1,322 @@
1
+ # Mindset Shift: From Imperative to Declarative
2
+
3
+ ## ⚠️ Important: Please understand this core concept before learning interaqt
4
+
5
+ The interaqt framework requires a fundamental **mindset shift**. If you continue to use traditional imperative thinking with this framework, you will not be able to realize its true value.
6
+
7
+ ## Core Principle: Only Interactions Create Data, Everything Else is a "Shadow" of Data
8
+
9
+ ### Traditional Thinking vs interaqt Thinking
10
+
11
+ #### ❌ Traditional Imperative Thinking (Wrong)
12
+ ```javascript
13
+ // Wrong mindset: What do I need to "do"
14
+ function createPost(title, content, authorId) {
15
+ // 1. Create post
16
+ const post = db.posts.create({ title, content, authorId });
17
+ // 2. Update user's post count
18
+ db.users.update(authorId, { postCount: postCount + 1 });
19
+ // 3. If it's a hot tag, update popularity
20
+ if (isHotTag(post.tags)) {
21
+ db.tags.update(post.tags, { hotness: hotness + 1 });
22
+ }
23
+ // 4. Notify followers
24
+ notifyFollowers(authorId, post);
25
+ }
26
+ ```
27
+
28
+ This thinking asks: "When a user creates a post, what series of operations do I need to execute?"
29
+
30
+ #### ✅ interaqt Declarative Thinking (Correct)
31
+ ```javascript
32
+ // Correct mindset: What do I need to "declare" data to be
33
+
34
+ // 1. User post count "is" the Count of posts created by the user
35
+ const User = Entity.create({
36
+ properties: [
37
+ Property.create({
38
+ name: 'postCount',
39
+ computation: Count.create({
40
+ record: UserPostRelation
41
+ })
42
+ })
43
+ ]
44
+ });
45
+
46
+ // 2. Tag popularity "is" the Count of posts containing that tag
47
+ const Tag = Entity.create({
48
+ properties: [
49
+ Property.create({
50
+ name: 'hotness',
51
+ computation: Count.create({
52
+ record: PostTagRelation
53
+ })
54
+ })
55
+ ]
56
+ });
57
+
58
+ // 3. Follower notifications "are" a Transform of follow relationships
59
+ const Notification = Entity.create({
60
+ computation: Transform.create({
61
+ record: InteractionEventEntity, // Listen to all interaction events
62
+ callback: (event) => {
63
+ if (event.interactionName === 'CreatePost') {
64
+ // Return notification data that should be created
65
+ return generateNotifications(event);
66
+ }
67
+ }
68
+ })
69
+ });
70
+
71
+ // 4. Interactions only "declare" what users can do, containing no operational logic
72
+ const CreatePost = Interaction.create({
73
+ name: 'CreatePost',
74
+ action: Action.create({ name: 'createPost' }), // Just an identifier!
75
+ payload: Payload.create({
76
+ items: [
77
+ PayloadItem.create({ name: 'title', required: true }),
78
+ PayloadItem.create({ name: 'content', required: true })
79
+ ]
80
+ })
81
+ });
82
+ ```
83
+
84
+ This thinking asks: "Post count is the count of posts, tag popularity is the count of posts containing that tag"
85
+
86
+ ## Key Concept Clarification
87
+
88
+ ### Action is Not an "Operation", It's an "Identifier"
89
+
90
+ **❌ Wrong Understanding:**
91
+ ```javascript
92
+ // LLMs often think this way: Action contains operational logic
93
+ const Action = Action.create({
94
+ name: 'createPost',
95
+ execute: async (payload) => { // ❌ There's no execute method at all!
96
+ // Write operational logic here...
97
+ }
98
+ });
99
+ ```
100
+
101
+ **✅ Correct Understanding:**
102
+ ```javascript
103
+ // Action is just an identifier, like giving this interaction a name
104
+ const Action = Action.create({
105
+ name: 'createPost' // That's all! No logic whatsoever!
106
+ });
107
+ ```
108
+
109
+ Action is like naming an event type, such as "UserClicked" or "OrderSubmitted". It contains no execution logic.
110
+
111
+ ### Data "Existence" vs "Operations"
112
+
113
+ #### ❌ Imperative Thinking: I need to operate on data
114
+ ```javascript
115
+ // Wrong: trying to "update" data somewhere
116
+ function likePost(userId, postId) {
117
+ // 1. Create like record
118
+ createLike(userId, postId);
119
+ // 2. Update post like count ❌ Don't do this!
120
+ const likeCount = countLikes(postId);
121
+ updatePost(postId, { likeCount });
122
+ }
123
+ ```
124
+
125
+ #### ✅ Declarative Thinking: Data "is" a computation result
126
+ ```javascript
127
+ // Correct: declare that like count is the count of like relationships
128
+ const Post = Entity.create({
129
+ properties: [
130
+ Property.create({
131
+ name: 'likeCount',
132
+ computation: Count.create({
133
+ record: LikeRelation // Like count "is" the number of like relationships
134
+ })
135
+ })
136
+ ]
137
+ });
138
+
139
+ // Like interaction only declares what action users can perform
140
+ const LikePost = Interaction.create({
141
+ name: 'LikePost',
142
+ action: Action.create({ name: 'likePost' }),
143
+ payload: Payload.create({
144
+ items: [
145
+ PayloadItem.create({ name: 'postId', base: Post, isRef: true })
146
+ ]
147
+ })
148
+ });
149
+
150
+ // The existence of like relationship itself responds to like interactions
151
+ const LikeRelation = Relation.create({
152
+ source: User,
153
+ target: Post,
154
+ computation: Transform.create({
155
+ record: InteractionEventEntity,
156
+ callback: (event) => {
157
+ if (event.interactionName === 'LikePost') {
158
+ return {
159
+ source: event.user.id,
160
+ target: event.payload.postId
161
+ };
162
+ }
163
+ }
164
+ })
165
+ });
166
+ ```
167
+
168
+ ## Unidirectional Data Flow
169
+
170
+ ### Data flow in interaqt is strictly unidirectional:
171
+
172
+ ```
173
+ Interaction (User Interaction)
174
+
175
+ InteractionEvent (Interaction Event)
176
+
177
+ Transform/Count/Every/Any (Reactive Computation)
178
+
179
+ Entity/Relation Data
180
+
181
+ More Reactive Computations
182
+
183
+ Final Business Data
184
+ ```
185
+
186
+ **Never try to operate in reverse!**
187
+
188
+ ## Real Example: E-commerce Order System
189
+
190
+ ### ❌ Traditional Imperative Thinking
191
+ ```javascript
192
+ function placeOrder(userId, items) {
193
+ // 1. Create order
194
+ const order = createOrder(userId, items);
195
+ // 2. Reduce inventory
196
+ items.forEach(item => {
197
+ reduceStock(item.productId, item.quantity);
198
+ });
199
+ // 3. Update user order count
200
+ incrementUserOrderCount(userId);
201
+ // 4. Update product sales
202
+ items.forEach(item => {
203
+ incrementProductSales(item.productId, item.quantity);
204
+ });
205
+ }
206
+ ```
207
+
208
+ ### ✅ interaqt Declarative Thinking
209
+ ```javascript
210
+ // 1. Product inventory "is" initial stock minus quantities in all orders
211
+ const Product = Entity.create({
212
+ properties: [
213
+ Property.create({ name: 'initialStock', type: 'number' }),
214
+ Property.create({
215
+ name: 'currentStock',
216
+ computation: WeightedSummation.create({
217
+ record: OrderItemRelation,
218
+ callback: (orderItem) => ({
219
+ weight: -1, // Reduce inventory
220
+ value: orderItem.quantity
221
+ })
222
+ })
223
+ }),
224
+ Property.create({
225
+ name: 'totalSales',
226
+ computation: WeightedSummation.create({
227
+ record: OrderItemRelation,
228
+ callback: (orderItem) => ({
229
+ weight: 1,
230
+ value: orderItem.quantity
231
+ })
232
+ })
233
+ })
234
+ ]
235
+ });
236
+
237
+ // 2. User order count "is" the Count of user's orders
238
+ const User = Entity.create({
239
+ properties: [
240
+ Property.create({
241
+ name: 'orderCount',
242
+ computation: Count.create({
243
+ record: UserOrderRelation
244
+ })
245
+ })
246
+ ]
247
+ });
248
+
249
+ // 3. Place order interaction only declares that users can place orders
250
+ const PlaceOrder = Interaction.create({
251
+ name: 'PlaceOrder',
252
+ action: Action.create({ name: 'placeOrder' }), // Just an identifier!
253
+ payload: Payload.create({
254
+ items: [
255
+ PayloadItem.create({ name: 'items', isCollection: true }),
256
+ PayloadItem.create({ name: 'address' })
257
+ ]
258
+ })
259
+ });
260
+
261
+ // 4. Order existence responds to place order interactions
262
+ const UserOrderRelation = Relation.create({
263
+ source: User,
264
+ target: Order,
265
+ computation: Transform.create({
266
+ record: InteractionEventEntity,
267
+ callback: (event) => {
268
+ if (event.interactionName === 'PlaceOrder') {
269
+ return {
270
+ source: event.user.id,
271
+ target: {
272
+ items: event.payload.items,
273
+ address: event.payload.address,
274
+ status: 'pending'
275
+ }
276
+ };
277
+ }
278
+ }
279
+ })
280
+ });
281
+ ```
282
+
283
+ ## Key Mental Models
284
+
285
+ ### 1. Interactions are "Seeds" of Data
286
+ - Only Interactions can generate new data
287
+ - All other data are "derivatives" of Interaction data
288
+
289
+ ### 2. Actions are "Event Type Labels"
290
+ - Actions are like event names, containing no logic
291
+ - They just tell the system "what type of event occurred"
292
+
293
+ ### 3. Data "Exists" Rather Than "Being Operated On"
294
+ - Don't think "how to modify data"
295
+ - Think "what this data essentially is"
296
+
297
+ ### 4. Everything is a "Function"
298
+ - User post count = Count(user's post relationships)
299
+ - Product inventory = Initial stock - Count(product quantities in orders)
300
+ - Notifications = Transform(interaction events)
301
+
302
+ ## Exercise: Transform Your Thinking
303
+
304
+ When you want to implement a feature, ask yourself:
305
+
306
+ ### ❌ Don't Ask:
307
+ - "When user does X, what data do I need to update?"
308
+ - "Where should I write the update logic?"
309
+ - "How do I ensure data consistency?"
310
+
311
+ ### ✅ Should Ask:
312
+ - "What computation result is this data essentially?"
313
+ - "What other data does this data depend on?"
314
+ - "What kind of interaction event should this user operation generate?"
315
+
316
+ Once you establish this mindset, the power of the interaqt framework will emerge:
317
+ - Data is always consistent
318
+ - Business logic is clear and maintainable
319
+ - Automatically handles complex dependencies
320
+ - Naturally supports real-time updates
321
+
322
+ Remember: **Stop thinking about "how to do", start thinking about "what it is"**.
@@ -0,0 +1,131 @@
1
+ # Core Concepts and Reactive Mechanism Overview
2
+
3
+ ## ⚠️ Read First: Mindset Shift
4
+
5
+ **Before learning interaqt, please read [00-mindset-shift.md](./00-mindset-shift.md) first, as this is crucial for understanding the framework.**
6
+
7
+ If you continue to use traditional imperative thinking ("how to operate data") with interaqt, you will not be able to realize its true value. interaqt requires a fundamental mindset shift: from "operating data" to "declaring the essence of data".
8
+
9
+ ## Core Philosophy of the Framework
10
+
11
+ interaqt is a **declarative reactive** backend framework with the core philosophy:
12
+
13
+ > **Stop thinking about "how to operate data", start thinking about "what data essentially is"**
14
+
15
+ ### Core Principle: Only Interactions Generate Data, Everything Else is a "Shadow" of Data
16
+
17
+ In interaqt:
18
+ - **Only user interactions can generate new data**
19
+ - **All other data are computation results of interaction data**
20
+ - **Never try to "operate" data, only "declare" what data is**
21
+
22
+ ### Basic Paradigm: data = computation(events)
23
+
24
+ #### ❌ Traditional Imperative Thinking (Wrong)
25
+ ```javascript
26
+ // Wrong: trying to operate data
27
+ async function likePost(userId, postId) {
28
+ // 1. Create like record
29
+ await createLike(userId, postId);
30
+ // 2. Manually update like count
31
+ const likeCount = await countLikes(postId);
32
+ await updatePost(postId, { likeCount });
33
+ // 3. Notify related users
34
+ await notifyPostAuthor(postId);
35
+ }
36
+ ```
37
+
38
+ This thinking asks: "When a user likes a post, what operations do I need to execute?"
39
+
40
+ #### ✅ interaqt Declarative Thinking (Correct)
41
+ ```javascript
42
+ // Correct: declare what data is
43
+ const Post = Entity.create({
44
+ name: 'Post',
45
+ properties: [
46
+ Property.create({ name: 'title' }),
47
+ Property.create({
48
+ name: 'likeCount',
49
+ // Like count "is" the number of like relationships
50
+ computation: Count.create({
51
+ record: LikeRelation
52
+ })
53
+ })
54
+ ]
55
+ });
56
+
57
+ // Like interaction only declares that users can like, containing no operational logic
58
+ const LikePost = Interaction.create({
59
+ name: 'LikePost',
60
+ action: Action.create({ name: 'likePost' }), // Just an identifier!
61
+ payload: Payload.create({
62
+ items: [
63
+ PayloadItem.create({ name: 'postId', base: Post, isRef: true })
64
+ ]
65
+ })
66
+ });
67
+
68
+ // Like relationship existence "is" a response to like interactions
69
+ const LikeRelation = Relation.create({
70
+ source: User,
71
+ target: Post,
72
+ computation: Transform.create({
73
+ record: InteractionEventEntity,
74
+ callback: (event) => {
75
+ if (event.interactionName === 'LikePost') {
76
+ return {
77
+ source: event.user.id,
78
+ target: event.payload.postId
79
+ };
80
+ }
81
+ }
82
+ })
83
+ });
84
+ ```
85
+
86
+ This thinking asks: "What is like count essentially? When should like relationships exist?"
87
+
88
+ When a user likes a post, the system automatically:
89
+ 1. Creates like relationship (because Transform declares it should exist)
90
+ 2. Updates like count (because Count declares it's the number of like relationships)
91
+ 3. Triggers any other computations that depend on like count
92
+
93
+ **You don't need to write any "update" logic!**
94
+
95
+ ## Core Concepts
96
+
97
+ ### Entity
98
+ Basic units of data, such as User, Post, Comment, etc.
99
+
100
+ ### Property
101
+ Fields of entities, can be simple values or automatically computed values based on other data.
102
+
103
+ ### Relation
104
+ Connections between entities, such as like relationships between users and posts.
105
+
106
+ ### Interaction
107
+ Events triggered by users, the **only source** of data changes in the system. Interactions only declare "what users can do", containing no operational logic.
108
+
109
+ ### Action
110
+ ⚠️ **Important Clarification**: Action is not an "operation", but an **identifier** for interaction types, like event names. It contains no execution logic.
111
+
112
+ ### Computation
113
+ Automatically computed values based on other data, the core of reactivity. Includes Count, Transform, Every, Any, StateMachine, etc.
114
+
115
+ ### Activity
116
+ Ordered combinations of multiple related Interactions, implementing complex business processes.
117
+
118
+ ## How Reactive Computation Works
119
+
120
+ 1. **Event Source**: All data changes originate from user Interactions
121
+ 2. **Change Tracking**: System automatically generates change events
122
+ 3. **Dependency Graph**: Computations declare dependencies on which data
123
+ 4. **Automatic Propagation**: When dependent data changes, related computations automatically re-execute
124
+ 5. **Incremental Computation**: Uses incremental algorithms to avoid full recalculation, ensuring performance
125
+
126
+ ## Typical Use Cases
127
+
128
+ - **Content Systems**: Articles, comments, like statistics
129
+ - **Social Networks**: Friend relationships, feed updates
130
+ - **Approval Workflows**: Multi-step, multi-role collaboration
131
+ - **E-commerce Systems**: Order status, inventory calculation