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

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:
Option 1: GitHub Actions (Recommended)
Manual trigger:
- Go to Actions tab in GitHub
- Select "Create Release Tag" workflow
- Click "Run workflow"
- Enter version (e.g.,
v0.1.0)
- Add release notes (optional)
- Click "Run workflow"
Automatic trigger:
- Update the
VERSION file with new version (e.g., 0.2.0)
- Commit and push to main branch
- 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
Support
Made with β€οΈ by Ryo ARIMA