Specs / TiltCheck Coding Standards & Conventions

TiltCheck Coding Standards & Conventions

1. Small Modules – Each module owns a narrow responsibility and communicates only via Event Router.

TiltCheck Coding Standards & Conventions

Core Principles

1. Small Modules – Each module owns a narrow responsibility and communicates only via Event Router.

2. Non-Custodial – Never store private keys or hold user funds.

3. Deterministic Events – Events published must be reproducible from inputs; avoid hidden random side-effects.

4. No Deep Relative Imports – Use workspace package names, not ../../../ paths.

5. Fail Soft – Handler errors are logged; do not crash the bus.

TypeScript

Naming

Event Usage


// Subscribe
eventRouter.subscribe('link.scanned', handler, 'suslink');

// Publish
await eventRouter.publish('link.scanned', 'suslink', { url, riskLevel }, userId);

Logging

Prefix all logs with module/service tag:


console.log('[SusLink] Scanned', url);

Avoid spam: batch repetitive logs or use counts.

Errors

Security & Safety

Testing (Vitest Plan)

Pull Request Guidelines

Anti-Patterns (Avoid)

| Pattern | Why Avoid |

|---------|-----------|

| Shared mutable state across modules | Breaks isolation & testability |

| Direct module imports for behavior | Defeats event-driven decoupling |

| Storing secrets in code | Security risk |

| Giant util files | Hard to reason; split by domain |

| Silent catch blocks | Masks failures |

Example Module Skeleton


export class ExampleModule {
  constructor() {
    eventRouter.subscribe('promo.submitted', this.onPromo.bind(this), 'example');
  }
  private async onPromo(event: TiltCheckEvent) {
    // validate
    // publish result
    await eventRouter.publish('promo.approved', 'example', { id: event.id }, event.userId);
  }
}

Performance Notes

Documentation Expectations

Each module requires a README with:

---

Evolves as platform grows; propose improvements via PR.