Cursor rule
.cursor/rules/language-agnostic-patterns.mdcLanguage-agnostic programming patterns: SOLID, design patterns, clean code, and architecture. Load when refactoring, designing abstractions, or reviewing structure — not for everyday syntax.
Cursor rules
Quality
58/100
Scores the file, not the repository.Length
1,951 words
69 headings · 24 code blocksRepository
124
— · pushed 49 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Language-Agnostic Programming Patterns78Universal principles for structure, naming, architecture, and testing — applicable across all languages.910Load this rule when refactoring modules, designing abstractions, reviewing architecture, or choosing patterns. For day-to-day coding workflow (read-before-edit, CI discovery, minimal diff, verification), the always-on core **Code Discipline** section is canonical — do not duplicate it here. For the judgment layer — root-cause method, simplicity taste, test integrity — load `fable5-coding-craft` alongside this rule.1112---1314## Pattern Judgment (Read First)1516Everything below is vocabulary, not a checklist. Frontier-quality code applies patterns *reactively* — when the code's actual pain demands them — never proactively because a situation pattern-matches a textbook example.1718- Every pattern has a cost: indirection, a new concept for readers, more files to trace through. Apply one only when the pain it removes is already present, not predicted.19- The strongest signal for an abstraction is the **third occurrence** of real duplication with identical reasons to change. Two similar blocks that change for different reasons are not duplication — unifying them couples things that must stay free.20- SOLID violations matter when they cause observed friction (a class you cannot test, a switch you keep re-editing). A small concrete class that "violates SRP" but has never needed to change is fine code — leave it alone.21- The best architecture for most changes is the one the repo already has. Pattern fluency is mostly for *reading* existing designs and for naming the structure a refactor is already growing toward.22- When reviewing, flag pattern *overuse* with the same severity as pattern absence: a Strategy with one strategy, a Factory with one product, or an interface with one implementation is indirection without payoff.2324---2526## Change Discipline2728- Solve the requested problem with the smallest vertical slice; expand only after it works.29- Prefer extending existing modules over creating parallel implementations.30- When adding a dependency, confirm the repo does not already solve the same need.31- Keep public surfaces stable unless the task explicitly requires a breaking change.32- Leave the codebase in a compilable, testable state after each meaningful step.3334---3536## SOLID Principles3738### Single Responsibility Principle (SRP)39A class/module should have only one reason to change.4041**Apply when:**42- A function does multiple unrelated things43- A class has too many dependencies44- Changes in one area affect unrelated code4546**Example Pattern:**47```48Bad: UserService handles auth, profile, notifications, and billing49Good: AuthService, ProfileService, NotificationService, BillingService50```5152### Open/Closed Principle (OCP)53Open for extension, closed for modification.5455**Apply when:**56- Adding new features requires modifying existing code57- Switch statements grow with each new type58- Core logic changes for edge cases5960**Example Pattern:**61```62Bad: if type == "email" ... elif type == "sms" ... elif type == "push" ...63Good: NotificationStrategy interface with EmailStrategy, SMSStrategy, PushStrategy64```6566### Liskov Substitution Principle (LSP)67Subtypes must be substitutable for their base types.6869**Apply when:**70- Derived classes override behavior in unexpected ways71- Code checks for specific types before operating72- Inheritance creates illogical hierarchies7374**Example Pattern:**75```76Bad: Square extends Rectangle but can't independently set width/height77Good: Both Square and Rectangle implement Shape interface78```7980### Interface Segregation Principle (ISP)81Clients shouldn't depend on interfaces they don't use.8283**Apply when:**84- Classes implement methods they don't need85- Interfaces have too many methods86- Changes affect many unrelated implementations8788**Example Pattern:**89```90Bad: Animal interface with fly(), swim(), walk() - Penguin can't fly91Good: Flyable, Swimmable, Walkable interfaces92```9394### Dependency Inversion Principle (DIP)95Depend on abstractions, not concretions.9697**Apply when:**98- High-level modules import low-level modules directly99- Changing database/service requires code changes100- Testing requires real dependencies101102**Example Pattern:**103```104Bad: UserService directly imports MySQLDatabase105Good: UserService depends on DatabaseInterface, injected at runtime106```107108## Common Design Patterns109110### Creational Patterns111112#### Factory Pattern113Use when object creation logic is complex or needs to be centralized.114115```116When to use:117- Multiple similar objects with different configurations118- Object creation depends on runtime conditions119- Hiding complex initialization logic120```121122#### Builder Pattern123Use for constructing complex objects step by step.124125```126When to use:127- Objects with many optional parameters128- Complex configuration requirements129- Need for immutable objects with many fields130```131132#### Singleton Pattern133Use sparingly for truly global, single-instance resources.134135```136When to use:137- Configuration managers138- Connection pools139- Logger instances140141Avoid when:142- It's just for convenience (use DI instead)143- Testing would be difficult144- Multiple instances might be needed later145```146147### Structural Patterns148149#### Adapter Pattern150Convert one interface to another that clients expect.151152```153When to use:154- Integrating third-party libraries155- Working with legacy code156- Unifying different data sources157```158159#### Decorator Pattern160Add behavior to objects dynamically.161162```163When to use:164- Adding features without subclassing165- Composable behaviors166- Middleware-like patterns167```168169#### Facade Pattern170Provide a simplified interface to a complex subsystem.171172```173When to use:174- Simplifying complex library usage175- Creating API boundaries176- Reducing coupling between layers177```178179### Behavioral Patterns180181#### Strategy Pattern182Define a family of interchangeable algorithms.183184```185When to use:186- Multiple algorithms for the same task187- Runtime algorithm selection188- Avoiding complex conditionals189```190191#### Observer Pattern192Notify dependents of state changes.193194```195When to use:196- Event-driven systems197- Pub/sub messaging198- Reactive data flows199```200201#### Command Pattern202Encapsulate requests as objects.203204```205When to use:206- Undo/redo functionality207- Queueing operations208- Macro recording209```210211## Clean Code Principles212213### Naming Conventions214215#### Variables and Functions216- Use intention-revealing names217- Avoid abbreviations unless universally understood218- Be consistent with terminology219220```221Bad: d, tmp, data, info, process()222Good: elapsedTimeInDays, userProfile, activeConnections, validatePayment()223```224225#### Booleans226- Use positive names (avoid double negatives)227- Start with is/has/can/should228229```230Bad: notDisabled, flag, status231Good: isEnabled, hasPermission, canEdit, shouldRefresh232```233234#### Functions235- Use verbs for actions236- Be specific about what they do237238```239Bad: handle(), process(), manage()240Good: validateUserInput(), calculateTotalPrice(), sendConfirmationEmail()241```242243### Function Design244245#### Keep Functions Small246- Do one thing well247- 5-20 lines is ideal248- If you can't name it well, it's probably doing too much249250#### Limit Parameters251- 0-3 parameters is ideal252- Use objects for more253- Consider builder pattern for complex initialization254255#### Avoid Side Effects256- Functions should be predictable257- Clearly document mutations258- Prefer pure functions when possible259260### Comments261262#### When to Comment263- Explain WHY, not WHAT264- Document public APIs265- Warn about non-obvious behavior266- Link to external resources/tickets267268#### When NOT to Comment269- Explaining what code does (make code clearer instead)270- Commented-out code (delete it)271- Redundant descriptions272- TODOs without tickets273274```275Bad: // increment counter by 1276 counter += 1;277278Good: // Retry limit based on SLA requirements (see JIRA-1234)279 MAX_RETRIES = 3;280```281282### Error Handling283284Match the repo's existing error style (exceptions, `Result`/`error`, error codes, etc.) before introducing a new pattern.285286#### Fail Fast287- Validate inputs early288- Throw exceptions for unexpected states289- Don't swallow errors silently290291#### Error Messages292- Include context (what was being done)293- Include relevant values294- Suggest remediation when possible295296```297Bad: "Error occurred"298Good: "Failed to connect to database 'users' at localhost:5432: Connection refused. Check if PostgreSQL is running."299```300301#### Error Categories3021. **Recoverable**: Retry, fallback, or prompt user3032. **Validation**: Return clear error to caller3043. **Programming**: Fail fast, fix the bug3054. **System**: Log, alert, graceful degradation306307## Architecture Patterns308309### Layered Architecture310```311Presentation → Business Logic → Data Access → Database312```313- Each layer only talks to adjacent layers314- Dependencies flow downward315316### Clean Architecture317```318Entities → Use Cases → Controllers → Frameworks319```320- Business rules at the center321- Frameworks/DB at the edges322- Dependency rule: inward only323324### Hexagonal Architecture (Ports & Adapters)325```326[Adapters] → [Ports] → [Core Domain] ← [Ports] ← [Adapters]327```328- Core domain is isolated329- Ports define interfaces330- Adapters implement external concerns331332### When to Choose What333- **Layered**: Simple CRUD apps, rapid development334- **Clean**: Complex business logic, long-lived systems335- **Hexagonal**: Multiple interfaces, testability focus336337## Testing Principles338339### Test Pyramid340```341 /\342 / \ E2E Tests (few)343 /----\ Integration Tests (some)344 /------\ Unit Tests (many)345```346347### Unit Tests348- Test one thing in isolation349- Fast and deterministic350- Mock external dependencies351352### Integration Tests353- Test component interactions354- Use real (or realistic) dependencies355- Focus on boundaries356357### End-to-End Tests358- Test complete user flows359- Slowest and most brittle360- Use for critical paths only361362### Test Quality363- Tests are documentation364- One assertion per test when possible365- Arrange-Act-Assert pattern366- Test behavior, not implementation367368## Performance Principles369370### Measure First371- Don't optimize prematurely372- Profile before changing373- Set performance budgets374375### Common Optimizations376- **Caching**: Memoization, HTTP caching, query caching377- **Batching**: Combine multiple operations378- **Lazy Loading**: Defer until needed379- **Pagination**: Don't load everything at once380381### Database Performance382- Index frequently queried columns383- Avoid N+1 queries384- Use connection pooling385- Consider read replicas for scale386387## Security Best Practices388389### Input Validation390- Validate all external input391- Whitelist, don't blacklist392- Sanitize before use393394### Authentication395- Use established libraries396- Hash passwords with strong algorithms397- Implement rate limiting398- Use HTTPS everywhere399400### Authorization401- Check permissions on every request402- Fail closed (deny by default)403- Log access attempts404405### Data Protection406- Encrypt sensitive data at rest407- Use parameterized queries408- Don't log sensitive information409- Implement proper session management410411## Code Organization412413### Module Structure414```415Feature-based (preferred for larger apps):416/features417 /auth418 - service419 - controller420 - repository421 /products422 - service423 - controller424 - repository425426Layer-based (simpler for smaller apps):427/controllers428/services429/repositories430```431432### File Naming433- Consistent conventions across project434- Reflect content purpose435- Include type suffix when helpful (e.g., `.service`, `.controller`)436437### Import Organization4381. Standard library4392. Third-party packages4403. Local modules4414. Relative imports442443---444445## Code Review Heuristics446447Use when reviewing diffs, PRs, or your own work before closeout. Complements core **Code Discipline** and the always-on verification contract.448449### Correctness450- Does the change solve the stated problem, or only a symptom?451- Are edge cases handled the way this repo handles them (null/empty, auth, timeouts)?452- Do error paths propagate or log usefully — no silent swallowing?453- If behavior changed, are callers, tests, and docs updated?454455### Scope & maintainability456- Is the diff the smallest honest fix? Any unrelated refactors or drive-by renames?457- Does new code match naming, layering, and error style of surrounding files?458- New abstraction justified by reuse, or premature?459- New dependency necessary, or does the repo already cover the need?460461### Tests & verification462- Is there a test or check proportional to the risk? If not, is that gap called out as `unverified`?463- Do tests assert behavior, not implementation details?464- Would CI scripts in this repo catch a regression from this change?465466### Security & data467- User/external input validated and parameterized (SQL, shell, HTML)?468- Secrets, tokens, or PII absent from logs, commits, and client bundles?469- AuthZ checked on the server for every sensitive action — not only UI gating?470471### Performance (when relevant)472- N+1 queries, unbounded loops, or loading entire datasets into memory?473- Caching added only where measured or clearly hot-path?474475### Review output shape476Keep feedback actionable: **issue → impact → suggested fix**. Separate blocking concerns from nits. Prefer pointing to existing repo patterns over generic style opinions.477
Also in madebyaris/advance-minimax-m3-cursor-rules
Diff this repo’s formatsOne 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 |
|---|---|---|---|---|---|
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/3d-graphics.mdc · 124 | Cursor rules | lint-formatstyle | 62/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/agent-teams.mdc · 124 | Cursor rules | setupstylegitapi+3 | 73/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/cursor-agent-orchestration.mdc · 124 | Cursor rules | styledo-notagent-behaviour | 73/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/cursor-mcp-optimization.mdc · 124 | Cursor rules | styledo-notagent-behaviour | 65/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/cursor-tools-mastery.mdc · 124 | Cursor rules | stylemonorepoagent-behaviour | 58/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/design-systems.mdc · 124 | Cursor rules | lint-formatstyleuido-not | 77/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/fable5-reasoning.mdc · 124 | Cursor rules | style | 58/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/devops-infrastructure.mdc · 124 | Cursor rules | stylesecuritydeploymentdo-not | 79/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/minimax-m3-core.mdc · 124 | Cursor rules | buildtestlint-formatstyle+4 | 75/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/minimax-m3-self-evolution.mdc · 124 | Cursor rules | styledo-notagent-behaviour | 65/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/minimax-m3-status-verification.mdc · 124 | Cursor rules | styletypestesting-strategyapi+1 | 65/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/minimax-m3-verification.mdc · 124 | Cursor rules | buildtestlint-formatstyle+3 | 89/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/minimax-mcp-tools.mdc · 124 | Cursor rules | styleagent-behaviour | 54/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/mobile-cross-platform.mdc · 124 | Cursor rules | setupperformancedeployment | 68/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/skill-authoring.mdc · 124 | Cursor rules | stylesecurityapi | 58/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/clarify-first-prompting.mdc · 124 | Cursor rules | styledo-not | 61/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/fable5-coding-craft.mdc · 124 | Cursor rules | teststylearchtesting-strategy+1 | 58/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/model-compatibility.mdc · 124 | Cursor rules | styledeploymentagent-behaviour | 66/100 | 3 days ago | |
| madebyaris/advance-minimax-m3-cursor-rules.cursor/rules/tool-discovery.mdc · 124 | Cursor rules | styletypesdatabaseagent-behaviour | 58/100 | 3 days ago |
Diff against .cursor/rules/3d-graphics.mdc Diff against .cursor/rules/agent-teams.mdc Diff against .cursor/rules/cursor-agent-orchestration.mdc Diff against .cursor/rules/cursor-mcp-optimization.mdc Diff against .cursor/rules/cursor-tools-mastery.mdc Diff against .cursor/rules/design-systems.mdc Diff against .cursor/rules/fable5-reasoning.mdc Diff against .cursor/rules/devops-infrastructure.mdc Diff against .cursor/rules/minimax-m3-core.mdc Diff against .cursor/rules/minimax-m3-self-evolution.mdc Diff against .cursor/rules/minimax-m3-status-verification.mdc Diff against .cursor/rules/minimax-m3-verification.mdc Diff against .cursor/rules/minimax-mcp-tools.mdc Diff against .cursor/rules/mobile-cross-platform.mdc Diff against .cursor/rules/skill-authoring.mdc Diff against .cursor/rules/clarify-first-prompting.mdc Diff against .cursor/rules/fable5-coding-craft.mdc Diff against .cursor/rules/model-compatibility.mdc Diff against .cursor/rules/tool-discovery.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/cli.mdc · 49 | Cursor rules | setupbuildteststyle+4 | 96/100 | 3 days ago | |
| iloveitaly/llm-ide-rules.cursor/rules/general.mdc · 13 | Cursor rules | teststyledo-notagent-behaviour+1 | 92/100 | 3 days ago | |
| danielvm-git/bigpowers.cursor/rules/guard-git.mdc · 119 | Cursor rules | stylearchgitsecurity+2 | 89/100 | 3 days ago | |
| nerds-odd-e/doughnut.cursor/rules/frontend-testing.mdc · 49 | Cursor rules | buildteststyletesting-strategy+2 | 89/100 | 3 days ago | |
| danielvm-git/bigpowers.cursor/rules/organize-workspace.mdc · 119 | Cursor rules | buildstylegitdeployment+2 | 89/100 | 3 days ago |
