NewLife.Cube Documentation

repository·master·Indexed 20 days ago

https://github.com/newlifex/newlife.cube

A rapid web development platform for data-driven scenarios that transforms database entities into administrative interfaces. It provides standard APIs for various frontend frameworks and includes multiple frontend implementations such as Angular 19, Vue 3 (ArcoVue, NaiveUI, TDesign), React 18 (MUI, Shadcn, Ant Design), and SvelteKit. The platform supports automated E2E testing via Playwright and .NET SDK 10.0.

Tokens
305.8K
Snippets
745
Records
1.1K
Agent score
61%

What's inside NewLife.Cube

  1. Overview of built-in entities in Membership and Cube libraries

    master

    NewLife.Cube organizes its core entities into two primary libraries:

    Membership Library (User & Permissions)

    Handles identity, access control, and organizational structure:

    • User: User accounts
    • Role: User roles
    • Menu: Navigation and permission items
    • Department: Organizational departments
    • Area: Geographic areas
    • Log: System logs (supports sharding)
    • UserToken: Authentication tokens
    • UserConnect: Third-party login bindings
    • UserOnline: Online status tracking
    • UserStat: User statistics

    Cube Library (System Management)

    Handles application infrastructure and system-wide settings:

    • App: Application systems
    • AppModule: Application plugins
    • Attachment: File attachments
    • CronJob: Scheduled tasks
    • OAuthConfig: OAuth configurations
    • OAuthLog: OAuth activity logs
    • AccessRule: Access control rules
    • Tenant: Multi-tenancy management
    • TenantUser: Tenant-specific user mappings
  2. What is NewLife.Cube?

    master

    NewLife.Cube is a Web rapid development platform built on ASP.NET Core. It provides a complete infrastructure for building administrative back-office systems, focusing on the principle of "Convention over Configuration."

    Core Capabilities:

    • User & Permission Management: Full RBAC (Role-Based Access Control) system including users, roles, menus, and permissions.
    • Generic Data Management: Automatic CRUD (Create, Read, Update, Delete) operations for entities, including auto-generated lists, forms, and detail pages.
    • System Management: Built-in support for logs, configurations, dictionaries, and scheduled tasks.
    • Extensibility: Support for theme/skin switching, OAuth login, and data-level permissions.
    • High Performance: Designed to handle massive datasets (up to 10 billion rows) using XCode ORM features like automatic sharding, read/write splitting, and second-level caching.
  3. Overview of @newlifex/cube-vue

    master

    The @newlifex/cube-vue package is the default Vue 3 frontend template and micro-frontend framework for NewLife.Cube. It is a metadata-driven engine: the backend EntityController provides field metadata (via GetPage and GetFields), and the frontend automatically renders dynamic lists, search bars, and forms without requiring manual page creation for every entity.

    Directory Structure

    • web/core/: The Framework Engine. This contains the core logic for dynamic lists, forms, layouts, and generic components. Modify default template logic only here.
    • web/apps/: Consumer applications (e.g., cube-admin, cube-cube) that consume the core engine at runtime.
    • web/src/: Deprecated. This is an old demonstration shell and does not import @newlifex/cube-vue/core. Do not use this for dynamic templates.
    • web/docs/: Entry point for frontend documentation.
  4. Overview of Cube-Cube functional modules

    master

    Cube-Cube contains core management pages for the Cube system. The available modules and their primary routes are:

    ModuleRouteDescription
    Application Management/Cube/AppCRUD for applications, startup configurations, and version management.
    Application Logs/Cube/AppLogViewing, filtering, and searching operation logs.
    Area Management/Cube/AreaManaging provincial, city, and district hierarchical data.
    Attachment Management/Cube/AttachmentFile uploads, classification, and download statistics.
    Scheduled Tasks/Cube/CronJobCron job configuration, status management, and manual execution.
    Order Management/Cube/OrderManagerOrder tracking, status management, and querying.
    Principal Agent/Cube/PrincipalAgentManaging agent entity information, types, and contact details.
  5. Select a Frontend Skin (SPA or MVC)

    master

    NewLife.Cube supports multiple frontend architectures and UI frameworks:

    Single Page Application (SPA) Skins (WebAPI JSON)

    • Vue 3: Element Plus, Naive UI, Arco Design, Vuetify, TDesign.
    • React 19: Ant Design (via MUI/Shadcn patterns), MUI 6, Shadcn (Radix UI + Tailwind CSS 4).
    • Other: Angular 19 (NG-ZORRO), SvelteKit 2 (Svelte 5 + Tailwind CSS 4), Blazor (experimental).

    Model-View-Controller (MVC) Skins (Razor)

    • Themes: AdminLTE, Metronic, Tabler (Bootstrap 5), LayuiAdmin, ElementUI.
    • Customization: You can override built-in views by placing a file with the same name and path in your sub-project.
  6. Core capabilities of @newlifex/cube-vue

    master

    The @newlifex/cube-vue framework provides several built-in capabilities for building enterprise applications:

    • Layout System: Uses MainLayout (sidebar + content area). You can customize it via dependency injection using LayoutKey.
    • State Management: Provides UserStore for user state and MenuStore for menu state. Access them via useUserStore() and useMenuStore().
    • Routing System: Supports dynamic routing and micro-frontend architectures, with routes dynamically generated from backend menu data.
    • API Requests: An Axios wrapper that includes automatic Token handling, 401 error processing, and error notifications. Import it via import request from '@newlifex/cube-vue/core/utils/request'.
    • Internationalization (i18n): Powered by Vue I18n with support for dynamic switching. Use intl.get('key').d('default_value') to retrieve translations.
    • Page Overriding: Uses a Section mechanism. You can override framework components by creating Vue files with uppercase names in the views/ directory.
    • BUILD_ Configuration Injection: Allows injecting variables into index.html during production builds. Use the ${BUILD_XXX} syntax within config.production.ts.
  7. Understand the NewLife.Cube system positioning and core capabilities

    master

    NewLife.Cube is a rapid development infrastructure layer designed for system administration backends. It aims to minimize repetitive development of common backend features by providing out-of-the-box capabilities for authentication, permissions, menus, CRUD operations, imports/exports, logging, and configuration.

    Key Capabilities:

    • Multi-Frontend Support: A single set of backend APIs can serve various frontend frameworks including Vue, React, Angular, Svelte, Blazor, and MVC Razor.
    • Extensible Architecture: Deep customization is achieved through EntityController inheritance, field metadata, and the IModule plugin mechanism.
    • High Data Scalability: Built on the XCode ORM, it supports sharding (table splitting), read/write splitting, and second-level caching to handle tables with up to 10 billion records.
  8. Verify NewLife.Cube API and Frontend Integration Capabilities

    master

    The NewLife.Cube (API-based/Third Generation) architecture provides a decoupled frontend-backend system. Developers can verify the following core capabilities for building applications:

    Core API Capabilities

    • Dynamic Field Rendering: Use the GetFields API to retrieve metadata for the current page, allowing the frontend to render fields dynamically.
    • Chart Data: Implement the OnGetChartData virtual method in the backend to provide data for ECharts rendering in the frontend.
    • Authentication Configuration: Use the /Auth/LoginConfig endpoint to retrieve dynamic login configurations, which can be integrated into Pinia stores (Vue) or similar state management.
    • Module Loading: Implement the IModule interface to enable automatic scanning and loading of plugins.

    Frontend Framework Support

    • Vue Support: Provided via NewLife.Cube.Vue (based on QuickVue). Supports dynamic field type mapping, search, sorting, permissions, hyperlinks, and form states. Includes import/export (5 formats) and batch operations.
    • React Support: Provided via NewLife.Cube.React (based on CubeAntd). Features the DynamicPage component which integrates ProTable, CRUD, search, sorting, and pagination with automatic route adaptation.

    Deployment and Routing

    • Embedded Static Files: Uses CubeEmbeddedFileProvider to read static resources directly from assemblies.
    • SPA Routing: Both VueService and ReactService implement SPA fallback routing to ensure that page refreshes do not result in 404 errors (non-file requests are redirected to index.html).
  9. Summary of Custom Form Page capabilities

    master

    The NewLife.Cube custom form system provides several layers of customization:

    1. Form Structure: Standardized layout consisting of a Header, Body, and Footer.
    2. Field Configuration: Use AddFormFields and EditFormFields in the controller to define which fields appear during creation vs. editing.
    3. Validation: Supports both Client-side validation and Server-side validation via the Valid method.
    4. Custom Controls: Built-in support for dropdowns, radio buttons, checkboxes, file uploads, and rich text editors.
    5. Custom Views: The ability to completely override the form page using custom .cshtml files for total control over the UI.
  10. Understand the NewLife.Cube.ArcoVue directory structure

    master

    The frontend project follows a standard Vue 3 structure organized as follows:

    • src/api/: API calling layer (reuses @cube/api-core)
    • src/components/: Reusable UI components
    • src/layouts/: Layout components for different page structures
    • src/router/: Routing configurations
    • src/stores/: Pinia state management stores
    • src/views/: Page-level view components
    • src/App.vue: Root component
    • src/main.ts: Application entry point
    • index.html: HTML template
    • vite.config.ts: Vite configuration
    • tsconfig.json: TypeScript configuration
    • package.json: Project dependencies and scripts
    web/
    ├── src/
    │   ├── api/          # API 调用层(复用 @cube/api-core)
    │   ├── components/   # 组件
    │   ├── layouts/      # 布局组件
    │   ├── router/       # 路由配置
    │   ├── stores/       # Pinia 状态管理
    │   ├── views/        # 页面视图
    │   ├── App.vue
    │   └── main.ts
    ├── index.html
    ├── vite.config.ts
    ├── tsconfig.json
    └── package.json
  11. Overview of NewLife.Cube core service modules

    master

    NewLife.Cube is organized into several functional layers and modules that provide the foundation for rapid application development:

    Infrastructure Layer

    • BASE (Base Services): Provides unified response protocols, declarative permission annotations, modular plugins, and data protection.
    • AUTH (User Authentication): Supports multiple authentication methods including passwords, MFA (Multi-Factor Authentication), verification codes, and external authentication with security risk control.
    • PERM (Permission Management): A Role-Based Access Control (RBAC) system managing users, roles, menus, departments, and data permissions. It supports multi-tenancy and delegated proxying.
    • OAUTH (Unified Authentication): Manages OAuth third-party logins and SSO (Single Sign-On), including OAuth configuration, logs, and user binding.

    Core Engine

    • DATA (Data Management): The central engine that automatically generates standard CRUD management interfaces once entities are defined. It uses field metadata to drive frontend rendering.

    Supporting & Value-Added Services

    • SYS (System Management): Includes configuration, auditing, jobs, value sets, file management, regions, and attachments.
    • NOTI (Message Notification): Unified management and sending of email, SMS, and in-app notifications.
    • AI (AI Services): An abstraction layer for Large Language Models (LLMs) providing log summarization, security inspections, and AI-driven data insights.

    Presentation Layer

    • MVC (MVC Views): Server-side rendered Razor views with support for multiple themes like Tabler, LayuiAdmin, and Metronic.
    • SPA (SPA Frontends): WebAPI-driven frontend skins for frameworks like Vue, React, NaiveUI, and Angular.
  12. Overview of NewLife.Cube authentication mechanisms

    master

    NewLife.Cube supports several authentication methods depending on the use case:

    • Password Login: Traditional method for Web page logins.
    • External Authentication: Integrates with enterprise systems; calls external interfaces when local authentication fails and automatically synchronizes users.
    • SSO (Single Sign-On): For multi-system integration and unified identity.
    • JWT Token: Stateless authentication suitable for decoupled frontend/backend (API) architectures.
    • OAuth Login: Supports third-party providers like WeChat, QQ, and DingTalk.