universal-patterns
Use when implementing language-agnostic patterns like layered architecture, dependency injection, error handling, or code organization principles across any technology stack.
What this skill does
# Universal Development Patterns
## Overview
Language-agnostic development patterns and best practices applicable across all technology stacks.
## Architecture Patterns
### Layered Architecture
```
┌─────────────────────────────┐
│ Presentation Layer │ UI, API handlers, CLI
├─────────────────────────────┤
│ Application Layer │ Use cases, services
├─────────────────────────────┤
│ Domain Layer │ Business logic, entities
├─────────────────────────────┤
│ Infrastructure Layer │ DB, cache, external APIs
└─────────────────────────────┘
```
**When to Use**: Most applications benefit from clear separation of concerns.
### Clean Architecture
```
┌─────────────────┐
│ Frameworks │ (outermost)
│ & Drivers │
┌───┴─────────────────┴───┐
│ Interface Adapters │
│ (Controllers, Gateways)│
┌───┴─────────────────────────┴───┐
│ Application Business │
│ Rules (Use Cases) │
┌─────────────────────────────────┐
│ Enterprise Business Rules │ (innermost)
│ (Entities) │
└─────────────────────────────────┘
```
**Dependency Rule**: Dependencies point inward. Inner layers don't know about outer layers.
### Component-Based Architecture (Frontend)
```
src/
├── components/
│ ├── common/ # Shared UI components
│ ├── layout/ # Layout components
│ └── features/ # Feature-specific components
├── hooks/ # Custom hooks
├── stores/ # State management
├── services/ # API services
└── utils/ # Utilities
```
## Code Organization Principles
### Single Responsibility
Each module/function should do ONE thing well.
```
// BAD: Multiple responsibilities
function processUser(user) {
validateUser(user);
saveToDatabase(user);
sendEmail(user);
logAnalytics(user);
}
// GOOD: Single responsibility
function validateUser(user) { /* validation only */ }
function saveUser(user) { /* persistence only */ }
function notifyUser(user) { /* notification only */ }
```
### Dependency Injection
Inject dependencies rather than creating them internally.
```
// BAD: Hard dependency
class UserService {
constructor() {
this.db = new Database(); // Hard-coded
}
}
// GOOD: Injected dependency
class UserService {
constructor(db) {
this.db = db; // Injected
}
}
```
### Interface Segregation
Prefer many specific interfaces over one general interface.
```
// BAD: Fat interface
interface Worker {
work();
eat();
sleep();
}
// GOOD: Segregated interfaces
interface Workable { work(); }
interface Eatable { eat(); }
interface Sleepable { sleep(); }
```
## Error Handling Patterns
### Fail Fast
Validate inputs early and fail immediately on invalid data.
```
function processOrder(order) {
// Validate early
if (!order) throw new Error('Order required');
if (!order.items?.length) throw new Error('Order must have items');
if (!order.customerId) throw new Error('Customer ID required');
// Process only after validation passes
return executeOrder(order);
}
```
### Error Boundaries
Contain errors at appropriate boundaries.
```
// API boundary - catch and format errors
async function apiHandler(req, res) {
try {
const result = await processRequest(req);
res.json({ success: true, data: result });
} catch (error) {
res.status(error.statusCode || 500).json({
success: false,
error: error.message
});
}
}
```
### Result Types (Where Supported)
Use Result/Either types instead of exceptions for expected failures.
```typescript
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
function parseConfig(input: string): Result<Config, ParseError> {
try {
return { ok: true, value: JSON.parse(input) };
} catch (e) {
return { ok: false, error: new ParseError(e.message) };
}
}
```
## Data Flow Patterns
### Unidirectional Data Flow
Data flows in one direction through the application.
```
Action → Dispatcher → Store → View → Action
```
### Event-Driven Architecture
Decouple components through events.
```
// Publisher
eventBus.emit('user.created', { userId: '123' });
// Subscriber
eventBus.on('user.created', async (event) => {
await sendWelcomeEmail(event.userId);
});
```
### Command Query Separation (CQS)
Separate commands (mutations) from queries (reads).
```
// Query - returns data, no side effects
function getUser(id) { return db.users.find(id); }
// Command - mutates data, returns void/status
function updateUser(id, data) { db.users.update(id, data); }
```
## Naming Conventions
### Functions
| Type | Convention | Examples |
|------|------------|----------|
| Actions | verb + noun | `createUser`, `deleteOrder`, `validateInput` |
| Queries | get/find/is/has + noun | `getUser`, `findOrders`, `isValid`, `hasPermission` |
| Handlers | handle + event | `handleClick`, `handleSubmit`, `handleError` |
| Callbacks | on + event | `onSuccess`, `onError`, `onChange` |
### Variables
| Type | Convention | Examples |
|------|------------|----------|
| Booleans | is/has/can/should | `isActive`, `hasAccess`, `canEdit`, `shouldRefresh` |
| Collections | plural | `users`, `orders`, `items` |
| Counts | count/num/total | `userCount`, `numItems`, `totalPrice` |
### Files
| Type | Convention | Examples |
|------|------------|----------|
| Components | PascalCase | `UserProfile.tsx`, `OrderList.vue` |
| Utilities | camelCase/kebab | `formatDate.ts`, `string-utils.ts` |
| Constants | SCREAMING_SNAKE | `API_ENDPOINTS.ts`, `ERROR_CODES.ts` |
| Tests | name.test/spec | `user.test.ts`, `order.spec.ts` |
## Code Quality Checklist
Before committing code, verify:
- [ ] Single responsibility - each function does one thing
- [ ] Clear naming - intent is obvious from names
- [ ] Error handling - failures are handled gracefully
- [ ] No magic numbers - constants are named and documented
- [ ] DRY - no unnecessary duplication (but don't over-abstract)
- [ ] Tests - critical paths are tested
- [ ] Documentation - complex logic is explained
## Anti-Patterns to Avoid
### God Objects
Objects that know too much or do too much. Split into focused components.
### Premature Optimization
Don't optimize before measuring. Write clear code first, optimize proven bottlenecks.
### Stringly Typed
Using strings where enums/types would be safer. Use type systems.
### Copy-Paste Programming
Duplicating code instead of abstracting. But: prefer duplication over wrong abstraction.
### Boolean Parameters
Functions with boolean flags that change behavior. Split into explicit functions.
```
// BAD
function process(data, isAdmin) { /* behaves differently based on flag */ }
// GOOD
function processUserData(data) { /* user logic */ }
function processAdminData(data) { /* admin logic */ }
```
## Performance Principles
1. **Measure First**: Profile before optimizing
2. **Lazy Loading**: Load resources only when needed
3. **Caching**: Cache expensive computations and API calls
4. **Pagination**: Don't load everything at once
5. **Batch Operations**: Combine multiple operations when possible
6. **Async/Parallel**: Use concurrency for independent operations
## Security Principles
1. **Input Validation**: Never trust user input
2. **Output Encoding**: Encode data for its context (HTML, SQL, etc.)
3. **Least Privilege**: Request minimum permissions needed
4. **Defense in Depth**: Multiple layers of security
5. **Fail Secure**: Default to denying access on errors
6. **Secrets Management**: Never hardcode secrets, use environment variables
---
*Universal patterns applicable to all technology stacks*
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.