@powerhousedao/academy 5.1.0-dev.0 → 5.1.0-dev.10

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 (75) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/blog/BeyondCommunication-ABlueprintForDevelopment.md +2 -1
  3. package/blog/TheChallengeOfChange.md +1 -0
  4. package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +24 -27
  5. package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +118 -9
  6. package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +110 -28
  7. package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +191 -145
  8. package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +378 -0
  9. package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +560 -0
  10. package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
  11. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
  12. package/docs/academy/{01-GetStarted → 02-MasteryTrack/01-BuilderEnvironment}/05-VetraStudio.md +48 -6
  13. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +75 -44
  14. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +28 -22
  15. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +28 -31
  16. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +211 -206
  17. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +176 -62
  18. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +21 -0
  19. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +309 -319
  20. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +4 -0
  21. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +4 -0
  22. package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
  23. package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +111 -35
  24. package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +255 -76
  25. package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +281 -160
  26. package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +188 -35
  27. package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +95 -7
  28. package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
  29. package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +24 -0
  30. package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +211 -0
  31. package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +171 -0
  32. package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +462 -0
  33. package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +45 -0
  34. package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +422 -0
  35. package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +61 -0
  36. package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +384 -0
  37. package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +8 -0
  38. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +7 -0
  39. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +9 -0
  40. package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +6 -2
  41. package/docs/academy/04-APIReferences/01-ReactHooks.md +2 -2
  42. package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +160 -0
  43. package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +316 -0
  44. package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +672 -0
  45. package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +957 -0
  46. package/docs/academy/04-APIReferences/renown-sdk/_category_.json +8 -0
  47. package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +7 -39
  48. package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +72 -24
  49. package/docs/academy/08-Glossary.md +7 -0
  50. package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +171 -0
  51. package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +462 -0
  52. package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +422 -0
  53. package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +370 -0
  54. package/docusaurus.config.ts +28 -3
  55. package/package.json +1 -1
  56. package/sidebars.ts +49 -12
  57. package/src/css/custom.css +26 -18
  58. package/static/img/Vetra-logo-dark.svg +11 -0
  59. package/static/img/vetra-logo-light.svg +11 -0
  60. package/docs/academy/00-EthereumArgentinaHackathon.md +0 -207
  61. package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +0 -218
  62. package/docs/academy/01-GetStarted/06-ReactorMCP.md +0 -58
  63. package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +0 -65
  64. package/docs/academy/05-Architecture/04-MovingBeyondCRUD +0 -61
  65. /package/docs/academy/{01-GetStarted → 02-MasteryTrack/01-BuilderEnvironment}/images/Modules.png +0 -0
  66. /package/docs/academy/{01-GetStarted → 02-MasteryTrack/01-BuilderEnvironment}/images/VetraStudioDrive.png +0 -0
  67. /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline → 02-RevisionHistoryTimeline/360/237/232/247"} +0 -0
  68. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{01-WhatIsADocumentModel → 360/237/232/247 /01-WhatIsADocumentModel"} +0 -0
  69. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{02-DAOandDocumentsModelsQ+A → 360/237/232/247 /02-DAOandDocumentsModelsQ+A"} +0 -0
  70. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{02-domain-modeling → 360/237/232/247 /02-domain-modeling"} +0 -0
  71. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{03-BenefitsOfDocumentModels → 360/237/232/247 /03-BenefitsOfDocumentModels"} +0 -0
  72. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{04-UtilitiesAndTips → 360/237/232/247 /04-UtilitiesAndTips"} +0 -0
  73. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{05-best-practices → 360/237/232/247 /05-best-practices"} +0 -0
  74. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{_category_.json → 360/237/232/247 /_category_.json"} +0 -0
  75. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{three-data-layers.png → 360/237/232/247 /three-data-layers.png"} +0 -0
@@ -1,5 +1,9 @@
1
1
  # Document Toolbar
2
2
 
3
+ :::warning Work in Progress
4
+ This documentation is still being written and may be incomplete.
5
+ :::
6
+
3
7
  The Document Toolbar is a central component in Powerhouse Connect, appearing at the top of every document view. It provides quick access to a variety of tools and functions designed to streamline your workflow and enhance document management.
4
8
 
5
9
  <figure className="image-container">
@@ -63,6 +63,10 @@ You can also view the committer's address for each revision, supporting full tra
63
63
 
64
64
  ![Committer Address Popup](./images/committer-address-popup.png)
65
65
 
66
+
67
+ :::warning Work in Progress
68
+ This remainder of this documentation is still being written and may be incomplete.
69
+ :::
66
70
  ## Replay, branch, and merge (under development)
67
71
 
68
72
  - **Replay:** When you load a document, the system replays all operations to build its state.
@@ -75,7 +75,7 @@ PH_CONNECT_ARBITRUM_ALLOW_LIST=""
75
75
  PH_CONNECT_RWA_ALLOW_LIST=""
76
76
  PH_CONNECT_HIDE_DOCUMENT_MODEL_SELECTION_SETTINGS="true"
77
77
 
78
- PH_CONNECT_RENOWN_URL="https://auth.renown.id"
78
+ PH_CONNECT_RENOWN_URL="https://www.renown.id"
79
79
  PH_CONNECT_RENOWN_NETWORK_ID="eip155"
80
80
  PH_CONNECT_RENOWN_CHAIN_ID=1
81
81
  PH_CONNECT_DISABLED_EDITORS="powerhouse/document-drive"
@@ -1,46 +1,112 @@
1
- # Create New Powerhouse Project
1
+ # Create a new chatroom project
2
2
 
3
- :::tip **Prerequisites**
3
+ :::tip Tutorial Repository
4
+ 📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
4
5
 
5
- - Powerhouse CLI installed: `pnpm install -g ph-cmd`
6
- - node.js 22 and pnpm installed
7
- - Visual Studio Code (or your preferred IDE)
8
- - Terminal/Command Prompt access
9
-
10
- If you need help with installing the prerequisites you can visit our page [prerequisites](/academy/MasteryTrack/BuilderEnvironment/Prerequisites)
6
+ This tutorial has a complete reference implementation available. You can:
7
+ - View the complete code for each step
8
+ - Clone and compare your implementation
9
+ - Use `git diff` to compare your code with the reference
11
10
  :::
12
11
 
13
- To create a new Powerhouse Document Model Library project, you can use the `ph init` command in your terminal. This command will create a new project in the current directory.
14
- This command will create a new project in the current directory. You can run the command in the terminal window of your OS or you open the newly installed VSCode and run the command in the terminal window of VSCode.Make sure the terminal reflects the directory where you want to create the new project.
12
+ <details>
13
+ <summary>📖 How to use this tutorial</summary>
14
+
15
+ This tutorial is designed for you to **build your own project from scratch** while having access to reference code.
16
+
17
+ ### Setup: Create your project and connect to tutorial repo
18
+
19
+ 1. **Create your project** following the tutorial:
20
+ ```bash
21
+ mkdir ph-projects
22
+ cd ph-projects
23
+ ph init
24
+ # When prompted, enter project name: ChatRoom
25
+ cd ChatRoom
26
+ ```
27
+
28
+ 2. **Add the tutorial repository as a remote** to access reference code:
29
+ ```bash
30
+ git remote add tutorial https://github.com/powerhouse-inc/chatroom-demo.git
31
+ git fetch tutorial --prune
32
+ ```
33
+
34
+ 3. **Create your own branch** to keep your work organized:
35
+ ```bash
36
+ git checkout -b my-chatroom-project
37
+ ```
38
+
39
+ Now you have access to the complete reference implementation while working on your own code!
40
+
41
+ ### Compare your work with the reference
42
+
43
+ At any point, compare what you've built with the reference:
15
44
 
16
45
  ```bash
17
- mkdir ph-projects
18
- cd ph-projects
46
+ # Compare your current work with the reference
47
+ git diff tutorial/main
48
+
49
+ # Compare specific files
50
+ git diff tutorial/main -- package.json
19
51
  ```
20
52
 
21
- This essentially opens that folder and places you in it.
53
+ ### If you get stuck
22
54
 
23
- Once you've navigated to the directory where you want to create the new project and in your terminal, run the following command:
55
+ Reset your code to match the reference:
24
56
 
25
57
  ```bash
26
- ph init
58
+ # Reset to reference (WARNING: loses your changes)
59
+ git reset --hard tutorial/main
27
60
  ```
28
61
 
29
- In the terminal, you will be asked to enter the project name. Fill in the project name and press enter. Make sure to pay attention to the capitalization of our name `ChatRoom` as it will influence your code generation.
62
+ </details>
30
63
 
31
- ```bash
32
- you@yourmachine:~/Powerhouse$ ph init
64
+ ## Overview
65
+
66
+ This tutorial guides you through creating a **ChatRoom** application using Powerhouse.
67
+ A Powerhouse project primarily consists of a document model and its editor. The ChatRoom demonstrates real-time collaboration features where users can post messages and react with emojis.
68
+
69
+ ## Prerequisites
70
+
71
+ - Powerhouse CLI installed: `pnpm install -g ph-cmd` or `npm install -g ph-cmd`
72
+ - node.js 22 and a package manager (pnpm or npm) installed
73
+ - Visual Studio Code (or your preferred IDE)
74
+ - Terminal/Command Prompt access
33
75
 
34
- ? What is the project name? ChatRoom
76
+ If you need help with installing the prerequisites you can visit our page [prerequisites](/academy/MasteryTrack/BuilderEnvironment/Prerequisites)
77
+
78
+ ## Quick start
79
+
80
+ Create a new Powerhouse project with a single command:
81
+
82
+ ```bash
83
+ ph init
35
84
  ```
36
85
 
86
+ ## Before you begin
87
+
88
+ 1. Open your terminal (either your system terminal or IDE's integrated terminal)
89
+ 2. Optionally, create a folder first to keep your Powerhouse projects:
90
+
91
+ ```bash
92
+ mkdir ph-projects
93
+ cd ph-projects
94
+ ```
95
+
96
+ 3. Ensure you're in the correct directory before running the `ph init` command.
97
+ In the terminal, you will be asked to enter the project name. Fill in the project name and press Enter.
98
+
99
+ ```bash
100
+ you@yourmachine:~/ph-projects % ph init
101
+
102
+ ? What is the project name? ‣ ChatRoom
103
+ ```
104
+
37
105
  Once the project is created, you will see the following output:
38
106
 
39
107
  ```bash
40
- The installation is done!
41
-
42
- You can start by typing:
43
- cd ChatRoom
108
+ Initialized empty Git repository in /Users/you/ph-projects/ChatRoom/.git/
109
+ The installation is done!
44
110
  ```
45
111
 
46
112
  Navigate to the newly created project directory:
@@ -49,9 +115,9 @@ Navigate to the newly created project directory:
49
115
  cd ChatRoom
50
116
  ```
51
117
 
52
- Once you are in the project directory, now you can run the `ph connect` command to instantiate a local version of the Connect application to start building your document model.
118
+ ## Develop your document model in Connect
53
119
 
54
- Run the following command to start the Connect application:
120
+ Once in the project directory, run the `ph connect` command to start a local instance of the Connect application. This allows you to start your document model specification document.
55
121
 
56
122
  ```bash
57
123
  ph connect
@@ -60,26 +126,36 @@ ph connect
60
126
  The Connect application will start and you will see the following output:
61
127
 
62
128
  ```bash
63
- you@yourmachine:~/Powerhouse/chatroom$ ph run connect
64
-
65
- > Chatroom@1.0.0 connect
66
- > connect --config-file ./powerhouse.config.json
67
-
68
- Watching local document models at '/home/you/Powerhouse/ChatRoom/document-models'...
69
- Watching local document editors at '/home/you/Powerhouse/ChatRoom/editors'...
70
129
  ➜ Local: http://localhost:3000/
130
+ ➜ Network: http://192.168.5.110:3000/
71
131
  ➜ press h + enter to show help
72
132
  ```
73
133
 
74
134
  A new browser window will open and you will see the Connect application. If it doesn't open automatically, you can open it manually by navigating to `http://localhost:3000/` in your browser.
75
135
 
76
- If you don't have a local drive created yet, create one using the Generic Drive Explorer app.
136
+ :::tip
137
+ If your local drive is not present, navigate to Settings in the bottom left corner. Settings > Danger Zone > Clear Storage.
138
+ Clear the storage of your localhost application as it might have an old session cached.
139
+ :::
77
140
 
78
- Open your Local Drive and create a new document model by clicking the `DocumentModel` button in the "New Document" section. The GIF below shows where to click.
141
+ 4. Move into your local drive.
142
+ Create a new document model by clicking the `DocumentModel` button, found in the 'New Document' section at the bottom of the page. Name your document `ChatRoom` (PascalCase, no spaces or hyphens).
79
143
 
144
+ **Pay close attention to capitalization, as it influences code generation.**
80
145
 
81
146
  ![Create New Document Model](./images/ChatRoomConnectApp.gif)
82
147
 
83
- If you followed the steps correctly, you should have an empty document model created called `ChatRoom`.
148
+ If you've followed the steps correctly, you'll have an empty `ChatRoom` document where you can define the **'Document Specifications'**.
149
+
150
+ ## Verify your setup
151
+
152
+ At this point, your project structure should include:
153
+
154
+ - Empty `document-models/`, `editors/`, `processors/`, and `subgraphs/` directories
155
+ - Configuration files: `powerhouse.config.json`, `powerhouse.manifest.json`
156
+ - Package management files: `package.json`, `pnpm-lock.yaml`
157
+ - Build configuration: `tsconfig.json`, `vite.config.ts`, `vitest.config.ts`
158
+
159
+ ## Up next
84
160
 
85
161
  In the next tutorial, you will learn how to design your document model and export it to be later used in your Powerhouse project.
@@ -1,54 +1,100 @@
1
- # Define the chatroom document model
1
+ # Write the document specification
2
2
 
3
- In this tutorial, you will learn how to design your document model and export it to be later used in your Powerhouse project.
4
- If you don't have a document model created yet, have a look at the previous steps of this tutorial to create a new document model.
3
+ :::tip Tutorial Repository
4
+ 📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
5
5
 
6
- Before you start, make sure you have the Connect application running.
6
+ This tutorial step has a corresponding implementation in the repository. After completing this step, your project will have a document model specification with:
7
+ - Document model specification files (`chat-room.json`, `schema.graphql`)
8
+ - Auto-generated TypeScript types and action creators
9
+ - Reducer scaffolding ready for implementation
10
+ :::
11
+
12
+ <details>
13
+ <summary>📖 How to use this tutorial</summary>
14
+
15
+ **Prerequisites**: Complete step 1 and set up the tutorial remote (see previous step).
16
+
17
+ ### Compare your generated code
18
+
19
+ After running `ph generate ChatRoom.phd`, compare with the reference:
20
+
21
+ ```bash
22
+ # Compare all generated files with the reference
23
+ git diff tutorial/main -- document-models/chat-room/
24
+
25
+ # View a specific file from the reference
26
+ git show tutorial/main:document-models/chat-room/schema.graphql
27
+ ```
28
+
29
+ ### Visual comparison with GitHub Desktop
30
+
31
+ After making a commit, use GitHub Desktop for visual diff:
32
+ 1. **Branch** menu → **"Compare to Branch..."**
33
+ 2. Select `tutorial/main`
34
+ 3. Review all file differences in the visual interface
35
+
36
+ See step 1 for detailed GitHub Desktop instructions.
7
37
 
8
- ## Chatroom document model schema
38
+ </details>
9
39
 
10
- We use GraphQL Schema Definition Language (SDL) to define the document model schema. Below, you can see the SDL for the `ChatRoom` document model.
40
+ In this tutorial, you will learn how to define the specifications for a **ChatRoom** document model within the Connect application using its GraphQL schema, and then export the resulting document model specification document for your Powerhouse project.
11
41
 
12
- :::info **The State Schema**
13
- This schema contains the data structure of the document model and the basic operations that can be performed on the document model. For more in depth information please visit [State Schema](/academy/MasteryTrack/DocumentModelCreation/SpecifyTheStateSchema)
42
+ If you don't have a document specification file created yet, have a look at the previous step of this tutorial to create a new document specification.
43
+
44
+ Before you start, make sure you have the Connect application running locally with the command:
45
+
46
+ ```bash
47
+ ph connect
48
+ ```
49
+
50
+ ## ChatRoom document specification
51
+
52
+ Make sure you have named your document model `ChatRoom` (PascalCase, no spaces or hyphens).
53
+ **Pay close attention to capitalization, as it influences code generation.**
54
+
55
+ We use the **GraphQL Schema Definition Language** (SDL) to define the schema for the document model. Below, you can see the SDL for the `ChatRoom` document model.
56
+
57
+ :::info
58
+ This schema defines the **data structure** of the document model and the types involved in its operations. Documents in Powerhouse leverage **event sourcing principles**, where every state transition is represented by an operation. GraphQL input types describe operations, ensuring that user intents are captured effectively.
14
59
  :::
15
60
 
16
- ## State schema (See next steps)
61
+ <details>
62
+ <summary>State schema of our ChatRoom</summary>
17
63
 
18
64
  ```graphql
19
- # Defines a GraphQL type for the state of the chatroom document
65
+ # The state of our ChatRoom
20
66
  type ChatRoomState {
21
- id: OID! # Unique identifier for the chat-room
22
- name: String! # Name of the chat-room
23
- description: String # Optional description of the chat-room
24
- createdAt: DateTime! # Timestamp of when the chat-room was created
25
- createdBy: ID! # Agent ID of the user who created the chat-room
67
+ id: OID! # Unique identifier for the chat-room
68
+ name: String! # Name of the chat-room
69
+ description: String # Optional description of the chat-room
70
+ createdAt: DateTime! # Timestamp of when the chat-room was created
71
+ createdBy: ID! # Agent ID of the user who created the chat-room
26
72
  messages: [Message!]! # List of messages in the chat-room
27
73
  }
28
74
 
29
- # Defines a GraphQL type for the state of a message
75
+ # A single message in the chat-room
30
76
  type Message {
31
- id: OID! # Unique identifier for the message
32
- sender: Sender! # Agent details of the message sender
33
- content: String # Message content
34
- sentAt: DateTime! # Timestamp of when the message was sent
77
+ id: OID! # Unique identifier for the message
78
+ sender: Sender! # Agent details of the message sender
79
+ content: String # Message content
80
+ sentAt: DateTime! # Timestamp of when the message was sent
35
81
  reactions: [Reaction!] # Reactions to the message
36
82
  }
37
83
 
38
- # Defines a GraphQL type for the state of a sender
84
+ # The sender of a message
39
85
  type Sender {
40
- id: ID! # Unique identifier for the sender
86
+ id: ID! # Unique identifier for the sender
41
87
  name: String
42
- avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
88
+ avatarUrl: URL # Allows us to pull the ENS and/or NFT of the person's profile
43
89
  }
44
90
 
45
- # Defines a GraphQL type for the state of a reaction to a message
91
+ # A reaction to a message
46
92
  type Reaction {
47
- type: ReactionType! # Type of reaction (one of the predefined emoji)
48
- reactedBy: [ID!]! # Agent ID of the user who reacted
93
+ type: ReactionType! # Type of reaction (one of the predefined emoji)
94
+ reactedBy: [ID!]! # Agent IDs of users who reacted
49
95
  }
50
96
 
51
- # Defines the various predefined emojis to react to a message
97
+ # The predefined emoji reactions
52
98
  enum ReactionType {
53
99
  THUMBS_UP
54
100
  THUMBS_DOWN
@@ -56,38 +102,72 @@ enum ReactionType {
56
102
  HEART
57
103
  CRY
58
104
  }
59
- ```
60
105
 
61
- ## Operations schema (See next steps)
106
+ type ChatRoomState {
107
+ id: OID!
108
+ name: String!
109
+ description: String
110
+ createdAt: DateTime
111
+ createdBy: ID
112
+ messages: [Message!]!
113
+ }
62
114
 
63
- ```graphql
64
- # add_message
115
+ type Message {
116
+ id: OID!
117
+ sender: Sender!
118
+ content: String
119
+ sentAt: DateTime!
120
+ reactions: [Reaction!]
121
+ }
122
+
123
+ type Sender {
124
+ id: ID!
125
+ name: String
126
+ avatarUrl: URL
127
+ }
128
+
129
+ type Reaction {
130
+ type: ReactionType!
131
+ reactedBy: [ID!]!
132
+ }
133
+
134
+ enum ReactionType {
135
+ THUMBS_UP
136
+ THUMBS_DOWN
137
+ LAUGH
138
+ HEART
139
+ CRY
140
+ }
141
+
142
+ # messages
65
143
 
66
144
  input AddMessageInput {
67
- messageId: OID! # ID of the message that is being added
68
- sender: SenderInput! # ID of the user sending the message
69
- content: String! # Content of the message
145
+ messageId: OID!
146
+ sender: SenderInput!
147
+ content: String!
70
148
  sentAt: DateTime!
71
149
  }
72
150
 
73
151
  input SenderInput {
74
- id: ID! # Unique identifier for the sender
152
+ id: ID!
75
153
  name: String
76
- avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
154
+ avatarUrl: URL
77
155
  }
78
156
 
79
157
  input AddEmojiReactionInput {
80
- messageId: OID! # ID of the message to which the reaction is being added
81
- reactedBy: ID! # ID of the user adding the reaction
82
- type: ReactionType! # Type of the reaction (emoji)
158
+ messageId: OID!
159
+ reactedBy: ID!
160
+ type: ReactionType!
83
161
  }
84
162
 
85
163
  input RemoveEmojiReactionInput {
86
- messageId: OID! # ID of the message to which the reaction is being removed
87
- senderId: ID! # ID of the user that is removing the reaction
88
- type: ReactionType! # Type of the reaction (emoji)
164
+ messageId: OID!
165
+ senderId: ID!
166
+ type: ReactionType!
89
167
  }
90
168
 
169
+ # settings
170
+
91
171
  input EditChatNameInput {
92
172
  name: String
93
173
  }
@@ -97,55 +177,154 @@ input EditChatDescriptionInput {
97
177
  }
98
178
  ```
99
179
 
100
- ## Define the document model
180
+ </details>
101
181
 
102
- To be able to define the document model, you need to open the Chatroom document model editor in Connect.
182
+ <details>
183
+ <summary>Messages Module: Operations schema of our ChatRoom Messages</summary>
103
184
 
104
- The steps below show you how to do this:
185
+ ```graphql
186
+ # Add a new message to the chat-room
187
+ input AddMessageInput {
188
+ messageId: OID! # ID of the message being added
189
+ sender: SenderInput! # Sender information
190
+ content: String! # Content of the message
191
+ sentAt: DateTime! # Timestamp when the message was sent
192
+ }
105
193
 
106
- 1. In the Connect application, click on the `ChatRoom` document model you've created in the previous step, to open the document model editor.
107
- 2. You'll be welcomed with a form to fill, this is metadata about the document model, fill in the details in the fields.
194
+ # Sender information for a message
195
+ input SenderInput {
196
+ id: ID! # Unique identifier for the sender
197
+ name: String
198
+ avatarUrl: URL # Avatar URL for the sender
199
+ }
108
200
 
109
- In the `Document Type` field, type `powerhouse/chat-room`. This defines the new type of document that will be created with this document model.
201
+ # Add an emoji reaction to a message
202
+ input AddEmojiReactionInput {
203
+ messageId: OID! # ID of the message to react to
204
+ reactedBy: ID! # ID of the user adding the reaction
205
+ type: ReactionType! # Type of the reaction (emoji)
206
+ }
110
207
 
111
- ![Chatroom Document Model Form Metadata](image-2.png)
208
+ # Remove an emoji reaction from a message
209
+ input RemoveEmojiReactionInput {
210
+ messageId: OID! # ID of the message to remove reaction from
211
+ senderId: ID! # ID of the user removing the reaction
212
+ type: ReactionType! # Type of the reaction (emoji)
213
+ }
112
214
 
113
- 3. In the code editor, you can see the SDL for the document model. Replace the existing SDL with the SDL defined in the [State Schema](#state-schema) section above. Only copy and paste the types, leaving the inputs for the next step. You can however already press 'Sync with schema' button to set the initial state of your document model based on your Schema Definition Language. Verify that your Global State Initial Value looks like this.
114
215
 
115
- ```json
116
- {
117
- "id": "",
118
- "name": "",
119
- "description": null,
120
- "createdAt": null,
121
- "createdBy": null,
122
- "messages": []
123
- }
124
- ```
216
+ </details>
125
217
 
126
- 4. Below the editor, there is an input field **'Add module'**. You need to create and name a module that the input operations will be added to. In this case, we will name the module **'general_operations'**. Press enter.
127
- 5. Now there is a new field, called **'Add operation'**. Here you will have to add each input operation to the module, one by one.
128
- 6. Inside the **'Add operation'** field, type **'ADD_MESSAGE'** and press enter. A small editor will appear under with an empty input type that you have to fill. Copy the first input type from the [Operations Schema](#operations-schema) section and paste it in the editor. The editor should look like this:
129
218
 
130
- ```graphql
131
- input AddMessageInput {
132
- messageId: OID!
133
- sender: SenderInput!
134
- content: String!
135
- sentAt: DateTime!
136
- }
219
+ <details>
220
+ <summary>Settings Module: Operations schema of our ChatRoom Settings</summary>
137
221
 
138
- input SenderInput {
139
- id: ID! # Unique identifier for the sender
222
+ # Edit the chat-room name
223
+ input EditChatNameInput {
140
224
  name: String
141
- avatarUrl: URL # Allows us to pull the ENS and/or nft of the persons profile
225
+ }
226
+
227
+ # Edit the chat-room description
228
+ input EditChatDescriptionInput {
229
+ description: String
142
230
  }
143
231
  ```
144
232
 
145
- 7. Repeat step 6 for the other input operations based on the [Operations Schema](#operations-schema). If you noticed, you only need to add the name `(ADD_EMOJI_REACTION, EDIT_CHAT_NAME, etc)` of the operation without the `input` suffix. Then it will be generated once you press enter.
146
- 8. Let's just add a couple more reducer exceptions to the `ADD_MESSAGE` operation which we'll be using later to avoid empty messages or messages exceeding a maximum lenght. Add `MessageContentCannotBeEmpty` and `MessageContentExceedsTheMaximumLenght` to the reducer exceptions of `ADD_MESSAGE`
147
- 9. Once you have added all the input operations, click on the `Export` button, at the top right of the editor, to save the document model on your local machine. Ideally you already save your file in the root of your powerhouse project on your machine.
233
+ </details>
234
+
235
+ ## Define the document model specification
236
+
237
+ To define the document model, you need to open the document model editor in Connect.
238
+
239
+ ### Steps to define your document model:
240
+
241
+ 1. In the Connect application, click on **'ChatRoom' Document** to open the document model specification editor.
242
+
243
+ 2. You'll be presented with a form to fill in metadata about the document model. Fill in the details in the respective fields.
244
+
245
+ In the **Document Type** field, type `powerhouse/chat-room` (lowercase with hyphen). This defines the new type of document that will be created with this document model specification.
246
+
247
+ ![Chatroom Document Model Form Metadata](image-2.png)
248
+
249
+ 3. In the code editor, you can see the SDL for the document model. Replace the existing SDL template with the SDL defined in the **State Schema** section above. Only copy and paste the types, leaving the inputs for the next step. You can press the 'Sync with schema' button to set the initial state of your document model based on your Schema Definition Language.
250
+
251
+ 4. Verify that your **Global State Initial Value** looks like this:
252
+
253
+ ```json
254
+ {
255
+ "name": "",
256
+ "description": null,
257
+ "createdAt": null,
258
+ "createdBy": null,
259
+ "messages": []
260
+ }
261
+ ```
262
+
263
+ 5. Below the editor, find the input field `Add module`. Create and name a module for organizing your input operations. Name the module `general_operations`. Press enter.
264
+
265
+ 6. Now there is a new field, called `Add operation`. Here you will add each input operation to the module, one by one.
266
+
267
+ 7. Inside the `Add operation` field, type `ADD_MESSAGE` and press enter. A small editor will appear underneath with an empty input type that you need to fill. Copy the `AddMessageInput` and `SenderInput` from the **Operations Schema** section and paste them in the editor:
268
+
269
+ ```graphql
270
+ input AddMessageInput {
271
+ messageId: OID!
272
+ sender: SenderInput!
273
+ content: String!
274
+ sentAt: DateTime!
275
+ }
276
+
277
+ input SenderInput {
278
+ id: ID!
279
+ name: String
280
+ avatarUrl: URL
281
+ }
282
+ ```
283
+
284
+ 8. Repeat step 7 for the other input operations: `ADD_EMOJI_REACTION`, `REMOVE_EMOJI_REACTION`, `EDIT_CHAT_NAME`, and `EDIT_CHAT_DESCRIPTION`. Note that you only need to add the operation name (e.g., `ADD_EMOJI_REACTION`) without the `Input` suffix—it will be generated automatically.
285
+
286
+ 9. Add reducer exceptions to the `ADD_MESSAGE` operation for validation: `MessageContentCannotBeEmpty` and `MessageContentExceedsTheMaximumLength`. These will be used later to validate messages.
287
+
288
+ 10. Once you have added all the input operations, click the `Export` button at the top right of the editor to save the document model specification to your local machine. Save the file in the root of your Powerhouse project.
148
289
 
149
290
  Check the screenshot below to verify the complete implementation:
150
291
 
151
292
  ![Chatroom Document Model](image-3.png)
293
+
294
+ ## Verify your document model generation
295
+
296
+ After running `ph generate ChatRoom.phd`, your project should have the following structure in `document-models/chat-room/`:
297
+
298
+ ```
299
+ document-models/chat-room/
300
+ ├── gen/ # Auto-generated code (don't edit)
301
+ │ ├── actions.ts
302
+ │ ├── creators.ts # Action creator functions
303
+ │ ├── types.ts # TypeScript type definitions
304
+ │ ├── reducer.ts
305
+ │ └── general-operations/
306
+ │ └── operations.ts # Operation type definitions
307
+ ├── src/ # Your custom implementation
308
+ │ ├── reducers/
309
+ │ │ └── general-operations.ts # Reducer functions (to implement next)
310
+ │ └── tests/
311
+ │ └── general-operations.test.ts # Test file scaffolding
312
+ ├── chat-room.json # Document model specification
313
+ └── schema.graphql # GraphQL schema
314
+ ```
315
+
316
+ ### Compare with reference
317
+
318
+ Verify your generated files match the expected structure:
319
+
320
+ ```bash
321
+ # Compare your generated files with the reference
322
+ git diff tutorial/main -- document-models/chat-room/
323
+
324
+ # List what was generated in the reference
325
+ git ls-tree -r --name-only tutorial/main document-models/chat-room/
326
+ ```
327
+
328
+ ## Up next: Reducers
329
+
330
+ In the next step, you'll learn how to implement the runtime logic that will use the `ChatRoom` document model specification you've just created and exported.