super simple minimal chat app for learning
| docs | ||
| pseudocode | ||
| public | ||
| .gitignore | ||
| curl_get.sh | ||
| curl_send_message.sh | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| README.md | ||
| sqlite-create-tables.sql | ||
grugchat
super simple minimal chat app for learning
how to run
- be on linux (for now)
- ensure dependencies are installed, here for archlinux:
- go
- sqlite
- git (for cloning the repo, sorry no binary releases yet)
- clone the repo
- cd into the repo
- initialize the sqlite db file:
- sqlite3 messages.sqlite < sqlite-create-tables.sql
- go mod tidy
- go build
- ./grugchat
- open browser to localhost:8080 or whatever port you configure
Initial scope:
frontend:
- 1 page, html/css/js. Rooms on the left sidebar, Chatwindow for the rest, chatwindow features a textbox + send button on the bottom.
- onload: get rooms, populate sidebar. get messages for the first room, populate chatbox.
- subscribe to sse.
- on changing room: new page, get that rooms messages, subscribe to that sse
backend:
- no auth, every user is "anonymous".
GET:
- /api/rooms to get a list of rooms (can even be hardcoded at first)
- /api/rooms/:roomID/messages to get the message history of a room
- /api/rooms/:roomID/sse to "subscribe" to a rooms messages per server-sent events
POST:
- /api/rooms/:roomID/messages with super simple "content" to send a chat message
database:
- rooms with id (index) and name
- messages, proper relation to rooms so each message is matched to the room its in:
id - primary key
room_id - foreign key
content - the text
tiestamp - needed for ordering
Notes on the "backend":
try to keep "business logic" seperated from the communications and storage layers.
We'll try to have a "handler" that converts HTTP requests into the proper Go structs and passes them on.
then we'll have a "service" that implements the actual logic - go structs go in, go structs come out (either to the client or the storage layer).
third, the storage layer accepts Go and saves/loads SQL.