|
| 1 | +--- |
| 2 | +name: cloudbase-platform |
| 3 | +description: CloudBase platform knowledge and best practices. Use this skill for general CloudBase platform understanding, including storage, hosting, authentication, cloud functions, database permissions, and data models. |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +## When to use this skill |
| 8 | + |
| 9 | +Use this skill for **CloudBase platform knowledge** when you need to: |
| 10 | + |
| 11 | +- Understand CloudBase storage and hosting concepts |
| 12 | +- Configure authentication for different platforms (Web vs Mini Program) |
| 13 | +- Deploy and manage cloud functions |
| 14 | +- Understand database permissions and access control |
| 15 | +- Work with data models (MySQL and NoSQL) |
| 16 | +- Access CloudBase console management pages |
| 17 | + |
| 18 | +**This skill provides foundational knowledge** that applies to all CloudBase projects, regardless of whether they are Web, Mini Program, or backend services. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## How to use this skill (for a coding agent) |
| 23 | + |
| 24 | +1. **Understand platform differences** |
| 25 | + - Web and Mini Program have completely different authentication approaches |
| 26 | + - Must strictly distinguish between platforms |
| 27 | + - Never mix authentication methods across platforms |
| 28 | + |
| 29 | +2. **Follow best practices** |
| 30 | + - Use SDK built-in authentication features (Web) |
| 31 | + - Understand natural login-free feature (Mini Program) |
| 32 | + - Configure appropriate database permissions |
| 33 | + - Use cloud functions for cross-collection operations |
| 34 | + |
| 35 | +3. **Use correct SDKs and APIs** |
| 36 | + - Different platforms require different SDKs for data models |
| 37 | + - MySQL data models must use models SDK, not collection API |
| 38 | + - Use `envQuery` tool to get environment ID |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +# CloudBase Platform Knowledge |
| 43 | + |
| 44 | +## Storage and Hosting |
| 45 | + |
| 46 | +1. **Static Hosting vs Cloud Storage**: |
| 47 | + - CloudBase static hosting and cloud storage are two different buckets |
| 48 | + - Generally, publicly accessible files can be stored in static hosting, which provides a public web address |
| 49 | + - Static hosting supports custom domain configuration (requires console operation) |
| 50 | + - Cloud storage is suitable for files with privacy requirements, can get temporary access addresses via temporary file URLs |
| 51 | + |
| 52 | +2. **Static Hosting Domain**: |
| 53 | + - CloudBase static hosting domain can be obtained via `getWebsiteConfig` tool |
| 54 | + - Combine with static hosting file paths to construct final access addresses |
| 55 | + - **Important**: If access address is a directory, it must end with `/` |
| 56 | + |
| 57 | +## Environment and Authentication |
| 58 | + |
| 59 | +1. **SDK Initialization**: |
| 60 | + - CloudBase SDK initialization requires environment ID |
| 61 | + - Can query environment ID via `envQuery` tool |
| 62 | + - Then proceed with login, for example using anonymous login |
| 63 | + |
| 64 | +## Authentication Best Practices |
| 65 | + |
| 66 | +**Important: Authentication methods for different platforms are completely different, must strictly distinguish!** |
| 67 | + |
| 68 | +### Web Authentication |
| 69 | +- **Must use SDK built-in authentication**: CloudBase Web SDK provides complete authentication features |
| 70 | +- **Recommended method**: `auth.toDefaultLoginPage()` redirect to default login page |
| 71 | +- **Forbidden behavior**: Do not use cloud functions to implement login authentication logic |
| 72 | +- **User management**: After login, get user information via `auth.getCurrentUser()` |
| 73 | + |
| 74 | +### Mini Program Authentication |
| 75 | +- **Login-free feature**: Mini program CloudBase is naturally login-free, no login flow needed |
| 76 | +- **User identifier**: In cloud functions, get `wxContext.OPENID` via wx-server-sdk |
| 77 | +- **User management**: Manage user data in cloud functions based on openid |
| 78 | +- **Forbidden behavior**: Do not generate login pages or login flow code |
| 79 | + |
| 80 | +## Cloud Functions |
| 81 | + |
| 82 | +1. **Node.js Cloud Functions**: |
| 83 | + - Node.js cloud functions need to include `package.json`, declaring required dependencies |
| 84 | + - Can use `createFunction` to create functions |
| 85 | + - Use `updateFunctionCode` to deploy cloud functions |
| 86 | + - Prioritize cloud dependency installation, do not upload node_modules |
| 87 | + - `functionRootPath` refers to the parent directory of function directories, e.g., `cloudfunctions` directory |
| 88 | + |
| 89 | +## Database Permissions |
| 90 | + |
| 91 | +1. **Permission Model**: |
| 92 | + - CloudBase database access has permissions |
| 93 | + - Default basic permissions include: |
| 94 | + - Only creator can write, everyone can read |
| 95 | + - Only creator can read/write |
| 96 | + - Only admin can write, everyone can read |
| 97 | + - Only admin can read/write |
| 98 | + - If directly requesting database from web or mini program side, need to configure appropriate database permissions |
| 99 | + - In cloud functions, there is no permission control by default |
| 100 | + |
| 101 | +2. **Cross-Collection Operations**: |
| 102 | + - If user has no special requirements, operations involving cross-database collections must be implemented via cloud functions |
| 103 | + |
| 104 | +3. **Cloud Function Optimization**: |
| 105 | + - If involving cloud functions, while ensuring security, can minimize the number of cloud functions as much as possible |
| 106 | + - For example: implement one cloud function for client-side requests, implement one cloud function for data initialization |
| 107 | + |
| 108 | +## Data Models |
| 109 | + |
| 110 | +1. **Get Data Model Operation Object**: |
| 111 | + - **Mini Program**: Need `@cloudbase/wx-cloud-client-sdk`, initialize `const client = initHTTPOverCallFunction(wx.cloud)`, use `client.models` |
| 112 | + - **Cloud Function**: Need `@cloudbase/node-sdk@3.10+`, initialize `const app = cloudbase.init({env})`, use `app.models` |
| 113 | + - **Web**: Need `@cloudbase/js-sdk`, initialize `const app = cloudbase.init({env})`, after login use `app.models` |
| 114 | + |
| 115 | +2. **Data Model Query**: |
| 116 | + - Can call MCP `manageDataModel` tool to: |
| 117 | + - Query model list |
| 118 | + - Get model detailed information (including Schema fields) |
| 119 | + - Get specific models SDK usage documentation |
| 120 | + |
| 121 | +3. **MySQL Data Model Invocation Rules**: |
| 122 | + - MySQL data models cannot use collection method invocation, must use data model SDK |
| 123 | + - **Wrong**: `db.collection('model_name').get()` |
| 124 | + - **Correct**: `app.models.model_name.list({ filter: { where: {} } })` |
| 125 | + - Use `manageDataModel` tool's `docs` method to get specific SDK usage |
| 126 | + |
| 127 | +## Console Management |
| 128 | + |
| 129 | +After creating/deploying resources, provide corresponding console management page links: |
| 130 | + |
| 131 | +1. **Static Hosting**: https://console.cloud.tencent.com/tcb/hosting |
| 132 | + |
| 133 | +2. **Cloud Function**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/scf/detail?id=${functionName}&NameSpace=${envId} |
| 134 | + |
| 135 | +3. **Database Collection**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/collection/${collectionName} |
| 136 | + |
| 137 | +4. **Data Model**: https://tcb.cloud.tencent.com/dev?envId=${envId}#/db/doc/model/${modelName} |
| 138 | + |
| 139 | +**Usage**: After creating corresponding resources, replace variables with actual values, provide to user for management operations. |
| 140 | + |
0 commit comments