Stage 6: gateway edge (Connect/FlatBuffers over h2c, platform/email/guest auth, sessions, rate-limit, admin passthrough, live push bridge)
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

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.
This commit is contained in:
Ilia Denisov
2026-06-02 22:38:24 +02:00
parent 104eb2a978
commit 408da3f201
98 changed files with 8134 additions and 57 deletions
@@ -0,0 +1,150 @@
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: edge/v1/edge.proto
// Package scrabble.edge.v1 is the client <-> gateway Connect-RPC contract. It is
// deliberately minimal (ARCHITECTURE.md §2): a single unary Execute that routes
// by message_type, and a server-streaming Subscribe for the in-app live channel.
// The actual request/response and event bodies travel as FlatBuffers bytes in the
// payload fields (pkg/fbs). The session token rides in the Authorization header,
// not the envelope (no per-request signing — ARCHITECTURE.md §3).
package edgev1connect
import (
connect "connectrpc.com/connect"
context "context"
errors "errors"
http "net/http"
v1 "scrabble/gateway/proto/edge/v1"
strings "strings"
)
// This is a compile-time assertion to ensure that this generated file and the connect package are
// compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of connect newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of connect or updating the connect
// version compiled into your binary.
const _ = connect.IsAtLeastVersion1_13_0
const (
// GatewayName is the fully-qualified name of the Gateway service.
GatewayName = "scrabble.edge.v1.Gateway"
)
// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
// GatewayExecuteProcedure is the fully-qualified name of the Gateway's Execute RPC.
GatewayExecuteProcedure = "/scrabble.edge.v1.Gateway/Execute"
// GatewaySubscribeProcedure is the fully-qualified name of the Gateway's Subscribe RPC.
GatewaySubscribeProcedure = "/scrabble.edge.v1.Gateway/Subscribe"
)
// GatewayClient is a client for the scrabble.edge.v1.Gateway service.
type GatewayClient interface {
// Execute runs one unary operation identified by message_type. Auth operations
// (auth.*) are unauthenticated and return a minted session; all others require
// a valid session token in the Authorization header.
Execute(context.Context, *connect.Request[v1.ExecuteRequest]) (*connect.Response[v1.ExecuteResponse], error)
// Subscribe opens the in-app live-event stream for the authenticated session.
Subscribe(context.Context, *connect.Request[v1.SubscribeRequest]) (*connect.ServerStreamForClient[v1.Event], error)
}
// NewGatewayClient constructs a client for the scrabble.edge.v1.Gateway service. By default, it
// uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and sends
// uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() or
// connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewGatewayClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) GatewayClient {
baseURL = strings.TrimRight(baseURL, "/")
gatewayMethods := v1.File_edge_v1_edge_proto.Services().ByName("Gateway").Methods()
return &gatewayClient{
execute: connect.NewClient[v1.ExecuteRequest, v1.ExecuteResponse](
httpClient,
baseURL+GatewayExecuteProcedure,
connect.WithSchema(gatewayMethods.ByName("Execute")),
connect.WithClientOptions(opts...),
),
subscribe: connect.NewClient[v1.SubscribeRequest, v1.Event](
httpClient,
baseURL+GatewaySubscribeProcedure,
connect.WithSchema(gatewayMethods.ByName("Subscribe")),
connect.WithClientOptions(opts...),
),
}
}
// gatewayClient implements GatewayClient.
type gatewayClient struct {
execute *connect.Client[v1.ExecuteRequest, v1.ExecuteResponse]
subscribe *connect.Client[v1.SubscribeRequest, v1.Event]
}
// Execute calls scrabble.edge.v1.Gateway.Execute.
func (c *gatewayClient) Execute(ctx context.Context, req *connect.Request[v1.ExecuteRequest]) (*connect.Response[v1.ExecuteResponse], error) {
return c.execute.CallUnary(ctx, req)
}
// Subscribe calls scrabble.edge.v1.Gateway.Subscribe.
func (c *gatewayClient) Subscribe(ctx context.Context, req *connect.Request[v1.SubscribeRequest]) (*connect.ServerStreamForClient[v1.Event], error) {
return c.subscribe.CallServerStream(ctx, req)
}
// GatewayHandler is an implementation of the scrabble.edge.v1.Gateway service.
type GatewayHandler interface {
// Execute runs one unary operation identified by message_type. Auth operations
// (auth.*) are unauthenticated and return a minted session; all others require
// a valid session token in the Authorization header.
Execute(context.Context, *connect.Request[v1.ExecuteRequest]) (*connect.Response[v1.ExecuteResponse], error)
// Subscribe opens the in-app live-event stream for the authenticated session.
Subscribe(context.Context, *connect.Request[v1.SubscribeRequest], *connect.ServerStream[v1.Event]) error
}
// NewGatewayHandler builds an HTTP handler from the service implementation. It returns the path on
// which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewGatewayHandler(svc GatewayHandler, opts ...connect.HandlerOption) (string, http.Handler) {
gatewayMethods := v1.File_edge_v1_edge_proto.Services().ByName("Gateway").Methods()
gatewayExecuteHandler := connect.NewUnaryHandler(
GatewayExecuteProcedure,
svc.Execute,
connect.WithSchema(gatewayMethods.ByName("Execute")),
connect.WithHandlerOptions(opts...),
)
gatewaySubscribeHandler := connect.NewServerStreamHandler(
GatewaySubscribeProcedure,
svc.Subscribe,
connect.WithSchema(gatewayMethods.ByName("Subscribe")),
connect.WithHandlerOptions(opts...),
)
return "/scrabble.edge.v1.Gateway/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case GatewayExecuteProcedure:
gatewayExecuteHandler.ServeHTTP(w, r)
case GatewaySubscribeProcedure:
gatewaySubscribeHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedGatewayHandler returns CodeUnimplemented from all methods.
type UnimplementedGatewayHandler struct{}
func (UnimplementedGatewayHandler) Execute(context.Context, *connect.Request[v1.ExecuteRequest]) (*connect.Response[v1.ExecuteResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("scrabble.edge.v1.Gateway.Execute is not implemented"))
}
func (UnimplementedGatewayHandler) Subscribe(context.Context, *connect.Request[v1.SubscribeRequest], *connect.ServerStream[v1.Event]) error {
return connect.NewError(connect.CodeUnimplemented, errors.New("scrabble.edge.v1.Gateway.Subscribe is not implemented"))
}