vibes-plug 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/BLUEPRINT.md +125 -0
- package/CHANGELOG.md +195 -0
- package/CONTRIBUTING.md +199 -0
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/SECURITY.md +21 -0
- package/banner.png +0 -0
- package/package.json +25 -0
- package/plugin.json +8 -0
- package/scripts/update_skills.js +75 -0
- package/skills/ai-llm-integration-expert/SKILL.md +162 -0
- package/skills/api-design-expert/SKILL.md +310 -0
- package/skills/app-analyzer-optimizer/SKILL.md +189 -0
- package/skills/asisten_ramah/SKILL.md +41 -0
- package/skills/authentication-identity-expert/SKILL.md +45 -0
- package/skills/auto-doc-updater/SKILL.md +204 -0
- package/skills/bootstrap-to-modern/SKILL.md +87 -0
- package/skills/brainstorming/SKILL.md +353 -0
- package/skills/bun-runtime-expert/SKILL.md +211 -0
- package/skills/ci-cd-devops-architect/SKILL.md +45 -0
- package/skills/cloud-hosting-expert/SKILL.md +244 -0
- package/skills/coderabbit/SKILL.md +192 -0
- package/skills/data-telemetry-expert/SKILL.md +213 -0
- package/skills/database-orm-expert/SKILL.md +294 -0
- package/skills/design-system-architect/SKILL.md +243 -0
- package/skills/e2e-testing-expert/SKILL.md +315 -0
- package/skills/event-driven-architect/SKILL.md +81 -0
- package/skills/firebase-security-expert/SKILL.md +195 -0
- package/skills/fullstack-expert/SKILL.md +202 -0
- package/skills/fullstack-expert/references/api_design_guide.md +466 -0
- package/skills/fullstack-expert/references/devops_infrastructure.md +477 -0
- package/skills/fullstack-expert/references/multi_language_backend.md +528 -0
- package/skills/fullstack-expert/references/system_design_patterns.md +358 -0
- package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -0
- package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -0
- package/skills/gemini-agent-booster/SKILL.md +135 -0
- package/skills/global-a11y-i18n-expert/SKILL.md +81 -0
- package/skills/go-programming-expert/SKILL.md +295 -0
- package/skills/hig/SKILL.md +188 -0
- package/skills/js-backend-expert/SKILL.md +192 -0
- package/skills/mcp-server-architect/SKILL.md +194 -0
- package/skills/mobile-expo-expert/SKILL.md +186 -0
- package/skills/monday-design-aesthetic/SKILL.md +67 -0
- package/skills/monorepo-architect/SKILL.md +227 -0
- package/skills/mpa-orchestrator/SKILL.md +101 -0
- package/skills/multi-agent-orchestration/SKILL.md +234 -0
- package/skills/multiple-entry-points/SKILL.md +55 -0
- package/skills/mvc-expert/SKILL.md +231 -0
- package/skills/payment-gateway-expert/SKILL.md +45 -0
- package/skills/performance-web-vitals/SKILL.md +332 -0
- package/skills/prd-architect/SKILL.md +191 -0
- package/skills/production-ready-hardener/SKILL.md +469 -0
- package/skills/production-ready-hardener/references/performance_optimization.md +441 -0
- package/skills/production-ready-hardener/references/production_checklist.md +161 -0
- package/skills/production-ready-hardener/references/security_hardening_guide.md +379 -0
- package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +875 -0
- package/skills/python-programming-expert/SKILL.md +271 -0
- package/skills/realtime-collaboration-expert/SKILL.md +45 -0
- package/skills/rust-programming-expert/SKILL.md +235 -0
- package/skills/saas-billing/SKILL.md +377 -0
- package/skills/saas-multi-tenant/SKILL.md +237 -0
- package/skills/saas-mvp-launcher/SKILL.md +231 -0
- package/skills/saas-transformer/SKILL.md +446 -0
- package/skills/saas-transformer/references/billing_integration_guide.md +401 -0
- package/skills/saas-transformer/references/feature_gating_patterns.md +137 -0
- package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -0
- package/skills/saas-transformer/scripts/saas_transformation_scanner.py +254 -0
- package/skills/scalability-clean-code/SKILL.md +229 -0
- package/skills/secure-fuzz-testing/SKILL.md +201 -0
- package/skills/senior-frontend/SKILL.md +161 -0
- package/skills/senior-frontend/references/frontend_best_practices.md +806 -0
- package/skills/senior-frontend/references/nextjs_optimization_guide.md +724 -0
- package/skills/senior-frontend/references/react_patterns.md +746 -0
- package/skills/senior-frontend/scripts/bundle_analyzer.py +407 -0
- package/skills/senior-frontend/scripts/component_generator.py +329 -0
- package/skills/senior-frontend/scripts/frontend_scaffolder.py +1005 -0
- package/skills/senior-fullstack/SKILL.md +167 -0
- package/skills/senior-fullstack/references/architecture_patterns.md +160 -0
- package/skills/senior-fullstack/references/development_workflows.md +222 -0
- package/skills/senior-fullstack/references/tech_stack_guide.md +190 -0
- package/skills/senior-fullstack/scripts/code_quality_analyzer.py +114 -0
- package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +114 -0
- package/skills/senior-fullstack/scripts/project_scaffolder.py +114 -0
- package/skills/seo/SKILL.md +225 -0
- package/skills/seo/references/cwv-thresholds.md +108 -0
- package/skills/seo/references/eeat-framework.md +214 -0
- package/skills/seo/references/quality-gates.md +155 -0
- package/skills/seo/references/schema-types.md +118 -0
- package/skills/seo-aeo-landing-page-writer/SKILL.md +97 -0
- package/skills/seo-geo/SKILL.md +188 -0
- package/skills/session-handoff-resume/SKILL.md +158 -0
- package/skills/skill_baru/SKILL.md +147 -0
- package/skills/spa-orchestrator/SKILL.md +288 -0
- package/skills/state-management-expert/SKILL.md +272 -0
- package/skills/supabase-migration/SKILL.md +45 -0
- package/skills/supabase-security-expert/SKILL.md +243 -0
- package/skills/tailwind-expert/SKILL.md +188 -0
- package/skills/tanstack-query-expert/SKILL.md +199 -0
- package/skills/tauri-expert/SKILL.md +97 -0
- package/skills/token-saver/SKILL.md +111 -0
- package/skills/typescript-expert/SKILL.md +279 -0
- package/skills/ui-components-expert/SKILL.md +63 -0
- package/skills/ui-ux-pro-max/SKILL.md +201 -0
- package/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
- package/skills/ui-ux-pro-max/scripts/core.py +257 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +493 -0
- package/skills/ui-ux-pro-max/scripts/search.py +81 -0
- package/skills/ui_ux_expert/SKILL.md +114 -0
- package/skills/vibe-code-gardener/SKILL.md +173 -0
- package/skills/web-scraper/SKILL.md +205 -0
- package/skills/web-scraper/references/data-transforms.md +397 -0
- package/skills/web-scraper/references/extraction-patterns.md +475 -0
- package/skills/web-scraper/references/output-templates.md +481 -0
- package/skills/zero-to-prod-orchestrator/SKILL.md +180 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mpa-orchestrator
|
|
3
|
+
description: "Orchestrates Multi-Page Application (MPA) architecture within a single repository, integrating with relevant skills / Mengorkestrasi arsitektur Multi-Page Application (MPA) dalam satu repositori, terintegrasi dengan skill relevan lainnya."
|
|
4
|
+
author: "Antigravity"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Multi-Page Application (MPA) Orchestrator (2026 Edition)
|
|
8
|
+
|
|
9
|
+
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<a name="english"></a>
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
### Description
|
|
17
|
+
A structured approach for building and orchestrating Multi-Page Application (MPA) architectures within a single repository. Acts as an orchestrator connecting MPA principles with specialized skills (like `mvc-expert`, `saas-multi-tenant`, `senior-frontend`) to deliver cohesive, server-rendered applications. In 2026, MPAs are increasingly built with **Astro 5** for content-heavy sites or **traditional server frameworks** (Laravel, Django, Go) augmented with **HTMX 2** or **Alpine.js** for interactivity.
|
|
18
|
+
|
|
19
|
+
### Core MPA Principles in a Single Repository
|
|
20
|
+
1. **Centralized Architecture**: Frontend views, backend logic, and routing in a unified codebase — simplifies deployment and reduces cognitive load.
|
|
21
|
+
2. **Server-Side Routing & Rendering**: A Front Controller intercepts requests, fetches data, and renders complete HTML per route. Options in 2026:
|
|
22
|
+
- **Astro 5**: Best for content-heavy sites — renders to static HTML by default, hydrates islands on demand.
|
|
23
|
+
- **Next.js 15 (Pages Router)**: Traditional MPA feel with React components.
|
|
24
|
+
- **Backend-driven**: Laravel/Django/Gin templates rendered server-side.
|
|
25
|
+
3. **Islands Architecture (Astro 5)**:
|
|
26
|
+
- Render 100% static HTML for non-interactive content.
|
|
27
|
+
- Use `client:load`, `client:idle`, or `client:visible` directives to hydrate interactive islands only when needed.
|
|
28
|
+
- Supports React, Vue, Svelte, Solid, or vanilla JS islands side by side.
|
|
29
|
+
4. **HTMX 2 — HTML-First Interactivity**:
|
|
30
|
+
- Enhance any server-rendered page with partial HTML swaps without writing JavaScript.
|
|
31
|
+
- Works with any backend — Django, Laravel, Go, Node.js.
|
|
32
|
+
- `hx-get`, `hx-post`, `hx-target`, `hx-swap` for declarative AJAX.
|
|
33
|
+
5. **Shared UI Ecosystem**:
|
|
34
|
+
- Maintain a `layouts/` directory for base HTML structures.
|
|
35
|
+
- Maintain a `components/` directory for reusable UI elements.
|
|
36
|
+
6. **Asset Management**: Centralize static assets in `public/`. Implement cache-busting for production.
|
|
37
|
+
7. **Session-based State**: Use secure HTTP-only cookies and server sessions for auth, tenant context, and flash messages.
|
|
38
|
+
|
|
39
|
+
### Framework Selection Guide
|
|
40
|
+
|
|
41
|
+
| Need | Recommended Stack |
|
|
42
|
+
|---|---|
|
|
43
|
+
| Content site / Blog / Docs | **Astro 5** + MDX + Tailwind v4 |
|
|
44
|
+
| Full server-rendered app (PHP) | **Laravel 11** + Livewire 3 / Alpine.js |
|
|
45
|
+
| Full server-rendered app (Python) | **Django 5** + HTMX 2 + Alpine.js |
|
|
46
|
+
| Full server-rendered app (Go) | **Templ** + HTMX 2 + Tailwind v4 |
|
|
47
|
+
| React MPA with SSR | **Next.js 15** Pages Router or App Router |
|
|
48
|
+
|
|
49
|
+
### Orchestration Guidelines
|
|
50
|
+
- **With `mvc-expert`**: Enforce MVC pattern — Controllers handle logic, Views handle rendering.
|
|
51
|
+
- **With `saas-multi-tenant`**: Integrate tenant identification in core routing middleware — every page load initializes `tenant_id` context securely.
|
|
52
|
+
- **With `senior-frontend` / `ui-ux-pro-max`**: Enhance with Alpine.js for reactive UI or HTMX 2 for HTML-driven partial updates — no heavy client-side bundles.
|
|
53
|
+
- **With `seo`**: Maximize MPA's inherent SEO advantages — every page returns fully populated HTML, correct meta tags, and Schema.org JSON-LD on initial load.
|
|
54
|
+
- **vs `spa-orchestrator`**: Choose MPA when SEO is critical, data is mostly read-heavy, and complex client-side state is not required. Choose SPA when the app is highly interactive and session-based (like dashboards).
|
|
55
|
+
|
|
56
|
+
### Trigger Conditions
|
|
57
|
+
- Building a web application using the Multi-Page Application (MPA) approach in a single repository.
|
|
58
|
+
- Refactoring or migrating an existing app to a centralized MPA architecture.
|
|
59
|
+
- Building content sites, marketing pages, or SEO-critical applications.
|
|
60
|
+
- Using Astro 5 for static or content-heavy sites with optional interactive islands.
|
|
61
|
+
- Adding interactivity to server-rendered pages with HTMX 2 without a full SPA rewrite.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
<a name="bahasa-indonesia"></a>
|
|
66
|
+
## Bahasa Indonesia
|
|
67
|
+
|
|
68
|
+
### Deskripsi
|
|
69
|
+
Pendekatan terstruktur untuk membangun dan mengorkestrasi arsitektur Multi-Page Application (MPA) di dalam satu repositori. Bertindak sebagai orkestrator yang menghubungkan prinsip MPA dengan skill spesialis lain untuk menghasilkan aplikasi server-rendered yang kohesif dan modern. Di 2026, MPA semakin banyak dibangun dengan **Astro 5** untuk situs konten-berat atau framework server tradisional yang diperkuat dengan **HTMX 2** atau **Alpine.js**.
|
|
70
|
+
|
|
71
|
+
### Prinsip Inti MPA
|
|
72
|
+
1. **Arsitektur Terpusat**: View frontend, logika backend, dan routing dalam satu codebase.
|
|
73
|
+
2. **Routing & Rendering Sisi Server**: Front Controller menangkap permintaan, mengambil data, dan me-render HTML lengkap per rute.
|
|
74
|
+
3. **Islands Architecture (Astro 5)**: Render HTML statis 100% secara default, hidrate island interaktif hanya saat diperlukan.
|
|
75
|
+
4. **HTMX 2 — Interaktivitas HTML-First**: Tingkatkan halaman server-rendered dengan pertukaran HTML parsial tanpa menulis JavaScript.
|
|
76
|
+
5. **Ekosistem UI Bersama**: Direktori `layouts/` dan `components/` untuk elemen UI yang dapat digunakan kembali.
|
|
77
|
+
6. **State Berbasis Session**: Cookie HTTP-only dan session sisi server untuk autentikasi dan konteks tenant.
|
|
78
|
+
|
|
79
|
+
### Panduan Pemilihan Framework
|
|
80
|
+
|
|
81
|
+
| Kebutuhan | Stack yang Direkomendasikan |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Situs konten / Blog / Docs | **Astro 5** + MDX + Tailwind v4 |
|
|
84
|
+
| Aplikasi server-rendered (PHP) | **Laravel 11** + Livewire 3 / Alpine.js |
|
|
85
|
+
| Aplikasi server-rendered (Python) | **Django 5** + HTMX 2 + Alpine.js |
|
|
86
|
+
| Aplikasi server-rendered (Go) | **Templ** + HTMX 2 + Tailwind v4 |
|
|
87
|
+
| React MPA dengan SSR | **Next.js 15** Pages Router atau App Router |
|
|
88
|
+
|
|
89
|
+
### Panduan Orkestrasi
|
|
90
|
+
- **Dengan `mvc-expert`**: Pastikan MPA mengikuti pola MVC secara ketat.
|
|
91
|
+
- **Dengan `saas-multi-tenant`**: Integrasikan identifikasi tenant di middleware routing inti.
|
|
92
|
+
- **Dengan `senior-frontend` / `ui-ux-pro-max`**: Tingkatkan dengan Alpine.js atau HTMX 2 untuk interaksi tanpa bundle berat.
|
|
93
|
+
- **Dengan `seo`**: Setiap halaman mengembalikan HTML penuh, tag meta, dan JSON-LD terisi saat load awal.
|
|
94
|
+
- **vs `spa-orchestrator`**: Pilih MPA saat SEO kritis dan data kebanyakan read-heavy. Pilih SPA saat aplikasi sangat interaktif seperti dashboard.
|
|
95
|
+
|
|
96
|
+
### Kondisi Pemicu
|
|
97
|
+
- Membangun aplikasi web dengan pendekatan MPA dalam satu repositori.
|
|
98
|
+
- Refaktor atau migrasi aplikasi yang ada ke arsitektur MPA terpusat.
|
|
99
|
+
- Membangun situs konten, halaman marketing, atau aplikasi kritis SEO.
|
|
100
|
+
- Menggunakan Astro 5 untuk situs statis atau konten-berat dengan island interaktif opsional.
|
|
101
|
+
- Menambahkan interaktivitas ke halaman server-rendered dengan HTMX 2 tanpa menulis ulang ke SPA.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: multi-agent-orchestration
|
|
3
|
+
description: "Expert guide for designing and orchestrating multi-agent systems, agent swarms, graph-based workflows (LangGraph, CrewAI, AutoGen), shared state memory, and human-in-the-loop guardrails in English and Indonesian."
|
|
4
|
+
author: "Roedy Rustam"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Multi-Agent Orchestration Expert (2026 Edition)
|
|
8
|
+
|
|
9
|
+
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<a name="english"></a>
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
### Description
|
|
17
|
+
Expert guide for designing, building, and deploying production-grade multi-agent AI systems. Covers agent orchestration frameworks (LangGraph, OpenAI Agents SDK, Google ADK, Mastra.ai, CrewAI, AutoGen), shared state and memory management, tool execution, human-in-the-loop (HITL) guardrails, and observability for agentic workflows.
|
|
18
|
+
|
|
19
|
+
**Swarm Synergy:** This skill acts as a powerful orchestrator when combined with `mcp-server-architect` (for external tool integration) and `ai-llm-integration-expert` (for foundation model setup). Together, they form a complete, end-to-end **AI Engineering Swarm**.
|
|
20
|
+
|
|
21
|
+
### Trigger Conditions
|
|
22
|
+
- Building autonomous AI agents that execute multi-step tasks.
|
|
23
|
+
- Designing systems where multiple specialized AI agents collaborate.
|
|
24
|
+
- Implementing graph-based agent workflows with LangGraph or similar frameworks.
|
|
25
|
+
- Integrating human-in-the-loop checkpoints for high-stakes decisions.
|
|
26
|
+
- Building AI pipelines with tool-calling, RAG retrieval, code execution, or browser control.
|
|
27
|
+
- Evaluating and selecting agent frameworks (LangGraph vs OpenAI Agents SDK vs Google ADK).
|
|
28
|
+
|
|
29
|
+
### Agent Framework Comparison (2026)
|
|
30
|
+
|
|
31
|
+
| Framework | Language | Best For | Key Differentiator |
|
|
32
|
+
|---|---|---|---|
|
|
33
|
+
| **LangGraph** | Python / TypeScript | Complex stateful workflows | Graph-based, any LLM, full control |
|
|
34
|
+
| **OpenAI Agents SDK** | Python | GPT-5 native agents | Built-in handoffs, tracing, guardrails |
|
|
35
|
+
| **Google ADK** | Python | Gemini-powered agents | Multi-agent, Vertex AI, streaming |
|
|
36
|
+
| **Mastra.ai** | TypeScript | TS-first agent apps | Built-in memory, evals, RAG, MCP |
|
|
37
|
+
| **CrewAI** | Python | Team-of-agents tasks | Role-based agents, easy to start |
|
|
38
|
+
| **AutoGen** | Python | Research & LLM evaluation | Conversation-driven agents |
|
|
39
|
+
|
|
40
|
+
### Core Architecture Principles
|
|
41
|
+
|
|
42
|
+
#### 1. Agent Roles & Specialization
|
|
43
|
+
Design agents with single responsibilities — avoid "do-everything" agents:
|
|
44
|
+
- **Orchestrator Agent**: Routes tasks, decomposes goals, delegates to specialists.
|
|
45
|
+
- **Specialist Agents**: Domain-specific (research agent, code agent, data analyst, writer).
|
|
46
|
+
- **Tool Agents**: Wrap external capabilities (browser agent, SQL agent, file agent).
|
|
47
|
+
- **Critic/Validator Agent**: Reviews output of other agents before finalizing.
|
|
48
|
+
|
|
49
|
+
#### 2. LangGraph — Stateful Graph Workflows
|
|
50
|
+
LangGraph models agent workflows as directed graphs with persistent state — ideal for complex, multi-step tasks with branching logic and HITL:
|
|
51
|
+
```python
|
|
52
|
+
from langgraph.graph import StateGraph, END
|
|
53
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
54
|
+
from typing import TypedDict, Annotated
|
|
55
|
+
import operator
|
|
56
|
+
|
|
57
|
+
class AgentState(TypedDict):
|
|
58
|
+
messages: Annotated[list, operator.add]
|
|
59
|
+
task: str
|
|
60
|
+
result: str
|
|
61
|
+
|
|
62
|
+
def research_node(state: AgentState):
|
|
63
|
+
# Call research agent
|
|
64
|
+
return {"messages": [research_agent.invoke(state["task"])]}
|
|
65
|
+
|
|
66
|
+
def write_node(state: AgentState):
|
|
67
|
+
# Call writing agent with research result
|
|
68
|
+
return {"result": writing_agent.invoke(state["messages"])}
|
|
69
|
+
|
|
70
|
+
def should_revise(state: AgentState) -> str:
|
|
71
|
+
# Conditional routing
|
|
72
|
+
return "revise" if needs_revision(state["result"]) else "end"
|
|
73
|
+
|
|
74
|
+
builder = StateGraph(AgentState)
|
|
75
|
+
builder.add_node("research", research_node)
|
|
76
|
+
builder.add_node("write", write_node)
|
|
77
|
+
builder.add_conditional_edges("write", should_revise, {"revise": "research", "end": END})
|
|
78
|
+
|
|
79
|
+
# Persist state for HITL
|
|
80
|
+
memory = MemorySaver()
|
|
81
|
+
graph = builder.compile(checkpointer=memory, interrupt_before=["write"])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### 3. OpenAI Agents SDK — Handoffs & Guardrails
|
|
85
|
+
Use the OpenAI Agents SDK for native GPT-5 agent workflows with built-in tracing:
|
|
86
|
+
```python
|
|
87
|
+
from agents import Agent, Runner, handoff, input_guardrail, GuardrailFunctionOutput
|
|
88
|
+
|
|
89
|
+
# Define specialist agents
|
|
90
|
+
researcher = Agent(
|
|
91
|
+
name="Researcher",
|
|
92
|
+
instructions="Search and retrieve relevant information.",
|
|
93
|
+
tools=[web_search, document_retrieval],
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
writer = Agent(
|
|
97
|
+
name="Writer",
|
|
98
|
+
instructions="Write high-quality content based on research.",
|
|
99
|
+
handoffs=[handoff(researcher, tool_name_override="get_research")],
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# Input guardrail to prevent harmful requests
|
|
103
|
+
@input_guardrail
|
|
104
|
+
async def content_filter(ctx, agent, input) -> GuardrailFunctionOutput:
|
|
105
|
+
if contains_harmful_content(input):
|
|
106
|
+
return GuardrailFunctionOutput(output_info="Blocked", tripwire_triggered=True)
|
|
107
|
+
return GuardrailFunctionOutput(output_info="OK", tripwire_triggered=False)
|
|
108
|
+
|
|
109
|
+
# Run with tracing
|
|
110
|
+
result = await Runner.run(writer, "Write an article about...", guardrails=[content_filter])
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### 4. Google ADK — Gemini Multi-Agent
|
|
114
|
+
Google Agent Development Kit (ADK) for building Gemini-powered agents with Vertex AI integration:
|
|
115
|
+
```python
|
|
116
|
+
from google.adk.agents import Agent
|
|
117
|
+
from google.adk.tools import google_search, code_execution
|
|
118
|
+
|
|
119
|
+
root_agent = Agent(
|
|
120
|
+
model="gemini-2.5-pro",
|
|
121
|
+
name="orchestrator",
|
|
122
|
+
instruction="Coordinate research and analysis tasks.",
|
|
123
|
+
sub_agents=[research_agent, analysis_agent],
|
|
124
|
+
tools=[google_search, code_execution],
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### 5. Mastra.ai — TypeScript-First Agents
|
|
129
|
+
For TypeScript teams, Mastra provides the most complete agentic framework:
|
|
130
|
+
```typescript
|
|
131
|
+
import { Agent, MastraMemory } from '@mastra/core';
|
|
132
|
+
import { createTool } from '@mastra/core/tools';
|
|
133
|
+
|
|
134
|
+
const webSearchTool = createTool({
|
|
135
|
+
id: 'web-search',
|
|
136
|
+
description: 'Search the web for current information',
|
|
137
|
+
inputSchema: z.object({ query: z.string() }),
|
|
138
|
+
execute: async ({ context: { query } }) => searchWeb(query),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const researchAgent = new Agent({
|
|
142
|
+
name: 'researcher',
|
|
143
|
+
instructions: 'Find and summarize information accurately.',
|
|
144
|
+
model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-5' },
|
|
145
|
+
tools: { webSearch: webSearchTool },
|
|
146
|
+
memory: new MastraMemory({ storage: supabaseStorage }),
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### 6. Human-in-the-Loop (HITL) Guardrails
|
|
151
|
+
Mandatory for high-stakes agent actions (financial transactions, email sending, code deployment):
|
|
152
|
+
- **Interrupt Checkpoints**: Pause graph execution before irreversible actions.
|
|
153
|
+
- **Approval Flows**: Send pending action to a UI for human review before continuing.
|
|
154
|
+
- **Confidence Thresholds**: Auto-approve if confidence > 90%, escalate if < 70%.
|
|
155
|
+
|
|
156
|
+
#### 7. Agent Memory Architecture
|
|
157
|
+
- **Working Memory (In-context)**: Recent messages and task state in the prompt window.
|
|
158
|
+
- **Episodic Memory**: Summarized past sessions stored as embeddings (Mem0, MemGPT).
|
|
159
|
+
- **Semantic Memory**: Domain knowledge in a vector store (pgvector, Qdrant).
|
|
160
|
+
- **Procedural Memory**: Learned tool-use patterns stored as structured data.
|
|
161
|
+
|
|
162
|
+
#### 8. Observability & Evaluation
|
|
163
|
+
- **LangSmith**: Native tracing for LangGraph, LangChain agents.
|
|
164
|
+
- **OpenAI Tracing**: Built-in in OpenAI Agents SDK — view agent runs, handoffs, tool calls.
|
|
165
|
+
- **Mastra Evals**: Built-in evaluation framework for Mastra agents.
|
|
166
|
+
- **Custom Metrics**: Track task completion rate, tool call accuracy, latency, and cost per run.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
<a name="bahasa-indonesia"></a>
|
|
171
|
+
## Bahasa Indonesia
|
|
172
|
+
|
|
173
|
+
### Deskripsi
|
|
174
|
+
Panduan ahli untuk merancang, membangun, dan men-deploy sistem multi-agen AI tingkat produksi. Mencakup framework orkestrasi agen (LangGraph, OpenAI Agents SDK, Google ADK, Mastra.ai), manajemen state dan memori bersama, eksekusi tool, guardrail human-in-the-loop (HITL), dan observabilitas untuk alur kerja agentik.
|
|
175
|
+
|
|
176
|
+
**Sinergi Swarm:** Skill ini bertindak sebagai orkestrator yang sangat *powerful* jika dikombinasikan dengan `mcp-server-architect` (untuk integrasi eksternal tool) dan `ai-llm-integration-expert` (untuk penyiapan foundation model). Bersama-sama, ketiganya membentuk **AI Engineering Swarm** yang komprehensif dari ujung ke ujung.
|
|
177
|
+
|
|
178
|
+
### Kondisi Pemicu
|
|
179
|
+
- Membangun agen AI otonom yang mengeksekusi tugas multi-langkah.
|
|
180
|
+
- Merancang sistem di mana beberapa agen AI khusus berkolaborasi.
|
|
181
|
+
- Mengimplementasikan alur kerja agen berbasis graph dengan LangGraph atau framework serupa.
|
|
182
|
+
- Mengintegrasikan checkpoint human-in-the-loop untuk keputusan berisiko tinggi.
|
|
183
|
+
- Membangun pipeline AI dengan tool-calling, RAG, eksekusi kode, atau kontrol browser.
|
|
184
|
+
- Mengevaluasi dan memilih framework agen yang tepat.
|
|
185
|
+
|
|
186
|
+
### Perbandingan Framework Agen (2026)
|
|
187
|
+
|
|
188
|
+
| Framework | Bahasa | Terbaik Untuk | Diferensiasi Kunci |
|
|
189
|
+
|---|---|---|---|
|
|
190
|
+
| **LangGraph** | Python / TS | Alur kerja stateful kompleks | Berbasis graph, LLM apa saja, kontrol penuh |
|
|
191
|
+
| **OpenAI Agents SDK** | Python | Agen GPT-5 native | Handoffs, tracing, guardrails bawaan |
|
|
192
|
+
| **Google ADK** | Python | Agen berbasis Gemini | Multi-agen, Vertex AI, streaming |
|
|
193
|
+
| **Mastra.ai** | TypeScript | Aplikasi agen TS-first | Memori, evaluasi, RAG, MCP bawaan |
|
|
194
|
+
| **CrewAI** | Python | Tugas tim-agen | Agen berbasis peran, mudah dimulai |
|
|
195
|
+
| **AutoGen** | Python | Riset & evaluasi LLM | Agen berbasis percakapan |
|
|
196
|
+
|
|
197
|
+
### Prinsip Arsitektur Inti
|
|
198
|
+
|
|
199
|
+
#### 1. Peran & Spesialisasi Agen
|
|
200
|
+
Rancang agen dengan tanggung jawab tunggal:
|
|
201
|
+
- **Orchestrator Agent**: Mendelegasikan tugas ke agen spesialis.
|
|
202
|
+
- **Specialist Agents**: Domain-spesifik (agen riset, kode, analis data, penulis).
|
|
203
|
+
- **Tool Agents**: Membungkus kemampuan eksternal (browser, SQL, file).
|
|
204
|
+
- **Critic/Validator Agent**: Meninjau output agen lain sebelum difinalisasi.
|
|
205
|
+
|
|
206
|
+
#### 2. LangGraph — Alur Kerja Graf Stateful
|
|
207
|
+
LangGraph memodelkan alur kerja agen sebagai graf terarah dengan state persisten — ideal untuk tugas kompleks dengan logika percabangan dan HITL. State disimpan di checkpointer (MemorySaver atau PostgreSQL) untuk resume antar sesi.
|
|
208
|
+
|
|
209
|
+
#### 3. OpenAI Agents SDK — Handoffs & Guardrails
|
|
210
|
+
SDK native untuk agen GPT-5 dengan handoffs agen-ke-agen, tracing bawaan, dan guardrails untuk mencegah output berbahaya.
|
|
211
|
+
|
|
212
|
+
#### 4. Google ADK — Agen Gemini Multi-Agent
|
|
213
|
+
ADK untuk membangun agen Gemini dengan integrasi Vertex AI, sub-agents, dan tool seperti Google Search dan eksekusi kode.
|
|
214
|
+
|
|
215
|
+
#### 5. Mastra.ai — Agen TypeScript-First
|
|
216
|
+
Framework paling lengkap untuk tim TypeScript: memori bawaan, evaluasi, RAG, dan dukungan MCP native.
|
|
217
|
+
|
|
218
|
+
#### 6. Human-in-the-Loop (HITL) Guardrails
|
|
219
|
+
Wajib untuk aksi agen berisiko tinggi (transaksi keuangan, pengiriman email, deployment kode):
|
|
220
|
+
- **Interrupt Checkpoints**: Jeda eksekusi graf sebelum aksi tidak dapat dibalik.
|
|
221
|
+
- **Approval Flows**: Kirim aksi yang menunggu ke UI untuk ditinjau manusia.
|
|
222
|
+
- **Confidence Thresholds**: Auto-approve jika keyakinan > 90%, eskalasi jika < 70%.
|
|
223
|
+
|
|
224
|
+
#### 7. Arsitektur Memori Agen
|
|
225
|
+
- **Working Memory**: Riwayat percakapan recent dalam context window.
|
|
226
|
+
- **Episodic Memory**: Sesi masa lalu yang diringkas sebagai embedding (Mem0).
|
|
227
|
+
- **Semantic Memory**: Pengetahuan domain dalam vector store (pgvector, Qdrant).
|
|
228
|
+
- **Procedural Memory**: Pola penggunaan tool yang dipelajari sebagai data terstruktur.
|
|
229
|
+
|
|
230
|
+
#### 8. Observabilitas & Evaluasi
|
|
231
|
+
- **LangSmith**: Tracing native untuk LangGraph.
|
|
232
|
+
- **OpenAI Tracing**: Bawaan di OpenAI Agents SDK — lihat run, handoff, tool call.
|
|
233
|
+
- **Mastra Evals**: Framework evaluasi bawaan untuk agen Mastra.
|
|
234
|
+
- **Metrik Kustom**: Lacak tingkat penyelesaian tugas, akurasi tool call, latensi, dan biaya per run.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: multiple-entry-points
|
|
3
|
+
description: "Expert guide for designing and implementing Multiple Entry Points architecture in web applications / Panduan ahli untuk merancang dan mengimplementasikan arsitektur Multiple Entry Points pada aplikasi web."
|
|
4
|
+
author: "Antigravity"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Multiple Entry Points Architecture
|
|
8
|
+
|
|
9
|
+
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<a name="english"></a>
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
### Description
|
|
17
|
+
This skill outlines the architectural pattern of using Multiple Entry Points in a web application. Instead of forcing all traffic through a single Front Controller (like a monolithic `index.php`), the application separates traffic logically into distinct entry files such as `index.php` (public), `admin.php`, and `api.php`. This provides stronger isolation, optimized loading, and stricter security boundaries.
|
|
18
|
+
|
|
19
|
+
### Core Principles of Multiple Entry Points
|
|
20
|
+
1. **Logical Separation**: Isolate different application domains into their own entry files. For example: `public/index.php` for user-facing pages, `public/admin.php` for back-office operations, and `public/api.php` for stateless API routes.
|
|
21
|
+
2. **Dedicated Bootstrapping**: Each entry point can bootstrap only the necessary dependencies, configurations, and middlewares it requires. For example, `api.php` does not need to initialize HTML template engines or stateful session cookies, while `admin.php` can enforce strict authentication middleware immediately upon execution.
|
|
22
|
+
3. **Security Boundaries**: By physically separating entry points, you can apply distinct server-level security rules (via `.htaccess`, Nginx configurations, or WAF). For example, you can restrict access to `admin.php` to specific internal IP addresses or enforce mutual TLS.
|
|
23
|
+
4. **Frontend Asset Bundling (Vite / Webpack)**: In a modern frontend context (especially for MPAs), define multiple entry points in the bundler configuration. This generates separate, optimized JavaScript and CSS bundles for the public site versus the complex admin dashboard, drastically reducing overall payload sizes for general users.
|
|
24
|
+
|
|
25
|
+
### Orchestration with Other Skills
|
|
26
|
+
- **With `mpa-orchestrator`**: In a Multi-Page Application, multiple entry points allow you to split heavy dashboard assets from fast-loading public marketing pages, enhancing both SEO and performance.
|
|
27
|
+
- **With `mvc-expert`**: Each entry point acts as a distinct Front Controller, initiating its own lightweight Router instance configured specifically for that domain's controllers (e.g., an AdminRouter vs an ApiRouter).
|
|
28
|
+
- **With `saas-multi-tenant`**: You can design a `tenant.php` entry point that strictly mandates a valid `tenant_id` resolution before bootstrapping the app, while a `landing.php` entry point handles anonymous public traffic safely.
|
|
29
|
+
|
|
30
|
+
### Trigger Conditions
|
|
31
|
+
- Active when building or refactoring applications that require strict separation between public, admin, and API traffic.
|
|
32
|
+
- Active when optimizing frontend bundler configurations (like Vite) for Multi-Page Applications.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
<a name="bahasa-indonesia"></a>
|
|
37
|
+
## Bahasa Indonesia
|
|
38
|
+
|
|
39
|
+
### Deskripsi
|
|
40
|
+
Skill ini menguraikan pola arsitektur menggunakan *Multiple Entry Points* dalam aplikasi web. Alih-alih memaksa semua lalu lintas (traffic) melalui satu Front Controller tunggal (seperti `index.php` monolitik), aplikasi memisahkan lalu lintas secara logis ke dalam file entri yang berbeda seperti `index.php` (publik), `admin.php`, dan `api.php`. Pola ini memberikan isolasi yang lebih kuat, pemuatan (loading) yang dioptimalkan, dan batas keamanan yang lebih ketat.
|
|
41
|
+
|
|
42
|
+
### Prinsip Inti Multiple Entry Points
|
|
43
|
+
1. **Pemisahan Logis**: Isolasi domain aplikasi yang berbeda ke dalam file entrinya masing-masing. Contoh: `public/index.php` untuk pengguna umum, `public/admin.php` untuk operasional *back-office*, dan `public/api.php` untuk rute API yang *stateless*.
|
|
44
|
+
2. **Bootstrapping Terdedikasi**: Setiap titik masuk (entry point) hanya memuat dependensi, konfigurasi, dan middleware yang benar-benar diperlukannya. Contohnya, `api.php` tidak perlu menginisialisasi *template engine* HTML atau *session cookies*, sementara `admin.php` dapat langsung memberlakukan middleware autentikasi secara ketat sejak awal file dieksekusi.
|
|
45
|
+
3. **Batas Keamanan (Security Boundaries)**: Dengan memisahkan titik masuk secara fisik, Anda dapat menerapkan aturan keamanan tingkat server yang berbeda (melalui `.htaccess`, konfigurasi Nginx, atau WAF). Misalnya, membatasi akses ke `admin.php` hanya untuk alamat IP internal tertentu.
|
|
46
|
+
4. **Bundling Aset Frontend (Vite / Webpack)**: Dalam konteks frontend modern (khususnya untuk MPA), tentukan beberapa *entry points* pada konfigurasi *bundler*. Ini akan menghasilkan bundel JavaScript dan CSS yang terpisah dan optimal antara situs publik dan dashboard admin, sehingga secara drastis mengurangi ukuran *payload* bagi pengguna umum.
|
|
47
|
+
|
|
48
|
+
### Orkestrasi dengan Skill Lain
|
|
49
|
+
- **Dengan `mpa-orchestrator`**: Dalam aplikasi MPA, penggunaan beberapa *entry point* memungkinkan Anda memisahkan aset dashboard yang berat dari halaman *marketing* publik yang butuh kecepatan muat tinggi, sehingga meningkatkan SEO dan performa sekaligus.
|
|
50
|
+
- **Dengan `mvc-expert`**: Setiap *entry point* bertindak sebagai Front Controller yang terpisah, menginisiasi instans Router yang ringan dan dikonfigurasi khusus untuk controller di domain tersebut (misalnya AdminRouter vs ApiRouter).
|
|
51
|
+
- **Dengan `saas-multi-tenant`**: Anda dapat memiliki *entry point* `tenant.php` yang secara ketat mewajibkan resolusi `tenant_id` yang valid sebelum memuat aplikasi, sementara *entry point* `landing.php` melayani lalu lintas publik anonim dengan aman.
|
|
52
|
+
|
|
53
|
+
### Kondisi Pemicu
|
|
54
|
+
- Aktif saat membangun atau melakukan refaktor aplikasi yang membutuhkan pemisahan ketat antara lalu lintas publik, admin, dan API.
|
|
55
|
+
- Aktif saat mengoptimalkan konfigurasi *bundler* frontend (seperti Vite) untuk proyek Multi-Page Application.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mvc-expert
|
|
3
|
+
description: "Expert guidelines to refactor legacy PHP codebases into clean, modern, and scalable MVC-structured projects / Pedoman ahli untuk merefaktor codebase PHP lama menjadi proyek terstruktur MVC yang bersih, modern, dan skalabel."
|
|
4
|
+
author: "Antigravity"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# PHP MVC Expert & Modernization
|
|
8
|
+
|
|
9
|
+
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<a name="english"></a>
|
|
14
|
+
## English
|
|
15
|
+
|
|
16
|
+
### Description
|
|
17
|
+
This skill provides the agent with structured protocols, coding patterns, and architectural guidelines to audit, refactor, and modernize legacy/obsolete PHP codebases (plain spaghetti PHP) into a clean, modern, secure, and scalable Model-View-Controller (MVC) structure adhering to PSR standards and modern PHP (v8.2+) capabilities.
|
|
18
|
+
|
|
19
|
+
### Instructions
|
|
20
|
+
|
|
21
|
+
#### 1. Audit Protocol for Legacy PHP
|
|
22
|
+
Before writing new structures, run a detailed audit on the legacy files to map out:
|
|
23
|
+
- **Routing & Entry Points**: Identify raw `.php` files acting as endpoints (e.g., `about.php`, `contact.php`, `process.php`).
|
|
24
|
+
- **Data Access & SQL**: Find inline SQL queries, string-concatenated queries (SQL Injection risks), and direct `mysqli` or `mysql_*` usages.
|
|
25
|
+
- **Session & Global State**: Identify direct session mutations (`$_SESSION`), raw cookies, and unchecked global variables (`$_GET`, `$_POST`, `$_REQUEST`).
|
|
26
|
+
- **Spaghetti Mixing**: Locate files where database connection, business logic, session validation, and HTML rendering are in a single script.
|
|
27
|
+
- **Hardcoded Secrets**: Identify database credentials, API keys, and configurations defined inside individual files.
|
|
28
|
+
|
|
29
|
+
#### 2. Modernization Strategy & Composer Setup
|
|
30
|
+
Apply a standard project directory structure and initialize dependency management:
|
|
31
|
+
- **PSR-4 Autoloading**: Create a `composer.json` file and define namespace mappings:
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"autoload": {
|
|
35
|
+
"psr-4": {
|
|
36
|
+
"App\\": "src/"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
- **Standard Directory Structure**:
|
|
42
|
+
- `public/`: Single entry point containing `index.php` (Front Controller), assets (CSS, JS), and uploaded files.
|
|
43
|
+
- `src/`: Root namespace for MVC structure (`src/Models/`, `src/Controllers/`, `src/Views/`, `src/Core/`).
|
|
44
|
+
- `config/`: Database configurations, router configurations, and app configurations.
|
|
45
|
+
- `.env` & `.env.example`: Store environment configurations.
|
|
46
|
+
|
|
47
|
+
#### 3. Implementing MVC Architecture
|
|
48
|
+
Refactor the spaghetti code into distinct MVC layers:
|
|
49
|
+
- **Front Controller (Unified Routing)**:
|
|
50
|
+
Use a clean routing engine (like AltoRouter or a lightweight custom router) in `public/index.php`. Map all requests through a single file using `.htaccess` or server redirects:
|
|
51
|
+
```php
|
|
52
|
+
// public/index.php
|
|
53
|
+
require_once __DIR__ . '/../vendor/autoload.php';
|
|
54
|
+
|
|
55
|
+
$router = new App\Core\Router();
|
|
56
|
+
$router->add('GET', '/', 'HomeController@index');
|
|
57
|
+
$router->add('GET', '/users', 'UserController@index');
|
|
58
|
+
$router->dispatch($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
|
|
59
|
+
```
|
|
60
|
+
- **Models**:
|
|
61
|
+
Isolate all database access inside Model classes. Implement prepared statements using PDO:
|
|
62
|
+
```php
|
|
63
|
+
namespace App\Models;
|
|
64
|
+
use App\Core\Database;
|
|
65
|
+
use PDO;
|
|
66
|
+
|
|
67
|
+
class User {
|
|
68
|
+
private PDO $db;
|
|
69
|
+
public function __construct() {
|
|
70
|
+
$this->db = Database::getInstance()->getConnection();
|
|
71
|
+
}
|
|
72
|
+
public function getAll(): array {
|
|
73
|
+
$stmt = $this->db->prepare("SELECT id, name, email FROM users ORDER BY name ASC");
|
|
74
|
+
$stmt->execute();
|
|
75
|
+
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
- **Controllers**:
|
|
80
|
+
Extract requests and input parameters, invoke models, and return/render views:
|
|
81
|
+
```php
|
|
82
|
+
namespace App\Controllers;
|
|
83
|
+
use App\Models\User;
|
|
84
|
+
|
|
85
|
+
class UserController {
|
|
86
|
+
public function index(): void {
|
|
87
|
+
$model = new User();
|
|
88
|
+
$users = $model->getAll();
|
|
89
|
+
render_view('users/index', ['users' => $users]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
- **Views**:
|
|
94
|
+
Never echo HTML directly in controllers. Implement clean PHP template rendering or integrate a lightweight template engine like Twig. Ensure all HTML output is properly escaped.
|
|
95
|
+
|
|
96
|
+
#### 4. Security Enhancements
|
|
97
|
+
Integrate the following standard security gates during refactoring:
|
|
98
|
+
- **SQL Injection Prevention**: Enforce prepared statements with parameters for every SQL query.
|
|
99
|
+
- **XSS Prevention**: Build or use a global escape helper (e.g., `htmlspecialchars($str, ENT_QUOTES, 'UTF-8')`) for all dynamic view output.
|
|
100
|
+
- **CSRF Protection**: Generate and validate CSRF tokens for all state-changing requests (`POST`, `PUT`, `DELETE`).
|
|
101
|
+
- **Secrets Management**: Load configuration via `.env` files using `vlucas/phpdotenv`.
|
|
102
|
+
|
|
103
|
+
#### 5. Leveraging Modern PHP (v8.2+)
|
|
104
|
+
Refactor old PHP logic to use modern constructs:
|
|
105
|
+
- **Constructor Property Promotion** and **Typed Properties**.
|
|
106
|
+
- **Readonly Classes** for immutable service/data classes.
|
|
107
|
+
- **Strict Types Declaration**: Add `declare(strict_types=1);` to all class files.
|
|
108
|
+
|
|
109
|
+
#### 6. Multi-Page Application (MPA) Approach in a Single Repository
|
|
110
|
+
When organizing a project as a Multi-Page Application within a single repository, adhere to the following guidelines:
|
|
111
|
+
- **Centralized Routing**: Use the Front Controller (`public/index.php`) to handle all page requests. Route each request to its respective controller and view, ensuring each page load is fully processed on the server side.
|
|
112
|
+
- **Shared Layouts & Partials**: Avoid duplicating HTML (headers, footers, navigation). Create a `src/Views/layouts/` directory for base templates and a `src/Views/partials/` directory for reusable UI components. Controllers should inject page-specific content into the base layout.
|
|
113
|
+
- **Asset Management**: Store all static assets (CSS, JS, images) in the `public/` directory. Use cache-busting techniques (e.g., appending file modification time `?v=123`) when linking assets in the views.
|
|
114
|
+
- **State Management**: Use server-side sessions securely for user authentication, flash messages, and tracking state across full page reloads.
|
|
115
|
+
|
|
116
|
+
### Trigger Conditions
|
|
117
|
+
Active whenever the user requests to:
|
|
118
|
+
- Modernize a legacy PHP project or spaghetti PHP script.
|
|
119
|
+
- Design an MVC architecture or introduce a clean routing pattern in plain PHP.
|
|
120
|
+
- Implement object-oriented programming (OOP), Composer namespaces (PSR-4), or clean up database access via PDO in a PHP application.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
<a name="bahasa-indonesia"></a>
|
|
125
|
+
## Bahasa Indonesia
|
|
126
|
+
|
|
127
|
+
### Deskripsi
|
|
128
|
+
Skill ini memberikan protokol terstruktur, pola penulisan kode, dan panduan arsitektur bagi agen untuk melakukan audit, refaktorisasi, dan modernisasi terhadap codebase PHP lama yang usang (Plain Spaghetti PHP) menjadi struktur Model-View-Controller (MVC) yang bersih, modern, aman, dan skalabel yang mematuhi standar PSR serta kemampuan PHP modern (v8.2+).
|
|
129
|
+
|
|
130
|
+
### Instruksi
|
|
131
|
+
|
|
132
|
+
#### 1. Protokol Audit Kode PHP Lama
|
|
133
|
+
Sebelum membuat struktur baru, jalankan langkah audit terperinci pada file-file proyek lama untuk memetakan:
|
|
134
|
+
- **Titik Entri & Routing**: Identifikasi file-file `.php` mentah yang bertindak langsung sebagai endpoint (misal `about.php`, `contact.php`, `process.php`).
|
|
135
|
+
- **Akses Data & SQL**: Cari query SQL inline, penggabungan query menggunakan string concatenation (berisiko SQL Injection), dan penggunaan langsung `mysqli` atau `mysql_*`.
|
|
136
|
+
- **Session & State Global**: Identifikasi mutasi langsung session (`$_SESSION`), cookie mentah, dan variabel global yang tidak divalidasi (`$_GET`, `$_POST`, `$_REQUEST`).
|
|
137
|
+
- **Pencampuran Logika (Spaghetti)**: Temukan file di mana koneksi database, logika bisnis, validasi session, dan render HTML berada dalam satu berkas tunggal.
|
|
138
|
+
- **Secret Hardcoded**: Identifikasi kredensial database, API key, dan konfigurasi lainnya yang didefinisikan di dalam file.
|
|
139
|
+
|
|
140
|
+
#### 2. Strategi Modernisasi & Konfigurasi Composer
|
|
141
|
+
Terapkan struktur direktori proyek standar dan inisialisasi manajemen dependensi:
|
|
142
|
+
- **PSR-4 Autoloading**: Buat file `composer.json` dan definisikan pemetaan namespace:
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"autoload": {
|
|
146
|
+
"psr-4": {
|
|
147
|
+
"App\\": "src/"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
- **Struktur Direktori Standar**:
|
|
153
|
+
- `public/`: Titik entri tunggal yang berisi `index.php` (Front Controller), aset (CSS, JS), serta file upload.
|
|
154
|
+
- `src/`: Namespace root untuk struktur MVC (`src/Models/`, `src/Controllers/`, `src/Views/`, `src/Core/`).
|
|
155
|
+
- `config/`: Konfigurasi database, konfigurasi router, dan konfigurasi aplikasi.
|
|
156
|
+
- `.env` & `.env.example`: Menyimpan konfigurasi environment.
|
|
157
|
+
|
|
158
|
+
#### 3. Menerapkan Arsitektur MVC
|
|
159
|
+
Refaktorkan kode spageti ke dalam lapisan MVC yang terpisah:
|
|
160
|
+
- **Front Controller (Routing Terpusat)**:
|
|
161
|
+
Gunakan library routing yang bersih (seperti AltoRouter atau router kustom ringan) di `public/index.php`. Arahkan semua request melalui satu file menggunakan `.htaccess` atau pengalihan server:
|
|
162
|
+
```php
|
|
163
|
+
// public/index.php
|
|
164
|
+
require_once __DIR__ . '/../vendor/autoload.php';
|
|
165
|
+
|
|
166
|
+
$router = new App\Core\Router();
|
|
167
|
+
$router->add('GET', '/', 'HomeController@index');
|
|
168
|
+
$router->add('GET', '/users', 'UserController@index');
|
|
169
|
+
$router->dispatch($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
|
|
170
|
+
```
|
|
171
|
+
- **Models**:
|
|
172
|
+
Pisahkan semua akses database di dalam kelas Model. Gunakan prepared statements dengan PDO:
|
|
173
|
+
```php
|
|
174
|
+
namespace App\Models;
|
|
175
|
+
use App\Core\Database;
|
|
176
|
+
use PDO;
|
|
177
|
+
|
|
178
|
+
class User {
|
|
179
|
+
private PDO $db;
|
|
180
|
+
public function __construct() {
|
|
181
|
+
$this->db = Database::getInstance()->getConnection();
|
|
182
|
+
}
|
|
183
|
+
public function getAll(): array {
|
|
184
|
+
$stmt = $this->db->prepare("SELECT id, name, email FROM users ORDER BY name ASC");
|
|
185
|
+
$stmt->execute();
|
|
186
|
+
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
- **Controllers**:
|
|
191
|
+
Ekstrak request dan parameter input, panggil model, lalu return/render view:
|
|
192
|
+
```php
|
|
193
|
+
namespace App\Controllers;
|
|
194
|
+
use App\Models\User;
|
|
195
|
+
|
|
196
|
+
class UserController {
|
|
197
|
+
public function index(): void {
|
|
198
|
+
$model = new User();
|
|
199
|
+
$users = $model->getAll();
|
|
200
|
+
render_view('users/index', ['users' => $users]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
- **Views**:
|
|
205
|
+
Jangan pernah me-render atau menggunakan `echo` HTML langsung di dalam controller. Terapkan render template PHP yang bersih atau gunakan template engine ringan seperti Twig. Pastikan semua output HTML divalidasi dan lolos proses escaping.
|
|
206
|
+
|
|
207
|
+
#### 4. Peningkatan Keamanan
|
|
208
|
+
Integrasikan filter keamanan standar berikut selama refaktorisasi:
|
|
209
|
+
- **Pencegahan SQL Injection**: Wajibkan prepared statements dengan parameter terikat untuk setiap query SQL.
|
|
210
|
+
- **Pencegahan XSS**: Buat atau gunakan fungsi helper escape global (misal `htmlspecialchars($str, ENT_QUOTES, 'UTF-8')`) pada setiap output dinamis pada view.
|
|
211
|
+
- **Proteksi CSRF**: Hasilkan dan validasi token CSRF untuk setiap request yang mengubah state data (`POST`, `PUT`, `DELETE`).
|
|
212
|
+
- **Manajemen Secrets**: Muat konfigurasi via file `.env` menggunakan library `vlucas/phpdotenv`.
|
|
213
|
+
|
|
214
|
+
#### 5. Memanfaatkan PHP Modern (v8.2+)
|
|
215
|
+
Refaktorkan logika PHP lama agar menggunakan fitur modern:
|
|
216
|
+
- **Constructor Property Promotion** dan **Typed Properties** untuk properti kelas.
|
|
217
|
+
- **Readonly Classes** untuk kelas layanan atau data yang bersifat immutable (tidak dapat diubah).
|
|
218
|
+
- **Deklarasi Strict Types**: Tambahkan `declare(strict_types=1);` di bagian paling atas setiap file kelas.
|
|
219
|
+
|
|
220
|
+
#### 6. Pendekatan Multi-Page Application (MPA) dalam Satu Repositori
|
|
221
|
+
Saat mengatur proyek sebagai Multi-Page Application di dalam satu repositori, ikuti panduan berikut:
|
|
222
|
+
- **Routing Terpusat (Centralized Routing)**: Gunakan Front Controller (`public/index.php`) untuk menangani semua permintaan halaman. Arahkan setiap permintaan ke controller dan view masing-masing, memastikan setiap pemuatan halaman diproses sepenuhnya di sisi server.
|
|
223
|
+
- **Layout & Parsial Bersama (Shared Layouts & Partials)**: Hindari duplikasi HTML (header, footer, navigasi). Buat direktori `src/Views/layouts/` untuk template dasar dan direktori `src/Views/partials/` untuk komponen UI yang dapat digunakan kembali. Controller harus menyuntikkan konten spesifik halaman ke dalam layout dasar.
|
|
224
|
+
- **Manajemen Aset**: Simpan semua aset statis (CSS, JS, gambar) di direktori `public/`. Gunakan teknik cache-busting (misalnya, menambahkan waktu modifikasi file `?v=123`) saat menautkan aset di dalam view.
|
|
225
|
+
- **Manajemen State**: Gunakan session sisi server secara aman untuk autentikasi pengguna, pesan flash, dan melacak state di seluruh proses reload halaman secara penuh.
|
|
226
|
+
|
|
227
|
+
### Kondisi Pemicu
|
|
228
|
+
Aktif setiap kali pengguna meminta untuk:
|
|
229
|
+
- Memodernisasi proyek PHP lama atau script PHP spageti.
|
|
230
|
+
- Merancang arsitektur MVC atau memperkenalkan pola routing yang bersih di plain PHP.
|
|
231
|
+
- Menerapkan pemrograman berorientasi objek (OOP), namespace Composer (PSR-4), atau membersihkan akses database via PDO pada aplikasi PHP.
|