Architecture Overview
Meshery Server is composed of several key components:- REST API – Built with Gorilla Mux; handles HTTP endpoints
- GraphQL API – Built with gqlgen; provides real-time subscriptions
- Database – PostgreSQL for persistent storage
- Message Broker – NATS for event streaming
- Provider Plugins – gRPC/HTTP interfaces for authentication and sync
- Kubernetes Client – Manages connections to Kubernetes clusters
- Adapters – gRPC clients for service mesh integrations
Repository Structure
The server code is located in the/server directory:
Development Workflow
Running the Server Locally
Basic server (port 9081):http://localhost:9081.
Run with local Remote Provider:
Building the Server
Build server binary:main binary in the project root.
Run the binary:
Environment Variables
Configure the server with environment variables:| Variable | Description | Default |
|---|---|---|
PORT | Server listening port | 9081 |
DEBUG | Enable debug logging | false |
PROVIDER_BASE_URLS | Remote provider URLs | Production URLs |
ADAPTER_URLS | Comma-separated adapter URLs | - |
KEYS_PATH | Path to encryption keys | - |
SKIP_COMP_GEN | Skip Kubernetes component generation | false |
DISABLE_OPERATOR | Disable operator deployment | false |
PLAYGROUND | Enable playground mode | false |
REGISTER_STATIC_K8S | Register static Kubernetes models | true |
OTEL_CONFIG | OpenTelemetry config path | - |
Code Style and Linting
Linting with golangci-lint
All Go code must pass golangci-lint checks:.github/.golangci.yml
Formatting
Format your code withgofmt and goimports:
Error Handling
Meshery uses MeshKit’s error utilities for consistent error handling. Define errors inserver/helpers:
./server/helpers.
Update error codes only:
Testing
Unit Tests
Unit tests are placed in*_test.go files alongside the code they test.
Run all tests:
Integration Tests
Integration tests are located inserver/integration-tests/.
MeshSync Integration Tests:
- Check dependencies:
- Setup test environment:
- Run tests:
- Cleanup:
Working with APIs
REST API
REST endpoints are defined inserver/handlers/.
Example handler:
GraphQL API
GraphQL schema and resolvers are inserver/internal/graphql/.
Schema location: server/internal/graphql/schema.graphql
Example schema:
Working with Kubernetes
Kubernetes Client
Meshery Server uses client-go to interact with Kubernetes clusters. Example: Get cluster version:MeshModel
MeshModel defines Kubernetes resources and their relationships. Location:server/models/meshmodel/
Registering new models:
Models are automatically generated from Kubernetes CRDs and registered on startup.
Skip model generation during development:
Working with Providers
Providers handle authentication, user preferences, and data synchronization. Provider interface:server/models/provider.go
Local Provider:
Built-in provider with local storage (no authentication).
Remote Provider:
External providers (e.g., Meshery Cloud) with authentication and cloud sync.
Switch providers during development:
Working with Adapters
Adapters are gRPC services that integrate with service meshes and infrastructure. Protocol definition:server/meshes/meshops.proto
Rebuild protocol buffers:
Database Operations
Meshery Server uses PostgreSQL for persistent storage. Database operations:server/internal/store/
Example query:
Event Streaming with NATS
Meshery uses NATS for event streaming and pub/sub messaging. Topics:meshsync.request– MeshSync discovery requestsmeshery.broker– Broker events
Common Tasks
Adding a New REST Endpoint
- Add handler in
server/handlers/:
- Register route in router:
- Update Swagger annotations:
- Rebuild Swagger:
Adding a New GraphQL Query
- Update schema in
server/internal/graphql/schema.graphql:
- Regenerate code:
- Implement resolver:
Adding a New Error Code
- Define error in
server/helpers/:
- Update error codes:
Debugging
Enable Debug Logging
Use Delve Debugger
Check Server Health
Performance Testing
Meshery includes wrk2 and Nighthawk for performance testing. Setup wrk2:Next Steps
Testing Guide
Learn how to test server changes
Code Style
Review Go code style guidelines
UI Development
Contribute to the frontend
CLI Development
Contribute to mesheryctl