A comprehensive authentication and role-based access control (RBAC) boilerplate built with Go (Echo framework) backend and React (TypeScript + shadcn/ui) frontend. This project provides a solid foundation for building web applications with modern authentication features and granular permissions system.
- User Authentication: Sign up, sign in, sign out with JWT tokens
- Two-Factor Authentication (2FA): TOTP-based 2FA with backup codes
- Role-Based Access Control (RBAC): Comprehensive permissions system
- Role Management: Create, update, delete roles with granular permissions
- User Role Assignment: Assign multiple roles to users
- Permission Middleware: Route-level permission enforcement
- Password Reset: Secure password reset via email
- Email Integration: Welcome emails, password reset, 2FA codes using Resend
- Database: PostgreSQL with GORM ORM and automatic migrations
- Validation: Request validation using go-playground/validator
- Logging: Structured logging with Zap
- Testing: Comprehensive unit tests
- Modern UI: Built with shadcn/ui components and Tailwind CSS
- Authentication Pages: Clean login/signup forms with 2FA support
- Role Management Interface: Complete RBAC administration
- Permissions Matrix: Visual permission management
- User Role Assignment: Drag-and-drop role management
- Dashboard: User profile and security management
- Responsive Design: Mobile-friendly interface
- Form Validation: Client-side validation with error handling
- State Management: React hooks and context
- Testing: Component tests with Vitest and React Testing Library
- Type Safety: Full TypeScript support
- Default Roles: Super Admin, Admin, Team, User
- Granular Permissions: Resource-based permissions (user:read, role:write, etc.)
- Permission Categories: User, Role, Report, Settings, System management
- Middleware Protection: Route-level access control
- Dynamic Role Creation: Create custom roles with specific permissions
- Permission Inheritance: System admin privileges override all permissions
.
βββ main.go # Application entry point
βββ makefile # Comprehensive build and dev commands
βββ go.mod # Go module dependencies
βββ .env.example # Environment variables template
βββ .gitignore # Comprehensive gitignore
βββ docker-compose.dev.yml # Development environment
βββ scripts/
β βββ init-db.sql # Database initialization
βββ internal/ # Private application code
β βββ api/ # HTTP handlers and routes
β β βββ api.go # API setup with RBAC
β β βββ roles.go # Role management endpoints
β β βββ routes.go # Protected routes with permissions
β βββ common/ # Shared utilities
β β βββ authentication_context/
β β βββ environment/
β β βββ logger/
β β βββ passwords/
β β βββ validator/
β βββ db/ # Database connection and migration
β βββ models/ # Database models with role relationships
β βββ services/ # Business logic services
β βββ authentication/ # Auth service with role loading
β βββ email/ # Email service with Resend
β βββ permissions/ # RBAC service and middleware
β β βββ permissions.go # Core RBAC functionality
β β βββ middleware.go # Permission middleware
β β βββ service.go # Database operations
β βββ users/ # User management service
βββ spa/ # React frontend
β βββ src/
β β βββ components/ # Reusable UI components
β β β βββ roles/ # Role management components
β β βββ pages/ # Page components
β β β βββ auth/ # Authentication pages
β β β βββ RoleManagement.tsx # RBAC admin interface
β β β βββ routing/ # Route configuration
β β βββ api/ # API client with RBAC endpoints
β β βββ hooks/ # Custom React hooks
β β βββ lib/ # Utility functions
β β βββ test/ # Test files
β βββ package.json
β βββ vite.config.ts
βββ README.md
- Go 1.21+
- Node.js 18+
- PostgreSQL 13+
- Docker (optional)
- Make (for using Makefile commands)
git clone https://github.com/feezyhendrix/echoboilerplate.git
cd echoboilerplate
# Copy and configure environment
cp .env.example .env
# Edit .env with your database and API keys
# Check environment setup
make env-check# Start full development environment
make dev
# Or build and start fresh
make dev-build
# View logs
make dev-logs
# Stop environment
make dev-downAccess Points:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8080
- PostgreSQL: localhost:5432
- Redis: localhost:6379
# Install dependencies
make deps
# Start database only
make dev-db
# Run server locally (in new terminal)
make dev-server
# Run SPA locally (in new terminal)
make dev-spamake help # Show all available commands
make dev # Run full development environment
make dev-build # Build and run development environment
make dev-server # Run server locally
make dev-spa # Run SPA development server
make dev-db # Start only database
make dev-logs # Show development logs
make dev-clean # Clean development environmentmake build # Build both server and SPA
make build-server # Build server binary
make build-spa # Build SPA for production
make build-docker # Build Docker imagesmake test # Run all tests
make test-server # Run server tests
make test-spa # Run SPA tests
make test-coverage # Generate coverage report
make lint # Run all linters
make fmt # Format all code
make check # Run format, lint, and testsmake db-migrate # Run database migrations
make db-seed # Seed database with initial data
make db-reset # Reset database completely
make db-backup # Create database backup
make db-console # Connect to database consolemake clean # Clean build artifacts
make deps # Install all dependencies
make deps-update # Update dependencies
make version # Show version information
make env-check # Check environment configuration
make security-check # Run security checks| Role | ID | Description | Default Permissions |
|---|---|---|---|
| Super Admin | 4 | Full system access | All permissions including system:admin |
| Admin | 1 | User and role management | user:read/write, role:read, report:read/write, settings:read |
| Team | 2 | Collaborative access | user:read, report:read/write |
| User | 3 | Basic access | report:read |
Format: resource:action
Resources: user, role, report, settings, system
Actions: read, write, delete, admin
Examples:
user:read- View user informationrole:write- Create and modify rolessystem:admin- Full system administration
// Require specific permission
roles.GET("", a.GetRoles, permissions.RequirePermission(permissions.PermissionRoleRead))
// Require any of multiple permissions
userRoutes.GET("/profile", a.GetProfile, permissions.RequireAnyPermission(
permissions.PermissionUserRead,
permissions.PermissionSystemAdmin,
))
// Require role
adminRoutes.GET("/settings", a.GetSettings, permissions.RequireRole(permissions.ROLE_ID_ADMIN))func (a *API) GetUsers(c echo.Context) error {
user := c.Get("user").(*models.User)
if !user.HasPermission(permissions.PermissionUserRead) {
return echo.NewHTTPError(http.StatusForbidden, "Insufficient permissions")
}
// Continue with logic...
}// Check user permissions
const hasUserManagement = user.permissions.includes('user:write');
// Conditionally render UI
{hasUserManagement && (
<Button onClick={handleCreateUser}>Create User</Button>
)}{
"email": "[email protected]",
"password": "password123"
}Response includes user with roles:
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": 1,
"email": "[email protected]",
"userRoles": [
{
"role": {
"id": 1,
"name": "Admin",
"permissions": [
{"name": "user:read", "resource": "user", "action": "read"},
{"name": "role:read", "resource": "role", "action": "read"}
]
}
}
]
}
}Get all roles with permissions (requires role:read)
Create new role (requires role:write)
{
"name": "Manager",
"description": "Department manager role",
"isActive": true
}Assign role to user (requires user:write)
{
"userId": 123,
"roleId": 2
}Get all available permissions (requires role:read)
- Role Management Tab: Create, edit, delete roles
- User Assignment Tab: Assign roles to users
- Permissions Matrix Tab: Visual permission grid
// Role management
<RoleManagement />
// User role assignment
<UserRoleAssignment userId={123} userName="John Doe" />
// Permissions matrix
<PermissionsMatrix />// Hide/show based on permissions
{user.hasPermission('user:write') && (
<CreateUserButton />
)}
// Different views for different roles
{user.hasRole(ROLE_ID_ADMIN) ? (
<AdminDashboard />
) : (
<UserDashboard />
)}make testmake test-server # Run tests
make test-server-coverage # Generate coverage report
make test-integration # Run integration testsmake test-spa # Run SPA testsThe boilerplate includes comprehensive tests for:
- Permission checking functions
- Middleware enforcement
- Role assignment logic
- API endpoint protection
# Build everything for production
make build
# Build Docker images
make build-docker
# Deploy to staging
make deploy-staging
# Deploy to production
make deploy-prodDevelopment: Copy .env.example to .env
Production: Set environment variables in your deployment platform
Required Variables:
POSTGRES_*- Database connectionAUTHENTICATION_JWT_SECRET- JWT signing key (32+ characters)AUTHENTICATION__PASSWORD_RESET_TOKEN_ENCRYPTION_KEY- Password reset encryptionRESEND_API_KEYorSENDGRID__API_KEY- Email service
- Password Hashing: bcrypt with salt
- JWT Tokens: Secure token-based authentication with role information
- 2FA Support: TOTP with backup codes
- RBAC: Granular permission system with middleware enforcement
- Rate Limiting: Protection against brute force attacks
- CORS: Configurable cross-origin resource sharing
- Input Validation: Server and client-side validation
- Secure Headers: Security middleware
- Email Verification: Account verification flow
- Permission Inheritance: System admin override capabilities
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Run quality checks:
make check - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Go and TypeScript best practices
- Write tests for new features (especially RBAC components)
- Update documentation as needed
- Use conventional commit messages
- Ensure all tests pass:
make test - Run security checks:
make security-check
This project is licensed under the MIT License - see the LICENSE file for details.
- Echo - High performance Go web framework
- GORM - Go ORM library with excellent relationship support
- shadcn/ui - Beautiful UI components
- Tailwind CSS - Utility-first CSS framework
- Vite - Fast build tool
- Resend - Email API service
If you have any questions or need help:
- Open an issue on GitHub
- Check the comprehensive documentation
- Review existing issues for solutions
- Use
make helpto see all available commands
Built with β€οΈ for modern web applications with security in mind