DEV Community

Diyor Umarkulov
Diyor Umarkulov

Posted on

๐Ÿง  Tired of bloated ACLs? Meet scode-acl: A minimal, schema-driven, token-friendly access control system

โ€œ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
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

๐Ÿ˜ตโ€๐Ÿ’ซ 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 true permissions

  • โœ… Validates schema with crc32 or sha256

  • โœ… 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"

Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Parse access string

formatter.parseAccess(accessString, schemaHash);
// โ†’ ['user.profile.read', 'user.settings.change', 'order.delivery.cancel']

Enter fullscreen mode Exit fullscreen mode

โœ… Check a permission

formatter.hasAccess("user.profile.read", accessString);
// โ†’ true

Enter fullscreen mode Exit fullscreen mode

โšก 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 true permissions are stored

  • Schema 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

Enter fullscreen mode Exit fullscreen mode

๐Ÿ›ฃ Roadmap

  • Wildcard permissions (user.profile.*)

  • Role groups (admin, viewer)

  • GUI schema editor (Web playground)

  • Schema โ†’ TS type generator


๐Ÿ”— Links


๐Ÿง  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)

Collapse
 
fazliddin_quvatboyev_855f profile image
Fazliddin Quvatboyev

very nice