## Struktur Proyek Lengkap ``` nuxt-multitenant-rbac-complete/ ├── assets/ │ ├── css/ │ │ └── main.css │ └── images/ │ └── logo.png ├── components/ │ ├── management/ │ ├── common/ │ │ ├── AppHeader.vue │ │ ├── AppSidebar.vue │ │ ├── AppLayout.vue │ │ ├── AppBreadcrumb.vue │ │ └── AppSearch.vue │ ├── user/ │ │ ├── UserCard.vue │ │ ├── UserForm.vue │ │ ├── UserList.vue │ │ └── UserStats.vue │ ├── role/ │ │ ├── RoleCard.vue │ │ ├── RoleForm.vue │ │ ├── RoleList.vue │ │ └── PermissionMatrix.vue │ └── menu/ │ ├── MenuBuilder.vue │ ├── MenuForm.vue │ ├── MenuList.vue │ ├── MenuTree.vue │ └── IconSelector.vue ├── composables/ │ ├── management/ │ ├── useAuth.ts │ ├── useTenant.ts │ ├── useUsers.ts │ ├── useRoles.ts │ ├── useMenus.ts │ ├── usePermissions.ts │ └── useNotifications.ts ├── data/ │ ├── management/ │ ├── users.json │ ├── roles.json │ ├── menus.json │ ├── tenants.json │ └── permissions.json ├── middleware/ │ ├── auth.ts │ ├── rbac.ts │ ├── tenant.ts │ └── admin.ts ├── pages/ │ ├── index.vue │ ├── login.vue │ ├── dashboard.vue │ ├── management/ │ ├── users/ │ │ ├── index.vue │ │ ├── create.vue │ │ └── [id]/ │ │ ├── edit.vue │ │ └── view.vue │ ├── roles/ │ │ ├── index.vue │ │ ├── create.vue │ │ └── [id]/ │ │ ├── edit.vue │ │ └── view.vue │ └── menu-builder/ │ ├── index.vue │ ├── create.vue │ └── [id]/ │ ├── edit.vue │ └── view.vue ├── plugins/ │ ├── axios.ts │ └── auth.client.ts ├── server/ │ ├── api/ │ │ ├── auth/ │ │ │ ├── login.post.ts │ │ │ ├── logout.post.ts │ │ │ ├── refresh.post.ts │ │ │ └── me.get.ts │ │ ├── users/ │ │ │ ├── index.get.ts │ │ │ ├── index.post.ts │ │ │ ├── [id].get.ts │ │ │ ├── [id].put.ts │ │ │ ├── [id].delete.ts │ │ │ └── stats.get.ts │ │ ├── roles/ │ │ │ ├── index.get.ts │ │ │ ├── index.post.ts │ │ │ ├── [id].get.ts │ │ │ ├── [id].put.ts │ │ │ ├── [id].delete.ts │ │ │ └── permissions.get.ts │ │ ├── menus/ │ │ │ ├── index.get.ts │ │ │ ├── index.post.ts │ │ │ ├── [id].get.ts │ │ │ ├── [id].put.ts │ │ │ ├── [id].delete.ts │ │ │ ├── tree.get.ts │ │ │ └── reorder.post.ts │ │ └── dashboard/ │ │ └── stats.get.ts │ └── middleware/ │ ├── auth.ts │ ├── cors.ts │ └── tenant.ts ├── stores/ │ ├── management/ │ ├── auth.ts │ ├── user.ts │ ├── role.ts │ ├── menu.ts │ └── notification.ts ├── types/ │ ├── management/ │ ├── auth.ts │ ├── user.ts │ ├── role.ts │ ├── menu.ts │ ├── tenant.ts │ ├── permission.ts │ └── api.ts ├── utils/ │ ├── management/ │ ├── permissions.ts │ ├── storage.ts │ ├── validation.ts │ ├── helpers.ts │ └── constants.ts ``` ## 2. Konfigurasi Types Lengkap ### types/api.ts ```typescript export interface ApiResponse { data: T message?: string success: boolean errors?: string[] } export interface PaginatedResponse { data: T[] total: number page: number limit: number totalPages: number } export interface QueryParams { page?: number limit?: number search?: string sort?: string order?: 'asc' | 'desc' [key: string]: any } export interface ApiError { statusCode: number statusMessage: string data?: any } ``` ### types/permission.ts ```typescript export interface Permission { id: string resource: string action: string description?: string category: string } export interface PermissionCategory { id: string name: string description?: string permissions: Permission[] } export const RESOURCES = { USERS: 'users', ROLES: 'roles', MENUS: 'menus', DASHBOARD: 'dashboard', SETTINGS: 'settings' } as const export const ACTIONS = { CREATE: 'create', READ: 'read', UPDATE: 'update', DELETE: 'delete', EXPORT: 'export', IMPORT: 'import' } as const export type ResourceType = typeof RESOURCES[keyof typeof RESOURCES] export type ActionType = typeof ACTIONS[keyof typeof ACTIONS] ``` ## 3. Data Storage Lengkap ### data/permissions.json ```json [ { "id": "perm-1", "resource": "users", "action": "create", "description": "Create new users", "category": "User Management" }, { "id": "perm-2", "resource": "users", "action": "read", "description": "View users", "category": "User Management" }, { "id": "perm-3", "resource": "users", "action": "update", "description": "Edit users", "category": "User Management" }, { "id": "perm-4", "resource": "users", "action": "delete", "description": "Delete users", "category": "User Management" }, { "id": "perm-5", "resource": "roles", "action": "create", "description": "Create new roles", "category": "Role Management" }, { "id": "perm-6", "resource": "roles", "action": "read", "description": "View roles", "category": "Role Management" }, { "id": "perm-7", "resource": "roles", "action": "update", "description": "Edit roles", "category": "Role Management" }, { "id": "perm-8", "resource": "roles", "action": "delete", "description": "Delete roles", "category": "Role Management" }, { "id": "perm-9", "resource": "menus", "action": "create", "description": "Create menu items", "category": "Menu Builder" }, { "id": "perm-10", "resource": "menus", "action": "read", "description": "View menu items", "category": "Menu Builder" }, { "id": "perm-11", "resource": "menus", "action": "update", "description": "Edit menu items", "category": "Menu Builder" }, { "id": "perm-12", "resource": "menus", "action": "delete", "description": "Delete menu items", "category": "Menu Builder" }, { "id": "perm-13", "resource": "dashboard", "action": "read", "description": "View dashboard", "category": "Dashboard" } ] ``` ### data/users.json (Updated) ```json [ { "id": "user-1", "name": "Super Admin", "email": "admin@example.com", "password": "$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "roles": ["super-admin"], "tenantId": "tenant-1", "mobileNo": "+1234567890", "isLoginEnabled": true, "avatar": "https://ui-avatars.com/api/?name=Super+Admin&background=1976d2&color=fff", "lastLogin": "2025-07-27T08:00:00Z", "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-07-27T08:00:00Z" }, { "id": "user-2", "name": "John Doe", "email": "john@example.com", "password": "$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "roles": ["admin"], "tenantId": "tenant-1", "mobileNo": "+1234567891", "isLoginEnabled": true, "avatar": "https://ui-avatars.com/api/?name=John+Doe&background=4caf50&color=fff", "lastLogin": "2025-07-26T15:30:00Z", "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-07-26T15:30:00Z" }, { "id": "user-3", "name": "Jane Smith", "email": "jane@example.com", "password": "$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "roles": ["staff"], "tenantId": "tenant-1", "mobileNo": "+1234567892", "isLoginEnabled": true, "avatar": "https://ui-avatars.com/api/?name=Jane+Smith&background=ff9800&color=fff", "lastLogin": "2025-07-25T10:15:00Z", "createdAt": "2025-01-02T00:00:00Z", "updatedAt": "2025-07-25T10:15:00Z" } ] ``` ### data/roles.json (Updated) ```json [ { "id": "super-admin", "name": "Super Admin", "description": "Full system access with all permissions", "permissions": [ { "resource": "users", "actions": ["create", "read", "update", "delete", "export", "import"] }, { "resource": "roles", "actions": ["create", "read", "update", "delete"] }, { "resource": "menus", "actions": ["create", "read", "update", "delete"] }, { "resource": "dashboard", "actions": ["read"] }, { "resource": "settings", "actions": ["create", "read", "update", "delete"] } ], "tenantId": "tenant-1", "type": "system", "isDefault": true, "userCount": 1, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-01T00:00:00Z" }, { "id": "admin", "name": "Administrator", "description": "Administrative access with most permissions", "permissions": [ { "resource": "users", "actions": ["create", "read", "update", "delete"] }, { "resource": "roles", "actions": ["read", "update"] }, { "resource": "menus", "actions": ["create", "read", "update", "delete"] }, { "resource": "dashboard", "actions": ["read"] } ], "tenantId": "tenant-1", "type": "custom", "isDefault": false, "userCount": 1, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-01T00:00:00Z" }, { "id": "staff", "name": "Staff", "description": "Basic staff access with limited permissions", "permissions": [ { "resource": "users", "actions": ["read"] }, { "resource": "dashboard", "actions": ["read"] } ], "tenantId": "tenant-1", "type": "custom", "isDefault": false, "userCount": 1, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-01T00:00:00Z" } ] ``` ## 4. Layout dan App.vue Lengkap ### app.vue ```vue ``` ### layouts/default.vue ```vue ``` ### layouts/auth.vue ```vue ``` ## 5. Components Utama ### components/common/AppHeader.vue ```vue ``` ### components/common/AppSidebar.vue ```vue ``` ## 6. Pages Lengkap ### pages/index.vue ```vue ``` ### pages/login.vue ```vue ``` ### pages/dashboard.vue ```vue ``` ## 7. README.md Lengkap ### README.md ```markdown # Multi-Tenant RBAC System with Menu Builder A complete **Multi-Tenant Role-Based Access Control (RBAC) System** built with **Nuxt 3**, **Vue 3**, **Vuetify**, and **TypeScript**. This system includes comprehensive user management, role management, and a dynamic menu builder with granular permissions. ## 🌟 Features ### Core Features - **Multi-Tenant Architecture**: Complete tenant isolation - **Role-Based Access Control (RBAC)**: Granular permissions system - **User Management**: Full CRUD operations with advanced filtering - **Role Management**: Create and manage roles with custom permissions - **Menu Builder**: Dynamic menu creation and management - **Authentication & Authorization**: JWT-based secure authentication - **Responsive Design**: Mobile-first approach with Vuetify - **TypeScript**: Full type safety throughout the application ### User Management - ✅ User CRUD operations - ✅ Role assignment - ✅ Profile management with avatars - ✅ Search and filtering - ✅ Pagination - ✅ Account status management - ✅ Bulk operations ### Role Management - ✅ Role CRUD operations - ✅ Permission matrix - ✅ System and custom roles - ✅ Role hierarchy - ✅ Permission inheritance ### Menu Builder - ✅ Dynamic menu creation - ✅ Main and sub-menu support - ✅ Icon selection with search - ✅ Link type configuration (Hash, Site, External) - ✅ Window target options - ✅ Multi-tenant menu support - ✅ Drag & drop ordering ### Security Features - ✅ JWT authentication - ✅ Route protection middleware - ✅ Permission-based access control - ✅ XSS protection - ✅ CSRF protection - ✅ Input validation & sanitization ## 🚀 Quick Start ### Prerequisites - Node.js 18+ - npm or yarn or pnpm ### Installation 1. **Clone the repository** ``` git clone cd nuxt-multitenant-rbac-complete ``` 2. **Install dependencies** ``` npm install # or yarn install # or pnpm install ``` 3. **Environment setup** ``` cp .env.example .env ``` 4. **Start development server** ``` npm run dev # or yarn dev # or pnpm dev ``` 5. **Access the application** - Open [http://localhost:3000](http://localhost:3000) - Use demo credentials to login ## 🔐 Demo Credentials | Role | Email | Password | Permissions | |------|-------|----------|-------------| | Super Admin | admin@example.com | password | Full Access | | Admin | john@example.com | password | Most Features | | Staff | jane@example.com | password | Limited Access | ## 📁 Project Structure ``` nuxt-multitenant-rbac-complete/ ├── assets/ \# Static assets ├── components/ \# Vue components │ ├── common/ \# Common components │ ├── user/ \# User management components │ ├── role/ \# Role management components │ └── menu/ \# Menu builder components ├── composables/ \# Vue composables ├── data/ \# JSON data storage ├── layouts/ \# Nuxt layouts ├── middleware/ \# Route middleware ├── pages/ \# Application pages ├── plugins/ \# Nuxt plugins ├── server/ \# Server API routes ├── stores/ \# Pinia stores ├── types/ \# TypeScript definitions └── utils/ \# Utility functions ``` ## 🛠️ Technology Stack - **Framework**: Nuxt 3 - **Frontend**: Vue 3 + Composition API - **UI Library**: Vuetify 3 - **Language**: TypeScript - **State Management**: Pinia - **Authentication**: JWT - **Styling**: CSS3 + Vuetify - **Icons**: Material Design Icons - **Utilities**: VueUse ## 🎨 UI/UX Features - **Responsive Design**: Works on all device sizes - **Dark/Light Theme**: Built-in theme switching - **Loading States**: Skeleton loaders and progress indicators - **Error Handling**: User-friendly error messages - **Notifications**: Toast notifications for user feedback - **Accessibility**: WCAG 2.1 compliant - **Animation**: Smooth transitions and micro-interactions ## 📊 Data Management - **JSON Storage**: File-based data storage for demo - **CRUD Operations**: Create, Read, Update, Delete - **Search & Filter**: Advanced filtering capabilities - **Pagination**: Efficient data pagination - **Sorting**: Multiple column sorting - **Validation**: Client and server-side validation ## 🔧 Configuration ### Environment Variables ``` # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-change-in-production JWT_EXPIRES_IN=24h # API Configuration API_BASE_URL=http://localhost:3000/api # Application Configuration APP_NAME="Multi-Tenant RBAC System" APP_VERSION=1.0.0 ``` ### Nuxt Configuration The `nuxt.config.ts` file contains all framework configurations including: - Vuetify theming - Module registrations - Runtime configurations - Build optimizations ## 🚦 Development ### Available Scripts ``` # Development npm run dev \# Start development server npm run build \# Build for production npm run generate \# Generate static site npm run preview \# Preview production build # Code Quality npm run lint \# Run ESLint npm run lint:fix \# Fix ESLint issues npm run type-check \# TypeScript type checking ``` ### Adding New Features 1. **Create API endpoint** in `server/api/` 2. **Define types** in `types/` 3. **Create composable** in `composables/` 4. **Build components** in `components/` 5. **Add pages** in `pages/` 6. **Update permissions** in `utils/permissions.ts` ## 📈 Performance - **Lazy Loading**: Components and routes - **Tree Shaking**: Unused code elimination - **Code Splitting**: Automatic route-based splitting - **Image Optimization**: Responsive images - **Caching**: API response caching - **Minification**: CSS and JS minification ## 🔒 Security - **Authentication**: JWT-based authentication - **Authorization**: Role-based access control - **Input Validation**: Comprehensive validation - **XSS Protection**: Content sanitization - **CSRF Protection**: Cross-site request forgery protection - **HTTPS**: SSL/TLS encryption (production) ## 🧪 Testing ### Manual Testing Use the provided demo credentials to test different user roles and permissions. ### Test Scenarios - User login/logout flow - User CRUD operations - Role management - Menu builder functionality - Permission enforcement - Responsive design ## 📚 API Documentation ### Authentication Endpoints - `POST /api/auth/login` - User login - `POST /api/auth/logout` - User logout - `GET /api/auth/me` - Get current user ### User Management - `GET /api/users` - Get users list - `POST /api/users` - Create new user - `GET /api/users/:id` - Get user by ID - `PUT /api/users/:id` - Update user - `DELETE /api/users/:id` - Delete user ### Role Management - `GET /api/roles` - Get roles list - `POST /api/roles` - Create new role - `GET /api/roles/:id` - Get role by ID - `PUT /api/roles/:id` - Update role - `DELETE /api/roles/:id` - Delete role ### Menu Builder - `GET /api/menus` - Get menus list - `POST /api/menus` - Create new menu - `GET /api/menus/:id` - Get menu by ID - `PUT /api/menus/:id` - Update menu - `DELETE /api/menus/:id` - Delete menu ## 🤝 Contributing 1. Fork the repository 2. Create feature branch (`git checkout -b feature/amazing-feature`) 3. Commit changes (`git commit -m 'Add amazing feature'`) 4. Push to branch (`git push origin feature/amazing-feature`) 5. Open Pull Request ## 📄 License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## 📞 Support For support and questions: - Create an issue in the repository - Check the documentation - Contact the development team ## 🚀 Deployment ### Production Build ``` npm run build npm run preview ``` ### Environment Setup 1. Set production environment variables 2. Configure web server (Nginx, Apache) 3. Set up SSL certificates 4. Configure database (if migrating from JSON) ## 🔄 Future Enhancements - [ ] Database integration (PostgreSQL, MySQL) - [ ] Email notifications - [ ] Two-factor authentication - [ ] Activity logging and audit trails - [ ] Advanced reporting and analytics - [ ] File upload and management - [ ] API rate limiting - [ ] Webhook support - [ ] Mobile app (React Native/Flutter) --- **Built with ❤️ using Nuxt 3, Vue 3, and Vuetify** ``` Proyek lengkap ini menggabungkan semua fitur dari kedua sistem sebelumnya menjadi **satu aplikasi yang terstruktur dan siap produksi** dengan: 1. **Struktur folder yang terorganisir** dengan pemisahan yang jelas 2. **Konfigurasi lengkap** dengan environment variables dan setup production 3. **UI/UX yang konsisten** dengan design system Vuetify 4. **Sistem keamanan** yang komprehensif 5. **Dokumentasi lengkap** untuk development dan deployment 6. **Type safety** penuh dengan TypeScript 7. **Performance optimization** built-in 8. **Responsive design** untuk semua perangkat Sistem ini siap untuk dikembangkan lebih lanjut dan dapat di-deploy ke production environment.