locky

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2025 License: MIT

README ΒΆ

Locky

A robust Role-Based Access Control (RBAC) service built with Go, providing comprehensive user, group, member, and role management with fine-grained permissions.

Go Version License Documentation

Features

  • πŸ” JWT Authentication: Secure token-based authentication with HS256
  • πŸ›‘οΈ Casbin RBAC: Flexible policy-based authorization
  • πŸ‘₯ User Management: Complete CRUD operations for user accounts
  • πŸ“¦ Group Management: Organize users into logical groups
  • πŸ‘€ Member Management: Control group membership and relationships
  • 🎭 Role Management: Define and assign fine-grained permissions
  • ⚑ Redis Caching: High-performance caching with token denylist
  • πŸ—„οΈ MySQL/TiDB: Reliable persistent data storage
  • 🌐 Multi-tier API: Public, Internal, and Private endpoints
  • πŸ“± CLI Clients: Admin, App, and Anonymous command-line interfaces

Quick Start

Prerequisites
  • Go 1.22 or higher
  • MySQL 8.0+ or TiDB
  • Redis 6.0+
  • Docker & Docker Compose (optional)
Installation
# Clone the repository
git clone https://github.com/ryo-arima/locky.git
cd locky

# Start dependencies with Docker Compose
docker-compose up -d

# Copy configuration
cp etc/app.dev.yaml etc/app.yaml

# Build the server
go build -o .bin/locky-server ./cmd/server/main.go

# Start the server
./.bin/locky-server

The server will start on http://localhost:8080.

Quick Test
# Register a user
curl -X POST http://localhost:8080/v1/public/users/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Test User","email":"test@example.com","password":"password123"}'

# Login
curl -X POST http://localhost:8080/v1/public/users/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password123"}'

# Use the JWT token from the response for authenticated requests

Architecture

Locky follows a clean, layered architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Client Layer                          β”‚
β”‚              (Admin CLI, App CLI, Anonymous CLI)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        API Layer                            β”‚
β”‚        (Gin Router, JWT Auth, Casbin RBAC, Logger)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Controller Layer                         β”‚
β”‚          (Public, Internal, Private Controllers)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Business Logic Layer                        β”‚
β”‚              (User, Group, Member, Role Usecases)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Repository Layer                          β”‚
β”‚         (User, Group, Member, Role Repositories)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Data Layer                             β”‚
β”‚              (MySQL/TiDB, Redis, Casbin Policies)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

View detailed architecture diagram β†’

Documentation

Comprehensive documentation is available at https://ryo-arima.github.io/locky/

API Endpoints

Public Endpoints (No Authentication Required)
  • POST /v1/public/users/register - Register a new user
  • POST /v1/public/users/login - Authenticate and get JWT token
  • GET /v1/public/health - Health check
Internal Endpoints (JWT Required)
  • GET /v1/internal/users - List users
  • GET /v1/internal/groups - List groups
  • GET /v1/internal/members - List members
  • GET /v1/internal/roles - List roles
Private Endpoints (JWT + Permissions Required)
  • PUT /v1/private/users/{id} - Update user
  • DELETE /v1/private/users/{id} - Delete user
  • POST /v1/private/groups - Create group
  • POST /v1/private/roles - Create role

Full API documentation β†’

Configuration

Create etc/app.yaml from the template:

cp etc/app.yaml.example etc/app.yaml

Edit the configuration with your settings:

Server:
  host: "0.0.0.0"
  port: 8080
  jwt_secret: "your-secure-secret-256-bits"

MySQL:
  host: "localhost"
  user: "locky"
  pass: "password"
  db: "locky"

Redis:
  host: "localhost"
  port: 6379
  db: 0

Configuration guide β†’

Development

Building
# Build all binaries
make build

# Or build individually
go build -o .bin/locky-server ./cmd/server/main.go
go build -o .bin/locky-client-admin ./cmd/client/admin/main.go
go build -o .bin/locky-client-app ./cmd/client/app/main.go
go build -o .bin/locky-client-anonymous ./cmd/client/anonymous/main.go
Testing
# Run tests
make test

# Run with coverage
go test -v -cover ./...
Documentation
# Build documentation
./scripts/build-docs.sh

# Serve documentation locally
cd docs/dist && python3 -m http.server 8000
Publishing to pkg.go.dev

To make your package available on pkg.go.dev, you have two options:

Manual trigger:

  1. Go to Actions tab in GitHub
  2. Select "Create Release Tag" workflow
  3. Click "Run workflow"
  4. Enter version (e.g., v0.1.0)
  5. Add release notes (optional)
  6. Click "Run workflow"

Automatic trigger:

  1. Update the VERSION file with new version (e.g., 0.2.0)
  2. Commit and push to main branch
  3. GitHub Actions will automatically create the tag
Option 2: Manual Script
# Publish with default version (v0.1.0)
./scripts/publish-to-pkggodev.sh

# Or specify a version
./scripts/publish-to-pkggodev.sh v0.2.0

After publishing (either method), your package will be available at:

Note: It may take 5-10 minutes for pkg.go.dev to index the package after tag creation.

CLI Clients

Admin Client

Administrative operations with elevated privileges:

./.bin/locky-client-admin --help
App Client

Application-level operations for authenticated users:

./.bin/locky-client-app --help
Anonymous Client

Public operations without authentication:

./.bin/locky-client-anonymous --help

Project Structure

locky/
β”œβ”€β”€ cmd/                    # Command-line applications
β”‚   β”œβ”€β”€ server/            # HTTP server
β”‚   └── client/            # CLI clients (admin, app, anonymous)
β”œβ”€β”€ pkg/                   # Shared packages
β”‚   β”œβ”€β”€ server/           # Server implementation
β”‚   β”‚   β”œβ”€β”€ controller/   # HTTP handlers
β”‚   β”‚   β”œβ”€β”€ middleware/   # Middleware components
β”‚   β”‚   └── repository/   # Data access layer
β”‚   β”œβ”€β”€ client/           # Client implementation
β”‚   β”œβ”€β”€ config/           # Configuration management
β”‚   └── entity/           # Data models and DTOs
β”œβ”€β”€ etc/                   # Configuration files
β”‚   β”œβ”€β”€ casbin/           # Casbin policy files
β”‚   └── app.yaml.example  # Configuration template
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ books/            # mdBook source
β”‚   β”œβ”€β”€ dist/             # Built documentation (GitHub Pages)
β”‚   β”œβ”€β”€ architecture/     # Architecture diagrams
β”‚   └── swagger/          # OpenAPI specification
β”œβ”€β”€ scripts/              # Build and utility scripts
└── test/                 # Test files

Technology Stack

  • Language: Go 1.22+
  • Web Framework: Gin
  • ORM: GORM
  • Authentication: JWT with golang-jwt
  • Authorization: Casbin
  • Database: MySQL 8.0+ / TiDB
  • Cache: Redis 6.0+
  • Documentation: mdBook, Swagger/OpenAPI

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Made with ❀️ by Ryo ARIMA

Directories ΒΆ

Path Synopsis
cmd
client/admin command
client/app command
server command
Package main provides the Locky API server.
Package main provides the Locky API server.
pkg
server/controller
Package controller provides HTTP handlers for the Locky API.
Package controller provides HTTP handlers for the Locky API.
test
cmd/server command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL