How gstones/moke-kit works
Main Components
• Application Layer – Represent the application entry point and the dependency injection system that ties together all components (see the fxmain directory and the usage of uber/fx).
• Server Layer – Comprises multiple server types:
• gRPC Server (server/internal/srpc)
• HTTP Gateway (server for grpc-gateway)
• TCP, WebSocket, and KCP servers (using the zinx framework within server/internal/zinx)
• Middleware Layer – Contains components such as:
• Authentication (server middlewares and related auth files in 3rd/auth)
• Rate Limiting, Logging, Recovery, and OpenTelemetry (implemented in server middlewares & sfx)
• Storage Layer – Includes:
• Database functionality (GORM in orm/pkg/ofx and MongoDB in orm/nosql/mongo)
• Cache support (Redis cache and Dragonfly support)
• Message Queue (mostly using NATS, with the mq directory containing various implementations and adapters)
• Integration Layer – Houses external integrations:
• IAP (in 3rd/iap for purchase receipt verification)
• Agones (in 3rd/agones for gaming server management on Kubernetes)
Relationships and Interactions
• Start at the Application Layer where the Application component initializes via dependency injection.
• DI then “wires” to various Server components, each of which is instrumented with Middleware such as authentication, rate-limiting, logging, etc.
• Each middleware component may access the Storage Layer (databases, caches) and be involved in message dispatch operations (using the Message Queue).
• Integration components (IAP, Agones) are accessible from the middleware or directly from the service logic for specialized tasks.
• The interactions imply that after a request enters through one of the server protocols, it gets processed via middleware and then uses various storage and integration modules based on its needs.
Important Architectural Patterns and Design Principles
• Modularity: The project is organized into clearly defined modules (3rd, auth, cloud, orm, server, mq, etc.) that encapsulate different concerns.
• Dependency Injection: Using uber/fx promotes decoupling and easier testing by allowing modules to be swapped simply.
• Middleware chaining: A clear separation between protocol-specific servers and shared middleware.
• Clean separation between message queue implementations, caching, and persistence layers.
Relevant Technologies and Libraries
• Go as the primary programming language.
• Uber/fx for dependency injection.
• gRPC, grpc-gateway for API communication.
• TCP/WebSocket/KCP handled partly by the zinx framework.
• GORM for relational databases and MongoDB driver for NoSQL.
• Redis and Dragonfly for caching.
• NATS for messaging.
• IAP libraries and Agones SDK for third party integrations.
• Various utility packages and logging frameworks (zap logger and custom logger components).
• Use clear labels for each component (e.g., Application, DI Container, gRPC Server, HTTP Gateway, TCP Server, Middleware components, GORM/MongoDB, Redis/Dragonfly, NATS MQ, IAP, Agones).
• The flow from the Application Layer (starting point) to the various Server components.
• Connection lines from the servers to the middleware that encloses shared functionality like authentication and rate limiting.
• Flow from middleware or service logic to storage systems and third-party integration modules.
• Integration components (yet another distinct style)
• Modular structure visible in the file tree by optionally drawing a “module container” that represents components such as “auth”, “cloud”, “iap”, “mq”, “orm”, and “server”.