Patterns In My Codebases

The 'did you use design patterns?' question, answered with real examples — the source registry, the middleware chain, the alert worker, the pricing engine, and graceful-degradation strategies.

design-patternsappliedprojects

Why this page exists

"Have you used design patterns?" goes badly when you recite GoF. It goes well when you point at code: "the ingestion layer is Strategy + Registry, the API middleware is Chain of Responsibility, the alert worker is Observer." Here are the real ones.

LandAI — source registry & compliance gate

Each external source is an adapter behind a common interface (Strategy), looked up by a Registry, and fronted by a Guard / Proxy (RobotsGate) that can refuse to run a non-permitted source.

interface SourceAdapter { id: string; permitted: boolean; fetch(q: Query): Promise<Raw>; }

const SOURCE_REGISTRY: Record<string, SourceAdapter> = {
  osm_overpass: overpassAdapter,   // permitted (ODbL)
  listing_portal: portalAdapter,   // permitted = false → RobotsGate blocks
};

function ingest(sourceId: string, q: Query) {
  const src = SOURCE_REGISTRY[sourceId];
  if (!src?.permitted) throw new ComplianceError(sourceId); // the gate
  return src.fetch(q);
}
  • Graceful degradation = Strategy with a fallback chain: FAISS → NumPy, PostGIS → in-memory, XGBoost → scikit-learn. Same interface, swap the implementation by availability.
  • Provenance envelope = a Decorator/wrapper that attaches source · license · confidence · freshness to every value.

StockVision — middleware & engines

  • Chain of Responsibility / Decorator: the request passes through auth → rate-limit → CSP → B2B-gateway middleware, each free to short-circuit. Adding a concern = adding a link, not editing the others.
  • Strategy + Composite: the conviction score combines 40+ weighted factors; each factor is a small strategy, the composite aggregates them.
  • Observer + Scheduler: the APScheduler alert worker observes price changes and notifies subscribers out of band.
  • Policy / Strategy: subscription plan-gating selects behavior by tier, enforced server-side.

StockStump — pricing & trading

  • Strategy: PriceEngineService (performance-based jumps) vs PlayerPriceService (random tick) are interchangeable price-move strategies.
  • State: a player is TRADING or FROZEN (lock active); the trade endpoint's behavior depends on that state object rather than scattered booleans.
  • Adapter: cricket-API responses are mapped into internal DTOs, isolating the domain from a third-party schema.
Tie the pattern to a force and a payoff

For each, say the force and the win: "sources vary and some are illegal → Strategy

  • a Registry + a Gate → I can add a licensed feed without touching callers and the illegal one can't run." That's a senior-sounding answer.