Maia Sequence & Activity Diagrams
For anyone looking to make their own AI-based MSME support tool with a WhatsApp front-end, here are sequence and activity diagrams for both the basic components (responding to user messages) and additional components (system-generated tips and follow-up) of Maia. I've provided the mermaid code, just paste this text into any free tool like mermaid.live to see the diagrams, and you can adapt them to your own case.
Core Components - Sequence Diagram
sequenceDiagram
participant User
participant WhatsAppProvider as WhatsApp Business Provider
participant BackEnd as Back-End Automation
participant ThreadManagement as Thread Management
participant RAG as Retrieval Augmented Generation
participant LLM as Large Language Model
participant DataStorage as Data Storage
Note over User,WhatsAppProvider: WhatsApp Front-end
Note over WhatsAppProvider,BackEnd: Provider-Specific Integration
Note over BackEnd: Automation & Orchestration
Note over ThreadManagement: Manage Conversations & Threads
Note over RAG: Retrieve & Augment Context
Note over LLM: Generate Responses
Note over DataStorage: Data Storage
User->>WhatsAppProvider: Sends message
WhatsAppProvider->>BackEnd: Sends message
alt First-time user
BackEnd->>User: Sends onboarding questions
User->>WhatsAppProvider: Sends responses
WhatsAppProvider->>BackEnd: Sends responses
BackEnd->>BackEnd: Initialize user
else Existing user
BackEnd->>BackEnd: Sanitize message
BackEnd->>ThreadManagement: Add message to thread
ThreadManagement-->>BackEnd: Confirmation
BackEnd->>RAG: Request context
RAG-->>BackEnd: Requested context
BackEnd->>LLM: Generate response
LLM-->>BackEnd: Response
BackEnd->>BackEnd: Sanitize response
BackEnd->>WhatsAppProvider: Send response
WhatsAppProvider->>User: Sends response
end
BackEnd->>DataStorage: Stream all data
Additional Components - Sequence Diagram
sequenceDiagram
participant User
participant WhatsAppProvider as WhatsApp Business Provider
participant BackEnd as Back-End Automation
participant RAG as Retrieval Augmented Generation
participant LLM as Large Language Model
participant DataStorage as Data Storage
opt Tip Message Flow – Time Trigger initiates tip generation
BackEnd->>RAG: Request tip context/resources
RAG-->>BackEnd: Provide tip context/resources
BackEnd->>LLM: Generate tip using context
LLM-->>BackEnd: Return generated tip
BackEnd->>WhatsAppProvider: Send tip message to user
WhatsAppProvider->>User: Deliver tip message
end
opt Follow-Up Message Flow – Time Trigger initiates follow-up generation
BackEnd->>DataStorage: Query user's chat history
DataStorage-->>BackEnd: Return chat history
BackEnd->>LLM: Generate follow-up message using chat history
LLM-->>BackEnd: Return follow-up message
BackEnd->>WhatsAppProvider: Send follow-up message to user
WhatsAppProvider->>User: Deliver follow-up message
end
BackEnd->>DataStorage: Stream all data
New User - Activity Diagram
flowchart TD
A([Start])
B[User sends message via WhatsApp]
C[WhatsApp Business Provider receives message]
D[Back-End receives message]
E{Is user new?}
%% Branch for existing users
F[Existing user – proceed with normal flow]
%% Branch for new user onboarding
G[Determine user's country from phone number]
H["Ask user for economic activity<br>(options based on country)"]
I[User replies with economic activity]
J["Initialize user profile<br>(store country, activity, system variables)"]
K[Send country-sector specific welcome messages]
L([End])
A --> B
B --> C
C --> D
D --> E
E -- "No" --> F
F --> L
E -- "Yes" --> G
G --> H
H --> I
I --> J
J --> K
K --> L
Returning User - Activity Diagram
flowchart TD
Start(["Start: Existing User<br>Message Received"])
A["User sends message"]
B["WhatsApp Provider<br>forwards message<br>to Back-End"]
X{"Can user receive<br>response?"}
Y["Send invalid user<br>template"]
C{"Is message audio?"}
D["Transcribe audio<br>message"]
E["Sanitize<br>transcript"]
F{"Is message image?"}
G["Fetch image and<br>accompanying text"]
H["Sanitize accompanying<br>text"]
I["Sanitize text (or button<br>press)"]
J["Determine sanitized<br>message content"]
K["Check if user has an<br>existing thread"]
L{"Thread exists?"}
M["If not, create new<br>thread"]
N1["Assign LLM instructions<br>and RAG resources<br>based on country and sector"]
N["Add sanitized content,<br>image, RAG, and other<br>context to thread"]
O["Thread Management<br>confirms thread update"]
P["Request context<br>from RAG"]
Q["Receive context<br>from RAG"]
R["Run LLM on thread<br>with RAG context"]
S["Poll model run and<br>fetch response"]
T["Sanitize generated<br>response"]
U["Send response via<br>WhatsApp Provider"]
V["User receives<br>response"]
End(["End"])
Start --> A
A --> B
B --> X
X -- "Yes" --> C
X -- "No" --> Y
Y --> End
C -- "Yes" --> D
D --> E
E --> J
C -- "No" --> F
F -- "Yes" --> G
G --> H
H --> J
F -- "No" --> I
I --> J
J --> K
K --> L
L -- "Yes" --> N1
L -- "No" --> M
M --> N1
N1 --> N
N --> O
O --> P
P --> Q
Q --> R
R --> S
S --> T
T --> U
U --> V
V --> End
Weekly Tips - Activity Diagram
flowchart TD
A[Start Tip Message Process: Time Trigger]
B[Request tip context/resources from RAG]
C[Receive tip context/resources from RAG]
D[Generate tip using LLM]
E[Send tip message to WhatsApp Provider]
F[Deliver tip message to User]
G{Did user reply?}
H[Include tip as additional context]
I[Begin existing user reply process]
J[End Process]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G -- Yes --> H
H --> I
G -- No --> J
Follow-up Messages - Activity Diagram
flowchart TD
A[Start Follow-Up Message Process: Time Trigger]
B[Query user's chat history from Data Storage]
C[Receive user's chat history]
D[Generate follow-up message using LLM with chat history]
E[Send follow-up message to WhatsApp Provider]
F[Deliver follow-up message to User]
G{Did user reply?}
H[Include follow-up as additional context]
I[Begin existing user reply process]
J[End Process]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G -- Yes --> H
H --> I
G -- No --> J