Loading repository data…
Loading repository data…
Agillmann / repository
A production-ready REST API boilerplate built with Hono and TypeScript, featuring a sophisticated Role-Based Access Control (RBAC) system, multi-tenant organizations, and modern authentication.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A production-ready REST API boilerplate built with Hono and TypeScript, featuring a sophisticated Role-Based Access Control (RBAC) system, multi-tenant organizations, and modern authentication.
| Component | Technology | Version |
|---|---|---|
| Runtime | Bun | Latest |
| Framework | Hono | ^4.9.6 |
| Authentication | Better-Auth | ^1.3.7 |
| Database | MySQL + Prisma | 8.0 + ^6.15.0 |
| Validation | Zod | ^4.0 |
| Logging | Pino | ^9.9.1 |
| Code Quality | BiomeJS | ^2.2.2 |
# Clone and install dependencies
git clone <repository-url>
cd api-boilerplate
bun install
# Copy environment template
cp .env.example .env
Essential environment variables:
# Better Auth Configuration
BETTER_AUTH_SECRET=your-super-secret-key-here-min-32-chars
BETTER_AUTH_URL=http://localhost:3000
# Database Configuration
DATABASE_URL=mysql://app_user:app_password@localhost:3306/api_boilerplate
SHADOW_DATABASE_URL=mysql://app_user:app_password@localhost:3306/api_boilerplate_shadow
# Application
NODE_ENV=development
APP_PORT=3000
# Start MySQL with Docker (recommended)
docker-compose up -d mysql
# Verify database is ready
docker-compose ps
# Generate Prisma client and run migrations
bun run db:generate
bun run db:migrate
# Start with hot reload
bun run dev
# ✅ API running at http://localhost:3000/api/v1
# Test public endpoints
curl http://localhost:3000/api/v1/health/api
curl http://localhost:3000/api/v1/system/stats
# Test protected endpoint (expect 401)
curl http://localhost:3000/api/v1/me
The API uses Better-Auth with session-based authentication:
admin/user)🎯 App-Level Roles
├── admin → System administrator (global access to /admin/*)
└── user → Authenticated user (access to /me/* + organization features)
🏢 Organization-Level Roles
├── owner → Full control (delete org, manage all)
├── admin → Manage members, teams, settings
└── member → Basic access to organization resources
Permissions are structured around resources and actions:
user, organization, team, invitation, membercreate, read, update, delete, manage, invite, banExample Permission Checks:
// Organization admin can invite members
user.hasPermission('invitation.create', organizationId)
// Only owners can delete organizations
user.hasRole('owner', organizationId)
// System admins bypass organization permissions
user.hasSystemRole('admin')
| Category | Base Path | Authentication | Description |
|---|---|---|---|
| System | /api/v1/health/* | Public | Health checks and system status |
| Documentation | /api/v1/docs/* | Public | Interactive API documentation with Scalar UI |
| Auth | /api/v1/auth/* | Public | Better-Auth endpoints (auto-generated) |
| User | /api/v1/me/* | Session Required | User profile, organizations, invitations |
| Organizations | /api/v1/organizations/* | Session + Membership | Multi-tenant org management |
| Admin | /api/v1/admin/* | Admin Role Required | System administration |
# Register new user
curl -X POST http://localhost:3000/api/v1/auth/sign-up \
-H "Content-Type: application/json" \
-d '{"email":"dev@example.com","password":"password123","name":"Developer"}'
# Login (get session cookie)
curl -X POST http://localhost:3000/api/v1/auth/sign-in \
-H "Content-Type: application/json" \
-c cookies.txt \
-d '{"email":"dev@example.com","password":"password123"}'
# Get my profile (with session)
curl http://localhost:3000/api/v1/me \
-b cookies.txt
# Get my organizations
curl http://localhost:3000/api/v1/me/organizations \
-b cookies.txt
# Create organization
curl -X POST http://localhost:3000/api/v1/organizations \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{"name":"My Company","slug":"my-company"}'
# Invite member to organization
curl -X POST http://localhost:3000/api/v1/organizations/{id}/invite \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{"email":"member@example.com","role":"admin"}'
# List all users with pagination
curl http://localhost:3000/api/v1/admin/users?page=1&limit=10 \
-b cookies.txt
# Ban a user
curl -X POST http://localhost:3000/api/v1/admin/users/{id}/ban \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{"reason":"Policy violation","expiresAt":"2024-12-31T23:59:59Z"}'
bun run dev # Start with hot reload
bun run build # Build for production
bun run start # Start production server
bun run db:generate # Generate Prisma client
bun run db:migrate # Create and run migrations
bun run db:studio # Open Prisma Studio (DB GUI)
bun run db:push # Push schema changes
bun run db:reset # Reset database (⚠️ destroys data)
bun run lint # Run BiomeJS linter
bun run lint:fix # Auto-fix linting issues
bun run typecheck # Run TypeScript type checking
bun run gen:sdk # Generate SDK client from OpenAPI spec
# Database only
docker-compose up -d mysql
# Database + Monitoring Stack
docker-compose up -d mysql loki promtail grafana
# View logs
docker-compose logs mysql
docker-compose logs grafana
# Stop services
docker-compose down
# Full stack (uncomment api service in docker-compose.yml)
docker-compose up -d
The project includes a complete Grafana monitoring stack with:
/logs/ directory# Start monitoring stack
docker-compose up -d loki promtail grafana
# Verify services
docker-compose ps
| Dashboard | URL | Purpose |
|---|---|---|
| API Performance | http://localhost:3001/d/api-performance | Response times, request rates, status codes |
| Auth & Security | http://localhost:3001/d/auth-security | Login events, admin actions, security alerts |
| System Health | http://localhost:3001/d/system-health | API status, errors, database connectivity |
| RBAC Activity | http://localhost:3001/d/rbac-activity | Organization operations, permissions |
NODE_ENV=production in .envdocker-compose up -d loki promtail grafanaSee Monitoring Documentation for detailed setup and customization.
The API includes comprehensive logging with Pino:
# View recent errors
tail -f logs/error.log
# Monitor API access
tail -f logs/access.log
# Watch auth events
tail -f logs/auth.log
# Check API health
curl http://localhost:3000/api/v1/health/api
# Verify database connection
curl http://localhost:3000/api/v1/health/db
# Test authentication (should return 401 without session)
curl http://localhost:3000/api/v1/me
# Check your permissions
curl http://localhost:3000/api/v1/system/permissions -b cookies.txt
| Document | Description | Use Case |
|---|---|---|
| 📋 Quick Reference | Concise endpoint tables by role | Fast API lookup during development |
| 📚 Complete API Docs | Detailed endpoint docs with schemas | Integration development |
| 📝 Logging Guide | Logging system & monitoring setup | Production debugging & monitoring |
| 🗺️ Documentation Index | Navigation & architecture overview | Understanding system design |
The API includes comprehensive interactive documentation powered by Scalar UI:
# Access interactive documentation
open http://localhost:3000/api/v1/docs
# View OpenAPI specification
open http://localhost:3000/api/v1/docs/openapi.json
# Better-Auth specific docs
open http://localhost:3000/api/v1/docs/auth-openapi.json
# Generate SDK client
bun run gen:sdk
The documentation includes:
src/
├── index.ts # Application entry point + main router
├── config.ts # Environment configuration
├── api/ # API route handlers organized by feature
│ ├── index.ts # Main router combining all sub-routers
│ ├── auth/ # Authentication routes
│ │ ├── auth.ts # Better-Auth integration handler
│ │ └── me.ts # User profile routes
│ ├── admin/ # Administration routes
│ │ ├── admin.ts # Global admin routes (user mgmt, stats)
│ │ └── organizations.ts # Admin organization oversight
│ ├── system/ # System routes
│ │ └── index.ts # Health checks and system info
│ └── docs/ # Documentation routes
│ ├── index.ts # Interactive API docs with Scalar UI
│ └── openapi.json # OpenAPI 3.0 specification
├── lib/ # Core libraries
│ ├── auth.ts # Bette