tonka/astro
Composer 安装命令:
composer create-project tonka/astro
包简介
Tonka Framework InertiaJs ReactJs Starter Kit
README 文档
README
The official React Starter Kit for the Tonka Framework.
Tonka Astro provides a seamless integration between your PHP backend and your React frontend. It comes pre-configured with InertiaJS, DriftQL, and Tonka Router, offering a development experience similar to Laravel's Inertia stack, but optimized for the Tonka ecosystem.
🌟 Key Features
- ⚛️ React + Vite: A modern, blazing-fast frontend environment with Hot Module Replacement (HMR).
- 🚀 InertiaJS: Build single-page applications without building an API. Server-side routing meets client-side rendering.
- 🧠 DriftQL Integration: Access your Elegant ORM models directly in your JSX with the powerful
<Elegant>component. - 🛣️ Tonka Router: Use your backend named routes in your React components effortlessly.
- 🛠️ Zero Config: Out-of-the-box configuration for TypeScript, Tailwind CSS (optional), and build tools.
📦 Installation
Install the package via Composer into your Tonka project:
composer create-project tonka/astro astro-app
Navigate to the astro-app directory, then run:
npm install
This will scaffold the frontend structure and install NPM dependencies.
🚀 Quick Start
Once installed, your resources/js directory is ready to go.
1. The Entry Point
Your React app is automatically wired to your backend via Inertia.
// resources/js/App.tsx import { usePage } from '@inertiajs/react'; import { route } from 'tonka-router'; // Auto-imported via Spark export default function App() { return ( <main> <h1>Welcome to Tonka Astro</h1> <a href={route('login')}>Login</a> </main> ); }
2. Fetching Data with DriftQL
Query your backend database without writing API calls. Use the <Elegant> component to bind data to DOM elements or use Render Props.
import { Elegant } from 'driftql-react'; export default function UserProfile() { return ( <div> <h1>My Profile</h1> {/* Auto-Binding: Fills src automatically from DB */} <Elegant as="img" resource="User" id={1} data-src="avatar_url" className="rounded-full" /> {/* Render Props: Full control */} <Elegant resource="Post" limit={5}> {(loading, error, posts) => ( loading ? <p>Loading...</p> : ( <ul> {posts.map(post => <li key={post.id}>{post.title}</li>)} </ul> ) )} </Elegant> </div> ); }
3. Navigation with Tonka Router
Navigate using your backend route names. Tonka Router handles URL generation automatically based on your Spark configuration.
import { route, current } from 'tonka-router'; export default function Navbar() { return ( <nav> <a href={route('home')}>Home</a> <a href={route('posts.index')}>Posts</a> {/* Highlight active link */} <a href={route('profile')} style={{ color: current().name === 'profile' ? 'blue' : 'black' }}> Profile </a> </nav> ); }
📁 Project Structure
The kit organizes your frontend code cleanly within the Tonka structure:
tonka-project/
├── app/ # Backend Logic (Controllers, Models)
├── resources/
│ ├── js/ # React Frontend (Scaffolded by Astro)
│ │ ├── App.tsx
│ │ ├── Pages/ # Inertia Pages
│ │ └── Components/ # Reusable React Components
│ └── views/ # Twig Templates (for initial load)
├── public/ # Public Assets
└── vite.config.js # Vite Configuration
⚙️ Configuration
Frontend Config (drift.config.js)
Located at the root of your project, generated by Astro.
export default { baseURL: '/api/bridge', bridge_public_key: 'your-key-here', // ... };
Backend Config (config/spark.php)
Configure which routes are visible to the frontend and apply access policies.
return [ 'only' => [ ['name' => 'home', 'policy' => null], ['name' => 'admin.*', 'policy' => \App\Contracts\DriftQL\AdminPolicy::class], ], ];
🛠️ Development
Start the Vite development server:
npm run dev
Build for production:
npm run build
📚 Learn More
- Tonka Framework Docs: Learn about the backend.
- DriftQL Docs: Master the frontend ORM.
- Tonka Router Docs: Understand dynamic routing.
- InertiaJS Docs: Learn the client-side protocol.
📝 License
MIT
tonka/astro 适用场景与选型建议
tonka/astro 是一款 基于 SCSS 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「reactjs」 「inertiajs」 「tonka」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tonka/astro 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tonka/astro 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tonka/astro 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Yii2 asset collection of useful JavaScript libraries
An elegant Laravel scaffolding for your next single-page application.
Client and Server-side React rendering for CraftCMS
Client and Server-side React rendering
Laravel PHP package to use Hypernova server-side rendering service.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-23