Phase 1 MVP: gateway, CRUD handlers, frontend components

Backend:
- WebSocket gateway (hub, client, events) with fanout broadcast
- Server CRUD handlers (create, list, get, update, delete)
- Channel CRUD handlers (create, list, get, update, delete)
- Message CRUD handlers (list with cursor pagination, create, update, delete)
- cmd/migrate standalone migration CLI (up/down)
- cmd/server wired to all handlers + WebSocket + static file serving

Frontend:
- Zustand stores: auth, server, channel, message, websocket
- API client with fetch wrapper
- Terminal-styled components: Layout, LoginForm, ChatArea, ChannelList, ServerBar, MemberList
- React Router with login and main routes
- Gruvbox dark palette throughout

Ops:
- Docker Compose with app service (multi-stage build)
- Caddyfile with WebSocket upgrade support
- Makefile for common tasks
This commit is contained in:
2026-06-26 14:47:29 -04:00
parent aa7854aee2
commit bb5a56816b
32 changed files with 2310 additions and 339 deletions
+50
View File
@@ -0,0 +1,50 @@
package gateway
import "encoding/json"
// Event type constants.
const (
EventMessageCreate = "MESSAGE_CREATE"
EventMessageUpdate = "MESSAGE_UPDATE"
EventMessageDelete = "MESSAGE_DELETE"
EventChannelCreate = "CHANNEL_CREATE"
EventChannelUpdate = "CHANNEL_UPDATE"
EventChannelDelete = "CHANNEL_DELETE"
EventMemberAdd = "SERVER_MEMBER_ADD"
EventMemberRemove = "SERVER_MEMBER_REMOVE"
EventPresenceUpdate = "PRESENCE_UPDATE"
EventTypingStart = "TYPING_START"
)
// Event represents a WebSocket event sent to clients.
type Event struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
// MarshalJSON implements custom JSON marshaling for Event.
func (e Event) MarshalJSON() ([]byte, error) {
type eventAlias struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
return json.Marshal(eventAlias{
Type: e.Type,
Data: e.Data,
})
}
// UnmarshalJSON implements custom JSON unmarshaling for Event.
func (e *Event) UnmarshalJSON(data []byte) error {
type eventAlias struct {
Type string `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
var raw eventAlias
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
e.Type = raw.Type
e.Data = raw.Data
return nil
}