

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456# Core Go Patterns & Conventions78## Concurrency Patterns910<pattern type="thread_safe_structures">11```go12// Thread-safe structs with embedded mutex13type Status struct {14 Name string15 mu sync.RWMutex // Protects all fields16}17```18</pattern>1920<pattern type="concurrent_operations">21```go22// Concurrent operations with errgroup23g, ctx := errgroup.WithContext(ctx)24for _, item := range items {25 item := item // capture loop variable26 g.Go(func() error { return process(ctx, item) })27}28return g.Wait()29```30</pattern>3132## Factory Pattern (OCP Implementation)3334<requirement type="mandatory">35**MANDATORY for service creation:**36</requirement>3738<pattern type="factory_implementation">39```go40// ✅ Good: Extensible through interfaces41type Storage interface {42 Save(ctx context.Context, data []byte) error43}4445type StorageFactory struct{}46func (f *StorageFactory) CreateStorage(storageType string) (Storage, error) {47 switch storageType {48 case "redis": return NewRedisStorage(), nil49 case "memory": return NewMemoryStorage(), nil50 default: return nil, fmt.Errorf("unsupported storage type: %s", storageType)51 }52}5354// Usage in constructors55func NewStorage(config *StorageConfig) (Storage, error) {56 factory := &StorageFactory{}57 return factory.CreateStorage(config.Type)58}59```60</pattern>6162## Configuration with Defaults6364<requirement type="always">65**Always provide defaults:**66</requirement>6768<pattern type="configuration_defaults">69```go70func NewService(config *Config) *Service {71 if config == nil {72 config = DefaultConfig() // Always provide defaults73 }74 return &Service{config: config}75}76```77</pattern>7879<pattern type="configuration_implementation">80```go81// ✅ Good: Centralized configuration with defaults82type ServiceConfig struct {83 Port int `yaml:"port"`84 Timeout time.Duration `yaml:"timeout"`85 MaxRetries int `yaml:"max_retries"`86}8788func DefaultServiceConfig() *ServiceConfig {89 return &ServiceConfig{90 Port: 8080,91 Timeout: 30 * time.Second,92 MaxRetries: 3,93 }94}9596func NewServiceFromConfig(cfg *ServiceConfig) *Service {97 if cfg == nil {98 cfg = DefaultServiceConfig()99 }100 return &Service{config: cfg}101}102```103</pattern>104105## Graceful Shutdown106107<requirement type="long_running_services">108**REQUIRED for long-running services:**109</requirement>110111<pattern type="graceful_shutdown">112```go113quit := make(chan os.Signal, 1)114signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)115select {116case <-ctx.Done():117 return shutdown(ctx)118case <-quit:119 return shutdown(ctx)120}121```122</pattern>123124## Middleware Pattern125126<context type="http_handlers">127**For HTTP handlers:**128</context>129130<pattern type="middleware_implementation">131```go132func authMiddleware() gin.HandlerFunc {133 return func(c *gin.Context) {134 if !isValidToken(c.GetHeader("Authorization")) {135 c.JSON(401, gin.H{"error": "unauthorized"})136 c.Abort()137 return138 }139 c.Next()140 }141}142```143</pattern>144145## Resource Management146147<context type="connection_handling">148**Connection limits and cleanup:**149</context>150151<pattern type="resource_management">152```go153// Connection limits154if len(m.clients) >= m.config.MaxConnections {155 return fmt.Errorf("max connections reached")156}157158// Cleanup with defer159defer func() {160 m.cancel()161 m.wg.Wait()162 if closeErr := m.conn.Close(); closeErr != nil {163 log.Error("failed to close connection", "error", closeErr)164 }165}()166```167</pattern>168169## Interface Design (ISP Implementation)170171<guideline type="interface_size">172**Small, focused interfaces (ISP):**173</guideline>174175<pattern type="interface_segregation">176```go177// ✅ Good: Small, focused interfaces178type Reader interface {179 Read(ctx context.Context, id core.ID) (*Data, error)180}181182type Writer interface {183 Write(ctx context.Context, data *Data) error184}185186type Deleter interface {187 Delete(ctx context.Context, id core.ID) error188}189190// Compose when needed191type Repository interface {192 Reader193 Writer194 Deleter195}196197// ❌ Bad: Monolithic interface198type DataManager interface {199 Read(ctx context.Context, id core.ID) (*Data, error)200 Write(ctx context.Context, data *Data) error201 Delete(ctx context.Context, id core.ID) error202 Backup(ctx context.Context) error203 Restore(ctx context.Context) error204 Migrate(ctx context.Context) error205}206```207</pattern>208209<pattern type="interface_definition">210```go211// Small, focused interfaces for specific domains212type Storage interface {213 SaveMCP(ctx context.Context, def *MCPDefinition) error214 LoadMCP(ctx context.Context, name string) (*MCPDefinition, error)215 Close() error216}217```218</pattern>219220<best_practices type="interface_organization">221**Interface best practices:**222- Define interfaces in separate files when used across packages223- Keep interfaces small and focused on specific behavior224- Use interface composition for complex behavior225- Honor contracts consistently (LSP)226</best_practices>227228## Constructor Patterns (DIP Implementation)229230<requirement type="mandatory">231**MANDATORY for all services:**232</requirement>233234<pattern type="dependency_injection">235```go236// ✅ Good: Depends on abstraction (DIP)237type WorkflowService struct {238 taskRepo TaskRepository // interface239 executor TaskExecutor // interface240}241242func NewWorkflowService(taskRepo TaskRepository, executor TaskExecutor) *WorkflowService {243 return &WorkflowService{244 taskRepo: taskRepo,245 executor: executor,246 }247}248249// ❌ Bad: Depends on concrete implementation250type WorkflowService struct {251 taskRepo *PostgreSQLTaskRepository // concrete252 executor *DockerExecutor // concrete253}254```255</pattern>256257<pattern type="service_constructor">258```go259// ✅ Required pattern for all services260type AgentService struct {261 repo AgentRepository262 config *AgentConfig263}264265func NewAgentService(266 repo AgentRepository,267 config *AgentConfig,268) *AgentService {269 if config == nil {270 config = DefaultAgentConfig()271 }272 return &AgentService{273 repo: repo,274 config: config,275 }276}277```278</pattern>279280## Single Responsibility Examples (SRP Implementation)281282<pattern type="srp_separation">283```go284// ✅ Good: Single responsibility285type UserValidator struct{}286func (v *UserValidator) ValidateEmail(email string) error { /* validation logic */ }287288type UserRepository struct{}289func (r *UserRepository) SaveUser(ctx context.Context, user *User) error { /* persistence logic */ }290291// ❌ Bad: Multiple responsibilities292type UserService struct{}293func (s *UserService) ValidateAndSaveUser(ctx context.Context, email string) error {294 // validation + persistence mixed295}296```297</pattern>298299## Context Handling Patterns300301<requirement type="mandatory">302**Context as first parameter:**303</requirement>304305<pattern type="context_propagation">306```go307// ✅ Context as first parameter308func (s *TaskService) ExecuteTask(ctx context.Context, task *core.Task) (*core.TaskResult, error) {309 select {310 case <-ctx.Done():311 return nil, ctx.Err()312 default:313 return s.doExecuteTask(ctx, task)314 }315}316```317</pattern>318319## Resource Management Patterns320321<pattern type="resource_cleanup">322```go323// ✅ Proper resource cleanup324func (s *Service) ProcessWithResources(ctx context.Context) error {325 conn, err := s.acquireConnection()326 if err != nil {327 return fmt.Errorf("failed to acquire connection: %w", err)328 }329 defer func() {330 if closeErr := conn.Close(); closeErr != nil {331 log.Error("failed to close connection", "error", closeErr)332 }333 }()334 return s.processWithConnection(ctx, conn)335}336337// ✅ Timeout handling with cleanup338func (s *Service) ProcessWithTimeout(ctx context.Context, timeout time.Duration) error {339 ctx, cancel := context.WithTimeout(ctx, timeout)340 defer cancel() // Always cancel to free resources341 done := make(chan error, 1)342 go func() {343 done <- s.heavyProcessing(ctx)344 }()345 select {346 case err := <-done:347 return err348 case <-ctx.Done():349 return fmt.Errorf("operation timed out: %w", ctx.Err())350 }351}352353// ✅ Multiple resource cleanup354func (s *Service) ProcessMultipleResources(ctx context.Context) error {355 file, err := os.Open("data.txt")356 if err != nil {357 return fmt.Errorf("failed to open file: %w", err)358 }359 defer file.Close()360 lock := s.mutex.Lock()361 defer s.mutex.Unlock()362 return s.processFileWithLock(ctx, file)363}364```365</pattern>366
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| compozy/gograph.cursor/rules/architecture.mdc · 9 | Cursor rules | styletesting-strategydependenciesdo-not | 57/100 | 14 days ago | |
| compozy/gograph.cursor/rules/api-standards.mdc · 9 | Cursor rules | lint-formatapidocs | 54/100 | 14 days ago | |
| compozy/gograph.cursor/rules/backwards-compatibility.mdc · 9 | Cursor rules | do-notagent-behaviour | 32/100 | 14 days ago | |
| compozy/gograph.cursor/rules/compozy-agent-config.mdc · 9 | Cursor rules | agent-behaviour | 45/100 | 14 days ago | |
| compozy/gograph.cursor/rules/compozy-examples.mdc · 9 | Cursor rules | stylearchtypesagent-behaviour | 58/100 | 14 days ago | |
| compozy/gograph.cursor/rules/compozy-project-config.mdc · 9 | Cursor rules | setupstyle | 54/100 | 14 days ago | |
| compozy/gograph.cursor/rules/compozy-shared-patterns.mdc · 9 | Cursor rules | styleagent-behaviour | 54/100 | 14 days ago | |
| compozy/gograph.cursor/rules/compozy-task-patterns.mdc · 9 | Cursor rules | stylearchagent-behaviour | 70/100 | 14 days ago | |
| compozy/gograph.cursor/rules/core-libraries.mdc · 9 | Cursor rules | testing-strategydependenciesdo-not | 60/100 | 14 days ago | |
| compozy/gograph.cursor/rules/critical-validation.mdc · 9 | Cursor rules | no sections | 24/100 | 14 days ago | |
| compozy/gograph.cursor/rules/cursor_rules.mdc · 9 | Cursor rules | no sections | 40/100 | 14 days ago | |
| compozy/gograph.cursor/rules/go-coding-standards.mdc · 9 | Cursor rules | stylearchdependencies | 62/100 | 14 days ago | |
| compozy/gograph.cursor/rules/no_linebreaks.mdc · 9 | Cursor rules | no sections | 31/100 | 14 days ago | |
| compozy/gograph.cursor/rules/prd-create.mdc · 9 | Cursor rules | stylearchagent-behaviour | 48/100 | 14 days ago | |
| compozy/gograph.cursor/rules/prd-tech-spec.mdc · 9 | Cursor rules | setuptestarchagent-behaviour | 56/100 | 14 days ago | |
| compozy/gograph.cursor/rules/quality-security.mdc · 9 | Cursor rules | securityperformancedo-not | 46/100 | 14 days ago | |
| compozy/gograph.cursor/rules/review-checklist.mdc · 9 | Cursor rules | testing-strategygit | 52/100 | 14 days ago | |
| compozy/gograph.cursor/rules/section_comments.mdc · 9 | Cursor rules | no sections | 31/100 | 14 days ago | |
| compozy/gograph.cursor/rules/task-developing.mdc · 9 | Cursor rules | agent-behaviour | 47/100 | 14 days ago | |
| compozy/gograph.cursor/rules/task-generate-list.mdc · 9 | Cursor rules | testlint-formatarchdo-not+1 | 85/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 46 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/compozy-gograph-cursor-rules-go-patterns)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.