agentleFS
opalinehqopalinehq/cli/.claude/skills/code-architecture/SKILL.md

code-architecture

Skill311 starsChanged 8 days agoApache-2.0View on GitHub

Code architecture patterns. Use when organizing code, refactoring classes, designing service structure, or extracting/moving code to new files. Enforces function ordering, service functions over classes, dependency injection.

  • Reads credentials

11 other projects use a version of this; 2 new projects in the last 4 weeks, against 0 the 4 before.

Adopted by

Surging: 2 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projectsWeek of Oct 25: 0 new projectsWeek of Nov 1: 0 new projectsWeek of Nov 8: 0 new projectsWeek of Nov 15: 0 new projectsWeek of Nov 22: 2 new projects
Oct 2026Nov 2026Nov 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 2 in all, so this is a hint, not a trend.

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    CRITICAL: Always apply these patterns when:

    line 9
  2. Distinctive:

    When a new endpoint needs the same orchestration as existing code (queue handlers, cron jobs, other endpoints):

    line 80
  3. Very specific:

    Always use last parameter as env object:

    line 120

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Architecture Standards

CRITICAL: Always apply these patterns when:

  • Creating a new file that will contain multiple functions
  • Extracting code from one file to another
  • Refactoring or reorganizing existing code structure

Function Order (Clean Code)

Organize from high-level to detail:

// 1. Constants, types, schemas at top
const CONFIG = { ... } as const
type Options = { ... }

// 2. Main/entry point functions
async function main() {
  await initialize()
  await processData()
}

// 3. Supporting functions
async function initialize() { ... }
async function processData() { ... }

// 4. Utilities at bottom
function formatDate(date: Date) { ... }

Avoid Bloat Proxy Functions

// ❌ Bad - Pure bloat
class MyWorkflow {
  async getCursorStats() {
    return await cursorService.getCursorStats({ DB: this.env.DB })
  }
}

// ✅ Good - Import and use directly
import { getCursorStats } from './cursor-service'
const stats = await getCursorStats(env)

Prefer Service Functions Over Classes

// ❌ Bad - Unnecessary class wrapper
export class CursorService {
  constructor(private db: D1Database) {}
  async getCursor(shopDomain: string) { ... }
}

// ✅ Good - Individual functions with DI
export async function getCursor(
  shopDomain: string,
  env: { DB: D1Database }
) {
  return await env.DB.prepare('...').bind(shopDomain).first()
}

Benefits

  • Tree-shakable: Only import what you need
  • Testable: Easy to mock dependencies
  • Explicit dependencies
  • No instantiation overhead
  • Functional style

When to Use Classes vs Functions

  • Classes: Complex stateful objects, entities with behavior, inheritance
  • Functions: Simple services, utilities, data transformation, API calls

When to Extract Shared Services

When a new endpoint needs the same orchestration as existing code (queue handlers, cron jobs, other endpoints):

Extract a shared function when:

  • The code is exactly the same (not just similar)
  • Changes should always propagate to both call sites
  • It represents the same semantic operation (e.g., "run an uptime check", "process a payment")

Don't force abstractions when:

  • Code paths are similar but could legitimately diverge
  • The operations might need independent evolution
  • Forcing alignment would create awkward conditional logic
// ❌ Bad - Duplicated orchestration
// In queue handler
const result = await executeCheck(monitor);
await writeResult(result);
await processAlert(result);

// In new endpoint (duplicated!)
const result = await executeCheck(monitor);
await writeResult(result);
await processAlert(result);

// ✅ Good - Shared service function
export async function runUptimeCheck(
  monitor: Monitor,
  env: { DB: D1Database }
): Promise<CheckResult> {
  const result = await executeCheck(monitor);
  await writeResult(result, env);
  await processAlert(result, env);
  return result;
}

// Both queue handler and endpoint call the service
await runUptimeCheck(monitor, env);

Dependency Injection Pattern

Always use last parameter as env object:

export async function myFunction(
  param1: string,
  param2: number,
  env: { DB: D1Database; KV: KVNamespace }
) {
  // Function implementation
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.