---
tags: RealMQ
---
# Chat Demo Tech Spec
## API
```
POST /accounts
Request:
{
"username": "string",
"password": "string"
}
Response:
{
"id": "uuid.v4",
"username": "string"
}
```
```
POST /auth
Request
{
"username": "string",
"password": "string"
}
Response
{
"apiToken": "string",
"rtmToken": "string"
}
```
```
GET /chats
Response
{
"items": [
{
"id": "string",
"type": "direct|group",
"name": "string",
"channels": {
"messages": "id"
"status": "id"
},
}
],
}
```
```
GET /chats/{id}
Response
{
"id": "string",
"type": "direct|group",
"name": "string",
"members": [
{
"id": "string",
"username": "string",
}
],
"channels": {
"messages": "id"
"status": "id"
},
}
```
```
POST /chats
Request
{
"type": "direct",
"members": [
{ "id": "string" }
],
}
```
## RTM
Message (Text)
```
{
"from": {
"id": "string",
"username": "string",
},
"sentAt": "(new Date()).toIsoString()",
"parts": [
{
"type": "text/plain; charset=utf-8",
"content": "..."
}
]
}
```
## Frontend
- create-react-app
## Backend
### Tech Stack
- OpenAPI 3.0
- express + middleware
### Business Logic
- Account = User
- username unique
- On startup: ensure lobby chat exists
- On account registration: subscribe user to lobby chat
- On chat creation:
- direct chat
- add creator to members list
- member list is forced to length === 0
- create channels
- subscribe members