npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@c-a-f/core

v1.0.4

Published

Clean Architecture Frontend (CAF) — domain-agnostic primitives: UseCase, Ploc, Pulse, ApiRequest, RouteManager. Build frontend apps with Clean Architecture.

Readme

@c-a-f/core

Domain-agnostic primitives for clean architecture frontends: UseCase, Ploc, Pulse, ApiRequest, RouteManager.

Documentation: @c-a-f/core docs

Installation

npm install @c-a-f/core

Usage

UseCase

Define application use cases that return Promise<RequestResult<T>>:

import { UseCase, RequestResult } from '@c-a-f/core';

interface LoginUserArgs {
  username: string;
  password: string;
}

class LoginUser implements UseCase<[LoginUserArgs], { token: string }> {
  async execute(args: LoginUserArgs): Promise<RequestResult<{ token: string }>> {
    // Your login logic here
    const result = await loginService.login(args);
    return {
      loading: pulse(false),
      data: pulse(result),
      error: pulse(null! as Error),
    };
  }
}

Ploc (Presentation Logic Component)

Create stateful presentation logic containers:

import { Ploc } from '@c-a-f/core';

interface CounterState {
  count: number;
  isLoading: boolean;
}

class CounterPloc extends Ploc<CounterState> {
  constructor() {
    super({ count: 0, isLoading: false });
  }

  increment() {
    this.changeState({ ...this.state, count: this.state.count + 1 });
  }

  subscribeToState(listener: (state: CounterState) => void) {
    this.subscribe(listener);
  }
}

// Usage
const counter = new CounterPloc();
counter.subscribe((state) => console.log('Count:', state.count));
counter.increment(); // Logs: Count: 1

Pulse (Single Reactive Value)

For single reactive values:

import { pulse } from '@c-a-f/core';

const count = pulse(0);
count.subscribe((value) => console.log('Value:', value));
count.value = 5; // Logs: Value: 5

ApiRequest

Wrap async requests with reactive loading/data/error state:

import { ApiRequest, IRequestHandler } from '@c-a-f/core';

// Works with Promise (backward compatible)
const fetchUser = new ApiRequest(fetch('/api/user').then(r => r.json()));

// Or with IRequestHandler for flexibility (real API, mocks, cached)
class ApiRequestHandler<T> implements IRequestHandler<T> {
  constructor(private apiCall: () => Promise<T>) {}
  async execute(): Promise<T> {
    return await this.apiCall();
  }
}

const userRequest = new ApiRequest(
  new ApiRequestHandler(() => fetch('/api/user').then(r => r.json()))
);

userRequest.loading.subscribe((loading) => {
  if (loading) console.log('Loading...');
});

userRequest.data.subscribe((data) => {
  console.log('User:', data);
});

await userRequest.mutate();

RouteManager

Coordinate routing (requires a RouteRepository implementation from your framework):

import { RouteManager, RouteRepository } from '@c-a-f/core';

// Your framework adapter implements RouteRepository
const routeRepository: RouteRepository = {
  currentRoute: '/',
  change: (route) => router.push(route),
};

const routeManager = new RouteManager(routeRepository, {
  loginPath: '/login',
  isLoggedIn: () => !!localStorage.getItem('token'),
});

routeManager.changeRoute('/dashboard');
routeManager.checkForLoginRoute(); // Redirects to /login if not authenticated

Exports

  • UseCase — Interface for application use cases
  • Ploc — Abstract class for presentation logic containers
  • Pulse — Class for single reactive values
  • pulse — Factory function for creating Pulse instances
  • ApiRequest — Class for wrapping async requests
  • RouteManager — Class for coordinating routing
  • RouteRepository — Interface for routing system abstraction
  • RouteManagerAuthOptions — Interface for auth configuration
  • RequestResult — Type for use case results
  • IRequest — Type for async requests
  • IApiClient — Interface for API client implementations
  • ApiRequestConfig — Interface for API request configuration
  • ApiResponse — Interface for standard API response wrapper
  • ApiError — Interface for standard API error format
  • HttpMethod — Type for HTTP method types
  • extractApiData — Helper function to extract data from wrapped responses
  • normalizeApiError — Helper function to normalize errors
  • IRequestHandler — Interface for request handler implementations (allows swapping real API, mocks, cached)
  • PromiseRequestHandler — Adapter class to convert Promise to IRequestHandler
  • toRequestHandler — Helper function to normalize requests to IRequestHandler

Documentation

License

MIT