Architecture

Process model

main.go loads .env, reads database and port settings, opens and pings the MySQL connection, ensures the user profile table exists, registers the default net/http routes, and starts http.ListenAndServe.

Handlers receive a shared *sql.DB through handlers.NewUserAPI. Authentication is cookie-based and sessions are held in process memory; a restart invalidates every session.

Request domains

The handler package is split by domain:

  • User.go — registration, login, profiles, account email, and user lookup;

  • Servers.go and Channels.go — servers, roles, channels, invites, and server messages;

  • Friends.go and Conversations.go — friend relationships and direct or group conversations;

  • Attachments.go and Reactions.go — message-associated features;

  • Websocket.go — live channel and conversation connections;

  • Admin.go and Reports.go — account standing and moderation;

  • Email.go — verification and password reset messages.

The frontend calls these handlers with fetch and opens WebSocket connections for live message updates.