โPermissions shouldn't feel like building a nuclear reactor.โ
โ Every developer buried in JSON access trees
๐ฅ What's the problem?
In every project with users, roles, and permissions, you eventually hit something like this:
{
"user": {
"profile": {
"read": true,
"edit": false
},
"settings": {
"change": true
}
},
"order": {
"delivery": {
"cancel": true
}
}
}
๐ตโ๐ซ Massive, nested JSON
๐คฏ Redundant data (false/null/undefined)
๐งฉ Pain to store in JWTs, sessions, or URLs
๐งจ Breaks when schema changes
๐ Enter scode-acl
scode-acl (Structured Compressed ACL) is a schema-driven, ultra-compact access control tool built with TypeScript. It compresses permission data into string-encoded indexes like "0 3 7", verifiable by schema hash.
๐ก Core ideas:
โ Schema โ dot paths โ compressed string
โ Only stores
truepermissionsโ Validates schema with
crc32orsha256โ Works great in JWTs, cookies, URLs, mobile apps
โ Full access check API
โ๏ธ Flat Mode Example
import { createFlatSCode } from "scode-acl";
const schema = {
user: {
profile: ["read", "update"],
settings: ["change"],
},
order: {
delivery: ["cancel"],
},
};
const access = {
user: {
profile: { read: true },
settings: { change: true },
},
order: {
delivery: { cancel: true },
},
};
const formatter = createFlatSCode(schema);
const { access: accessString, schemaHash } = formatter.encodeAccess(access);
console.log(accessString); // โ "0 3 5"
๐ Parse access string
formatter.parseAccess(accessString, schemaHash);
// โ ['user.profile.read', 'user.settings.change', 'order.delivery.cancel']
โ Check a permission
formatter.hasAccess("user.profile.read", accessString);
// โ true
โก Performance Comparison
Format
Encode Time
Size (30+ permissions)
JSON
~8ms
~300 bytes
scode-acl
~1.2ms
~16โ28 bytes
Itโs basically JWT-safe and sessionStorage-ready.
๐ Use Cases
โ JWT tokens โ fits easily in payload
โ GraphQL/REST auth guards
โ Admin panels โ cleaner than boolean spaghetti
โ Mobile/web apps โ tiny access footprint
โ Firebase custom claims / access tokens
๐ฎ Why is it useful?
Only
truepermissions are storedSchema hash ensures backward compatibility
Tiny strings โ easier to debug than full JSON
Supports Flat and Nested encoding
100% TypeScript โ type-safe, fast, and portable
๐ Install
npm install scode-acl
๐ฃ Roadmap
Wildcard permissions (
user.profile.*)Role groups (
admin,viewer)GUI schema editor (Web playground)
Schema โ TS type generator
๐ Links
๐ง GitHub Repo
๐ฆ NPM Package
๐ค Maintainer: @diyor-dev on LinkedIn
๐ง Final thoughts
Most ACL systems are heavy, bloated, or overcomplicated.
scode-acl is a minimalistic alternative designed to be:
๐งฉ Small enough to fit in a token.
๐ Clear enough to read as a dot path.
๐ง Smart enough to validate itself.
If you're building systems that deal with auth, access control, roles, or modular UIs โ try scode-acl.
Use it, fork it, improve it.
And if youโve been burned by ACL complexity before โ
youโll probably find this very refreshing.
Top comments (1)
very nice