Files
scrabble-game/pkg/fbs/scrabble.fbs
T
Ilia Denisov 408da3f201
Tests · Go / test (push) Successful in 8s
Tests · Integration / integration (push) Successful in 11s
Tests · Go / test (pull_request) Successful in 6s
Tests · Integration / integration (pull_request) Successful in 10s
Stage 6: gateway edge (Connect/FlatBuffers over h2c, platform/email/guest auth, sessions, rate-limit, admin passthrough, live push bridge)
New public ingress and the first network edge. Framework + a vertical slice of
operations end-to-end; remaining ops reuse the same transcode pattern in Stage 7.

Contracts (new module scrabble/pkg):
- push.proto (backend->gateway gRPC server-stream) + scrabble.fbs (FlatBuffers
  edge payloads), committed generated Go; buf/flatc Makefiles (dev-time codegen).

Backend:
- REST handlers on the /api/v1 groups: internal session endpoints
  (telegram/guest/email login -> mint, resolve, revoke) and the user slice
  (profile, submit_play, state, lobby enqueue/poll, chat).
- internal/notify in-process Publisher hub + internal/pushgrpc gRPC server
  (BACKEND_GRPC_ADDR) streaming your_turn/opponent_moved/chat/nudge/match_found;
  emission in game.commit, social, matchmaker.
- migration 00005 accounts.is_guest; guests are durable rows excluded from stats;
  ProvisionGuest; email-as-login (RequestLoginCode/LoginWithCode).

Gateway (new module scrabble/gateway):
- Connect Gateway service over h2c (Execute + Subscribe), FlatBuffers<->JSON
  transcode registry, Telegram initData HMAC validator (seam), session cache,
  token-bucket rate limiter (3 classes), push fan-out hub, backend REST + push
  gRPC client, admin Basic-Auth reverse proxy.

go.work: use ./pkg, ./gateway + replace scrabble/pkg. CI: gateway/**, pkg/**
path filters; unit build/vet/test span all three modules. Docs (PLAN,
ARCHITECTURE, FUNCTIONAL+ru, TESTING, READMEs) updated; gateway/pkg unit tests +
guest/email-login integration tests.
2026-06-02 22:38:24 +02:00

206 lines
4.7 KiB
Plaintext

// FlatBuffers payloads for the client <-> gateway edge transport (Stage 6).
//
// Every request and response that rides inside the Connect envelope
// (gateway/proto/edge) `payload` field, and every push Event payload, is one of
// these tables. They are the binary wire contract shared with the UI, which
// generates TypeScript from this same schema (Stage 7). A single namespace keeps
// nested tables (GameView inside MoveResult / MatchResult) free of
// cross-namespace imports. Keep this schema and the backend JSON DTOs in lockstep
// — the gateway transcodes one to the other.
//
// Generate Go with `make fbs` (flatc, version-pinned). The committed output lives
// in fbs/scrabblefb/.
namespace scrabblefb;
// --- shared building blocks ---
// TileRecord is one placed (or to-place) tile: its board coordinate, the concrete
// letter ("?" when read from a hand for a blank) and whether it came from a blank.
table TileRecord {
row:int;
col:int;
letter:string;
blank:bool;
}
// SeatView is one seat's public standing in a game.
table SeatView {
seat:int;
account_id:string;
score:int;
hints_used:int;
is_winner:bool;
}
// GameView is the shared (non-private) game summary.
table GameView {
id:string;
variant:string;
dict_version:string;
status:string;
players:int;
to_move:int;
turn_timeout_secs:int;
move_count:int;
end_reason:string;
seats:[SeatView];
}
// MoveRecord is one decoded move (a committed play, or a hint preview).
table MoveRecord {
player:int;
action:string;
dir:string;
main_row:int;
main_col:int;
tiles:[TileRecord];
words:[string];
count:int;
score:int;
total:int;
}
// --- auth (unauthenticated) ---
// TelegramLoginRequest carries the platform launch data; the gateway validates
// its HMAC before forwarding the extracted identity to the backend.
table TelegramLoginRequest {
init_data:string;
}
// GuestLoginRequest bootstraps an ephemeral guest session. locale is an optional
// preferred-language hint.
table GuestLoginRequest {
locale:string;
}
// EmailRequestRequest asks the backend to send a login confirm-code to email.
table EmailRequestRequest {
email:string;
}
// EmailLoginRequest logs in (or provisions) the account owning email, verifying
// the confirm-code.
table EmailLoginRequest {
email:string;
code:string;
}
// Session is the minted credential returned by every auth operation.
table Session {
token:string;
user_id:string;
is_guest:bool;
display_name:string;
}
// Ack is a simple success acknowledgement (e.g. an email-code request).
table Ack {
ok:bool;
}
// --- profile (authenticated) ---
// Profile is the authenticated account's own profile view.
table Profile {
user_id:string;
display_name:string;
preferred_language:string;
time_zone:string;
hint_balance:int;
block_chat:bool;
block_friend_requests:bool;
is_guest:bool;
}
// --- game (authenticated) ---
// SubmitPlayRequest places tiles in a direction on the player's turn.
table SubmitPlayRequest {
game_id:string;
dir:string;
tiles:[TileRecord];
}
// MoveResult is the outcome of a committed move: the move and the post-move game.
table MoveResult {
move:MoveRecord;
game:GameView;
}
// StateRequest asks for the requesting player's view of a game.
table StateRequest {
game_id:string;
}
// StateView is a player's view of a game: the shared summary plus their private
// rack, the bag size and their remaining hint budget.
table StateView {
game:GameView;
seat:int;
rack:[string];
bag_len:int;
hints_remaining:int;
}
// --- lobby (authenticated) ---
// EnqueueRequest joins the per-variant auto-match pool.
table EnqueueRequest {
variant:string;
}
// MatchResult reports whether the caller has been paired into a game yet.
table MatchResult {
matched:bool;
game:GameView;
}
// --- chat (authenticated) ---
// ChatPostRequest posts a per-game chat message.
table ChatPostRequest {
game_id:string;
body:string;
}
// ChatMessage is one stored chat message or nudge.
table ChatMessage {
id:string;
game_id:string;
sender_id:string;
kind:string;
body:string;
created_at_unix:long;
}
// --- push event payloads ---
// YourTurnEvent signals that it is now the recipient's turn.
table YourTurnEvent {
game_id:string;
deadline_unix:long;
}
// OpponentMovedEvent summarises a move another seat just committed; the client
// refetches the full state.
table OpponentMovedEvent {
game_id:string;
seat:int;
action:string;
score:int;
total:int;
}
// NudgeEvent signals that a player nudged the recipient.
table NudgeEvent {
game_id:string;
from_user_id:string;
}
// MatchFoundEvent signals that an auto-match pairing (or robot substitution)
// started a game the recipient is seated in.
table MatchFoundEvent {
game_id:string;
}