English | 中文
moke-kit is a toolkit for building microservices or monolithic applications in Go. You can develop your application as a monolithic service and deploy it as microservices. Like building with LEGO, you can assemble your services exactly how you want them.
flowchart TD
%% Application Layer
subgraph "Application Layer"
app["App & DI (fxmain)"]:::app
end
%% Server Layer
subgraph "Server Layer"
grpc["gRPC Server"]:::server
gateway["HTTP Gateway"]:::server
zinx["TCP/WebSocket/KCP Server (zinx)"]:::server
end
%% Middleware Layer
subgraph "Middleware Layer"
auth["Auth Middleware"]:::mw
stdmw["Other Middlewares (Logging,RateLimit,Recovery,OTel)"]:::mw
end
%% Storage & Message Queue Layer
subgraph "Storage & Message Queue Layer"
gorm["Relational DB (GORM)"]:::storage
mongo["NoSQL DB (MongoDB)"]:::storage
cache["Cache (Redis & Dragonfly)"]:::storage
nats["Message Queue (NATS)"]:::storage
end
%% Integration Layer
subgraph "Integration Layer"
iap["IAP Integration"]:::integration
agones["Agones Integration"]:::integration
end
%% Connections from Application Layer to Server Layer
app -->|"initializes"| grpc
app -->|"initializes"| gateway
app -->|"initializes"| zinx
%% Connections from Server Layer to Middleware Layer
grpc -->|"processed by"| auth
grpc -->|"processed by"| stdmw
gateway -->|"processed by"| auth
gateway -->|"processed by"| stdmw
zinx -->|"processed by"| auth
zinx -->|"processed by"| stdmw
%% Connections from Middleware Layer to Storage & Message Queue Layer
auth -->|"accesses"| gorm
auth -->|"accesses"| mongo
auth -->|"accesses"| cache
auth -->|"accesses"| nats
stdmw -->|"accesses"| gorm
stdmw -->|"accesses"| mongo
stdmw -->|"accesses"| cache
stdmw -->|"accesses"| nats
%% Connections from Middleware Layer to Integration Layer
auth -->|"integrates"| iap
auth -->|"integrates"| agones
stdmw -->|"integrates"| iap
stdmw -->|"integrates"| agones
%% Styles
classDef app fill:#D0E6A5,stroke:#333,stroke-width:2px;
classDef server fill:#86E3CE,stroke:#333,stroke-width:2px;
classDef mw fill:#FFDD94,stroke:#333,stroke-width:2px;
classDef storage fill:#F09494,stroke:#333,stroke-width:2px;
classDef integration fill:#A29BFE,stroke:#333,stroke-width:2px;
%% Click Events
click app "https://github.com/gstones/moke-kit/blob/main/fxmain/fxmain.go"
click grpc "https://github.com/gstones/moke-kit/blob/main/server/internal/srpc/grpc.go"
click gateway "https://github.com/gstones/moke-kit/blob/main/server/internal/srpc/gateway.go"
click zinx "https://github.com/gstones/moke-kit/blob/main/server/internal/zinx/zinx_tcp.go"
click auth "https://github.com/gstones/moke-kit/blob/main/3rd/auth/pkg/authfx/firebase_middleware.go"
click stdmw "https://github.com/gstones/moke-kit/blob/main/server/middlewares/logger.go"
click gorm "https://github.com/gstones/moke-kit/blob/main/orm/pkg/ofx/gorm_module.go"
click mongo "https://github.com/gstones/moke-kit/blob/main/orm/nosql/mongo/factory.go"
click cache "https://github.com/gstones/moke-kit/blob/main/orm/nosql/cache/redis_cache.go"
click nats "https://github.com/gstones/moke-kit/blob/main/mq/internal/nats/message_queue.go"
click iap "https://github.com/gstones/moke-kit/blob/main/3rd/iap/pkg/iapfx/iap_clients.go"
click agones "https://github.com/gstones/moke-kit/tree/main/3rd/agones/pkg/agonesfx"
- Dependency Injection: Uses uber/fx for inversion of control
- Security:
- Built-in TLS and mTLS support for Zero Trust security
- Built-in Token-based authentication with JWT support
- Built-in Middleware: Rate limiting, OpenTelemetry, authentication, logging, panic recovery, and more
- Caching:
- Built-in Cache-Aside pattern for ORM and NoSQL
- Built-in Compare-and-swap for database consistency
- Development Tools:
- Command-line client for independent testing
- Single command generation of proto, gRPC, gateway, Swagger, and client code using buf
- Servers:
- gRPC
- HTTP with grpc-gateway
- TCP via zinx
- WebSocket via zinx
- KCP via zinx
- Message Queue:
- ORM:
- Cache:
- Redis
- Dragonfly
- Third Party Integrations:
- Install gonew:
go install golang.org/x/tools/cmd/gonew@latest
- Create a new project:
gonew github.com/gstones/moke-layout your.domain/myprog