How tencent/cloudbase-framework works
Project type and purpose
• This is a monorepo (Lerna-managed) Node.js/TypeScript toolset and CLI—CloudBase Framework—designed to provide “one-click” front-end and back-end deployment on Tencent Cloud’s Serverless platform.
• Key use case: automatically detect your application’s technologies (Vue, Nuxt, Next, Node, Dart, etc.), load the corresponding plugin(s), build the code, then deploy it as cloud functions, static hosting, managed containers, databases, etc., without writing cloud-specific infrastructure code yourself.
Main components
a. CLI layer
• @cloudbase/cli (root package.json & bin entry)
• Initialization commands (cloudbase init, cloudbase framework deploy)
b. Core framework (packages/framework-core)
• API entrypoints (src/index.ts)
• Configuration resolution and validation (src/config)
• Lifecycle orchestrator and hook manager (src/lifecycle, src/hooks)
• Plugin manager (src/plugin-manager)—loads & invokes plugins
• Builder, generator, deployer, SAM convertor modules (src/builder, src/generator, src/deployer, src/sam)
• Context and utilities (src/context, src/utils, src/logger, src/error)
c. Plugin packages (packages/framework-plugin-* + builder packages)
• Website plugin (static hosting)
• Node plugin (cloud functions / cloud hosting)
• Nuxt, Next, Deno, Dart, MP (mini-program), Function, Container, Database, Auth, etc.
• Each plugin implements build/deploy steps against cloud APIs
d. Builders (packages/cloudbase-*-builder)
• Low-level “asset launcher” and bundling logic for various targets (Next, Nuxt, static, Node, etc.)
e. Configuration schema & CLI helpers
• JSON schema for .cloudbaserc.json (packages/cloudbaserc-json-schema)
• Scripts folder: build-runner, doc-builder, CI helpers, license checks
f. Documentation & community resources
• README.md, CLI_GUIDE.md, community posts, doc folder
Relationships and data flow
1. User runs cloudbase CLI → CLI entry loads framework-core API
2. Core reads project root config (cloudbaserc.json or auto-detect), resolves framework.plugins
3. Plugin manager loads detected plugins (via NPM packages under packages/framework-plugin-*)
4. For each plugin:
• Execute “detect” phase (to validate the project structure)
• Execute “build” phase (invoke matching builder from cloudbase-*-builder)
• Package artifacts (functions/containers/static files)
• Execute “deploy” phase (call Tencent Cloud TCB REST APIs or SAM conversion + Cloud API)
5. Core orchestrates phases in sequence, aggregates results, logs progress
Architectural patterns & design principles
• Plugin architecture: core orchestrator + pluggable modules, each implements a uniform interface (detect, build, deploy)
• Command pattern: CLI commands map to core APIs
• Lifecycle hooks: stages (pre-build, post-build, pre-deploy, post-deploy) allow cross-cutting concerns
• Monorepo modularization: shared utilities & types in framework-core, isolated plugin packages
• Separation of concerns:
• Config resolution/validation → config
• Business logic (build/deploy) → builder & deployer
• Plugin management → plugin-manager
• Context/environment abstraction → context
Final recommendations
• In the Plugin Layer, represent at least one or two sample plugins (e.g., website, node, function) to illustrate extensibility