Licence
MIT
Version
0.1.0-alpha.3
Deps
0
Size
73 kB
Vulns
0
Weekly
0
LimitLayer
A modern, framework-agnostic rate limiting library for Node.js and TypeScript.
LimitLayer is designed to be fast, extensible, and easy to integrate. It separates the core rate-limiting engine from framework adapters, allowing the same limiter to work across Express today and other frameworks in future releases.
Architecture
flowchart TD
App[Application]
Express["@limitlayer/express"]
Core["@limitlayer/core"]
Engine[Decision Engine]
Matcher[Rule Matcher]
Registry[Algorithm Registry]
Algorithm[Fixed Window Algorithm]
Store[Memory Store]
App --> Express
Express --> Core
Core --> Engine
Engine --> Matcher
Engine --> Registry
Registry --> Algorithm
Engine --> Store
Features
- High-performance TypeScript implementation
- Framework-agnostic core
- Official Express adapter
- ESM + CommonJS support
- Built-in Fixed Window algorithm
- Extensible algorithm registry
- Pluggable storage architecture
- Type-safe public API
- Simple configuration
Packages
| Package | Description |
|---|---|
@limitlayer/core |
Core rate limiting engine |
@limitlayer/express |
Express middleware |
Installation
Core
npm install @limitlayer/core
Express
npm install @limitlayer/core @limitlayer/express express
Quick Start
import {
MemoryStore,
createLimitLayer,
} from "@limitlayer/core";
const limiter = createLimitLayer({
storage: new MemoryStore(),
rules: [
{
path: "/login",
algorithm: "fixed-window",
limit: 5,
window: "1m",
},
],
});
const result = await limiter.consume({
method: "POST",
path: "/login",
ip: "127.0.0.1",
headers: {},
query: {},
});
console.log(result);
Express Example
import express from "express";
import { MemoryStore } from "@limitlayer/core";
import { limitLayer } from "@limitlayer/express";
const app = express();
app.use(
limitLayer({
storage: new MemoryStore(),
rules: [
{
path: "/login",
algorithm: "fixed-window",
limit: 5,
window: "1m",
},
],
})
);
app.post("/login", (_, res) => {
res.json({
success: true,
});
});
app.listen(3000);
Built-in Algorithms
| Algorithm | Status |
|---|---|
| Fixed Window | Available |
| Sliding Window | Planned |
| Sliding Log | Planned |
| Token Bucket | Planned |
| Leaky Bucket | Planned |
Storage
| Storage | Status |
|---|---|
| MemoryStore | Available |
| RedisStore | Planned |
Roadmap
v0.1
- Core engine
- Memory storage
- Fixed Window algorithm
- Express adapter
v0.2
- Redis storage
- Sliding Window
- Token Bucket
- Leaky Bucket
- Sliding Log
Future
- Fastify adapter
- Hono adapter
- Next.js adapter
- Analytics dashboard
- Hosted SaaS
Development
Clone the repository:
git clone https://github.com/gargavi-oss/limitlayer.git
cd limitlayer
pnpm install
Build all packages:
pnpm build
Run tests:
pnpm test
Contributing
Contributions, bug reports, feature requests, and discussions are welcome.
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a Pull Request
License
MIT License.
Built with using TypeScript.