From 214fca9ef64c8d840d8d2ea4c41ad9d52f998e34 Mon Sep 17 00:00:00 2001 From: pbao9 Date: Tue, 3 Feb 2026 09:22:40 +0700 Subject: [PATCH] update --- .agent/workflows/code-style-guide.md | 179 ++++++++++++++++++ .github/workflows/README.md | 151 --------------- config/assets.php | 37 ++++ .../administrator/layout/master.blade.php | 36 ++-- .../pages/package/datacenter/add.blade.php | 98 +++++----- .../pages/package/datacenter/index.blade.php | 15 +- .../components/admin-breadcrumb.blade.php | 2 +- 7 files changed, 285 insertions(+), 233 deletions(-) create mode 100644 .agent/workflows/code-style-guide.md delete mode 100644 .github/workflows/README.md create mode 100644 config/assets.php diff --git a/.agent/workflows/code-style-guide.md b/.agent/workflows/code-style-guide.md new file mode 100644 index 0000000..376b687 --- /dev/null +++ b/.agent/workflows/code-style-guide.md @@ -0,0 +1,179 @@ +--- +description: Code Style Guide +--- + +# Laravel 10 – Repository Pattern +## Strict Coding Rules (Anti-Trash & Anti-Overengineering) + +This document defines mandatory rules to prevent meaningless files, useless comments, and over-engineered architecture. + +--- + +## 0. Core Principle + +Do not create code unless it introduces real behavior. +Do not write comments to compensate for bad code. + +Readable code replaces comments. +Behavior justifies files. + +--- + +## 1. Comment Rules (VERY STRICT) + +Forbidden: +- Comments repeating code meaning +- Comments describing method names +- Placeholder comments +- TODO without ticket reference + +Allowed only to explain WHY: +- Architectural decisions +- Non-obvious side effects +- Constraints or workarounds + +--- + +## 2. File Creation Rules + +Do NOT create files: +- For clean structure only +- For symmetry +- For future assumptions +- To wrap a single call + +--- + +## 3. When a New File Is Allowed + +At least ONE condition must be true: +1. Real business rules exist +2. Logic reused in 2+ places +3. Side effects exist (transaction, cache, events) + +--- + +## 4. Repository Rules + +Repositories MAY: +- Query data +- Filter +- Paginate +- Cache + +Repositories MUST NOT: +- Validate +- Apply business rules +- Format responses +- Check permissions + +--- + +## 5. Service Layer Rules + +Service allowed only if: +- Uses multiple repositories +- Manages transactions +- Coordinates caching +- Enforces domain rules + +Proxy-only services are forbidden. + +--- + +## 6. Controller Rules + +Controllers MAY: +- Accept Request +- Call Service or Repository +- Return Response + +Controllers MUST NOT: +- Contain business logic +- Query database directly + +--- + +## 7. Interface Rules + +Do NOT create interfaces if only one implementation exists. + +Interfaces allowed only when: +- Multiple implementations exist +- Cache on/off switching +- Required for testing + +--- + +## 8. Helper Rules + +Forbidden: +- Business logic in helpers + +Allowed: +- String +- Date +- Array utilities + +--- + +## 9. Naming Rules + +Forbidden: +handle, process, execute, run, doSomething + +Required: +publishCourse, syncStudentProgress, calculateFinalScore + +--- + +## 10. Exception Rules + +Forbidden: +throw new Exception() + +Required: +Explicit domain-specific exceptions + +--- + +## 11. Folder Structure Rules + +Avoid over-fragmentation. + +One concept = minimal files. + +--- + +## 12. File Count Sanity Check + +CRUD feature <= 5 files is acceptable. +More than 10 files indicates over-engineering. + +--- + +## 13. Code Review Rejection Checklist + +Reject if: +- File has no behavior +- Service only proxies calls +- Comment explains WHAT not WHY +- Interface has one implementation +- File exists for future use + +--- + +## 14. AI Enforcement Rules + +- Do not create files without behavior +- Do not generate meaningless comments +- Do not create proxy layers +- Prefer fewer, clearer files +- Reject over-engineering + +--- + +## 15. Final Rule + +Architecture serves behavior. +If code has no clear reason to exist, remove it. diff --git a/.github/workflows/README.md b/.github/workflows/README.md deleted file mode 100644 index 4318420..0000000 --- a/.github/workflows/README.md +++ /dev/null @@ -1,151 +0,0 @@ -# GitHub Actions Deployment Workflows - -Các workflow tự động deploy được tạo cho project Laravel Portal. - -## Workflows Available - -### 1. `deploy.yml` - Deployment thông thường -- **Trigger**: Push vào branches `main`, `master`, `develop` hoặc manual trigger -- **Mục đích**: Deploy cho staging/development environment -- **Actions**: Git pull, npm run production, Laravel optimization - -### 2. `deploy-minified.yml` - Production Deployment với minification -- **Trigger**: Push vào branches `main`, `master` hoặc manual trigger -- **Mục đích**: Deploy cho production environment -- **Actions**: Git pull, npm run minify-all, database migration, backup, cleanup - -## Setup Requirements - -### 1. GitHub Secrets Configuration - -Cần setup các secrets sau trong GitHub repository: - -#### For `deploy.yml`: -``` -HOST - IP address hoặc domain của server -USERNAME - SSH username -SSH_KEY - SSH private key content -PORT - SSH port (optional, default: 22) -PROJECT_PATH - Đường dẫn tới project (optional, default: /var/www/portal) -``` - -#### For `deploy-minified.yml`: -``` -PROD_HOST - Production server IP/domain -PROD_USERNAME - Production SSH username -PROD_SSH_KEY - Production SSH private key -PROD_PORT - Production SSH port (optional, default: 22) -PROD_PROJECT_PATH - Production project path (optional, default: /var/www/portal) -``` - -### 2. Server Requirements - -#### Server cần có sẵn: -- Git -- PHP >= 8.0 -- Composer -- Node.js & NPM -- Web server (nginx/apache) với quyền www-data - -#### Project directory structure: -``` -/var/www/portal/ # Main project -/var/www/portal-backup-* # Backup directories (auto-created) -``` - -### 3. SSH Key Setup - -1. **Generate SSH key pair:** - ```bash - ssh-keygen -t rsa -b 4096 -C "github-actions@yourdomain.com" - ``` - -2. **Add public key to server:** - ```bash - # Copy public key to server - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys - ``` - -3. **Add private key to GitHub Secrets:** - - Copy nội dung của private key file - - Paste vào GitHub Secrets với tên `SSH_KEY` hoặc `PROD_SSH_KEY` - -## Manual Deployment - -Có thể trigger deployment manually: - -1. Vào GitHub repository -2. Click tab "Actions" -3. Chọn workflow muốn chạy -4. Click "Run workflow" -5. Chọn branch và click "Run workflow" - -## Workflow Features - -### Security Features: -- SSH key authentication -- Separate production secrets -- Backup before deployment - -### Performance Features: -- Asset minification cho production -- Laravel optimization commands -- Cache clearing/rebuilding - -### Maintenance Features: -- Automatic backup rotation (keep last 5) -- Queue restart -- Permission fixing -- Database migration - -## Troubleshooting - -### Common Issues: - -1. **SSH Connection Failed:** - - Kiểm tra HOST, USERNAME, SSH_KEY secrets - - Verify SSH key format (complete private key including headers) - -2. **Permission Denied:** - - Kiểm tra SSH user có quyền access project directory - - Verify www-data ownership - -3. **Build Failed:** - - Kiểm tra Node.js version trên server - - Verify npm dependencies - -4. **Laravel Commands Failed:** - - Kiểm tra PHP version compatibility - - Verify .env file exists và correct - -### Debug Commands: -Để debug, có thể thêm các commands sau vào workflow: - -```yaml -# Add to workflow script section -echo "Current user: $(whoami)" -echo "Current directory: $(pwd)" -echo "PHP version: $(php -v)" -echo "Node version: $(node -v)" -echo "NPM version: $(npm -v)" -``` - -## Environment-specific Customization - -Có thể customize workflows theo environment: - -### Development: -- Sử dụng `npm run dev` thay vì `production` -- Skip database migrations -- Enable debug mode - -### Staging: -- Sử dụng `npm run production` -- Include database migrations -- Moderate optimization - -### Production: -- Sử dụng `npm run minify-all` -- Full optimization -- Backup và cleanup -- Queue restart \ No newline at end of file diff --git a/config/assets.php b/config/assets.php new file mode 100644 index 0000000..086f348 --- /dev/null +++ b/config/assets.php @@ -0,0 +1,37 @@ + [ + 'css' => [ + 'resources/sass/app.scss', + 'resources/css/components/micromodal.css', + ], + 'js' => [ + 'resources/js/pages/color-modes.js', + 'resources/js/app-vite.js', + 'resources/js/pages/template.js', + 'resources/js/components/micromodal.js', + ], + ], + 'static' => [ + 'css' => [ + 'build/plugins/perfect-scrollbar/perfect-scrollbar.css', + ], + 'js' => [ + 'build/plugins/bootstrap/bootstrap.bundle.min.js', + 'build/plugins/lucide/lucide.min.js', + 'build/plugins/perfect-scrollbar/perfect-scrollbar.min.js', + ], + ], + 'datatable' => [ + 'css'=> [ + 'build/plugins/select2/select2.min.css' + ], + 'js' => [ + 'build/plugins/jquery/jquery.min.js', + 'build/plugins/select2/select2.min.js', + 'build/plugins/datatables.net/dataTables.min.js', + 'build/plugins/datatables.net-bs5/dataTables.bootstrap5.min.js' + ] + ] +]; \ No newline at end of file diff --git a/resources/views/administrator/layout/master.blade.php b/resources/views/administrator/layout/master.blade.php index ff5c633..8f6dc36 100644 --- a/resources/views/administrator/layout/master.blade.php +++ b/resources/views/administrator/layout/master.blade.php @@ -15,11 +15,8 @@ Thế Giới Số Admin | Service Management Portal - - @vite(['resources/js/pages/color-modes.js']) - - - + + @foreach (config('assets.static.js') as $js) + + @endforeach @stack('plugin-scripts') - - @vite(['resources/js/pages/template.js']) - - - @vite(['resources/js/components/micromodal.js']) - - - - - + @foreach (config('assets.datatable.js') as $js) + + @endforeach @endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/datacenter/index.blade.php b/resources/views/administrator/pages/package/datacenter/index.blade.php index e3959d7..f79a347 100644 --- a/resources/views/administrator/pages/package/datacenter/index.blade.php +++ b/resources/views/administrator/pages/package/datacenter/index.blade.php @@ -1,6 +1,8 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush @section('breadcrumb') @@ -35,9 +37,8 @@ $breadcrumbItems = [ @endif @endsection - @push('plugin-scripts') - - - - - @endpush \ No newline at end of file +@push('plugin-scripts') + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach +@endpush \ No newline at end of file diff --git a/resources/views/components/admin-breadcrumb.blade.php b/resources/views/components/admin-breadcrumb.blade.php index e2a7648..ef81205 100644 --- a/resources/views/components/admin-breadcrumb.blade.php +++ b/resources/views/components/admin-breadcrumb.blade.php @@ -1,7 +1,7 @@ @props(['items' => []])