Bỏ qua để đến nội dung

Tạo dự án mới

Hướng dẫn này sẽ chỉ bạn cách sử dụng Galaxy CLI để tạo một dự án Next.js e-commerce hoàn chỉnh.

Trong ví dụ này, chúng ta sẽ tạo một ứng dụng e-commerce với:

  • Product catalog
  • Shopping cart
  • Checkout với Stripe
  • User authentication
  • Admin dashboard
  1. Mở terminal và cd vào thư mục làm việc

    Terminal window
    cd ~/projects
  2. Khởi động Galaxy CLI

    Terminal window
    cd /path/to/galaxy-cli
    bun run start --test --review
  3. Chờ Galaxy CLI khởi động

    Bạn sẽ thấy banner:

    ____ _ ____ _ ___
    / ___| __ _| | __ ___ ___ _ / ___| | |_ _|
    | | _ / _` | |/ _` \ \/ / | | || | | | | |
    | |_| | (_| | | (_| |> <| |_| || |___| |___ | |
    \____|\__,_|_|\__,_/_/\_\\__, | \____|_____|___|
    |___/
    Version: 2.0.0
    Agent=auto Git=OFF Test=ON Review=ON
    > _

Nhập yêu cầu chi tiết:

Terminal window
> Tạo app Next.js e-commerce với những tính năng sau:
- Product catalog với search, filter pagination
- Shopping cart với local storage
- Checkout integration với Stripe
- User authentication với JWT
- Admin dashboard để quản products
Tech stack mong muốn:
- Next.js 14 với App Router
- TypeScript
- Tailwind CSS
- Prisma + PostgreSQL
- NextAuth.js

Galaxy sẽ gọi BA Analyzer để phân tích:

🔄 Đang phân tích yêu cầu...
⚡ ba_it_analyze
↳ Analyzing project requirements...

Sau khoảng 10-15 giây, Galaxy sẽ hiển thị phân tích:

📊 Phân tích dự án: Next.js E-commerce Platform
💡 Mô tả:
Ứng dụng thương mại điện tử full-stack được xây dựng với Next.js 14,
tích hợp Stripe payments và admin dashboard.
✨ Tính năng chính:
1. Product Catalog (must-have)
- Hiển thị products với images, prices, descriptions
- Search functionality với debouncing
- Advanced filters (category, price range, ratings)
- Pagination với infinite scroll
2. Shopping Cart (must-have)
- Add/remove items
- Quantity management
- Persist cart data với localStorage
- Cart summary với total calculation
3. Stripe Checkout (must-have)
- Stripe payment integration
- Secure checkout flow
- Order confirmation
- Payment webhooks handling
4. User Authentication (must-have)
- Sign up / Sign in
- JWT token management
- Protected routes
- User profile management
5. Admin Dashboard (should-have)
- Product CRUD operations
- Order management
- Analytics dashboard
- User management
📦 Tech Stack:
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Prisma ORM
- Database: PostgreSQL
- Auth: NextAuth.js với JWT strategy
- Payments: Stripe
- Deployment: Vercel (recommended)
📊 Data Models:
- User: id, email, password, name, role, createdAt
- Product: id, name, description, price, image, category, stock
- Order: id, userId, total, status, items[], createdAt
- Cart: userId, items[], updatedAt
🔗 API Endpoints:
- GET /api/products - List products
- GET /api/products/[id] - Product details
- POST /api/cart - Add to cart
- POST /api/checkout - Create order
- POST /api/auth/signin - Sign in
- POST /api/auth/signup - Sign up
⏱️ Thời gian ước tính: Long (8-12 hours)
💡 Đề xuất:
1. Sử dụng SWR hoặc React Query cho data fetching
2. Implement image optimization với next/image
3. Add Redis caching cho product queries
4. Setup environment variables cho Stripe keys
❓ Câu hỏi:
1. Bạn có muốn thêm wishlist feature?
2. Cần multi-currency support?
3. Shipping calculation logic?
Bạn đồng ý với phương án này?
(Type 'yes' để tiếp tục hoặc điều chỉnh requirements)
Terminal window
> yes, làm đi

Hoặc nếu muốn điều chỉnh:

Terminal window
> Thêm wishlist feature và multi-currency với USD và VND

Galaxy sẽ cập nhật phân tích và hỏi lại xác nhận.

Sau khi xác nhận, Galaxy gọi Planning Agent:

📋 Đang tạo execution plan...
⚡ plan_task
↳ Creating feature-driven plan...

Galaxy hiển thị plan với todos:

📋 Implementation Plan (long):
Tổng quan: Build Next.js e-commerce với 5 core features.
Thời gian ước tính: 8-12 hours
☐ Step 1: Initialize Next.js project
Tool: command_run
Reasoning: Setup Next.js 14 with TypeScript and App Router
☐ Step 2: Install dependencies
Tool: install_dependencies
Reasoning: Install required packages (Prisma, Tailwind, NextAuth, Stripe)
☐ Step 3: Setup database and Prisma
Tool: code_generate
Reasoning: Configure PostgreSQL connection and define Prisma schema
☐ Step 4: Implement Product Catalog
Tool: code_generate
Feature: Product Catalog (must-have)
Reasoning: Core feature - Product listing với search & filters
☐ Step 5: Implement Shopping Cart
Tool: code_generate
Feature: Shopping Cart (must-have)
Reasoning: Cart management với localStorage persistence
☐ Step 6: Implement Stripe Checkout
Tool: code_generate
Feature: Stripe Checkout (must-have)
Reasoning: Payment integration với webhooks
☐ Step 7: Implement User Authentication
Tool: code_generate
Feature: User Authentication (must-have)
Reasoning: Auth system với NextAuth.js và JWT
☐ Step 8: Implement Admin Dashboard
Tool: code_generate
Feature: Admin Dashboard (should-have)
Reasoning: Admin panel để quản lý products và orders
☐ Step 9: Write unit tests
Tool: test_generate
Reasoning: Test coverage cho core features (enabled via --test)
☐ Step 10: Code review & refactoring
Tool: code_review
Reasoning: Final review và optimize code (enabled via --review)
Bắt đầu thực thi? (yes/no)
Terminal window
> yes

Galaxy bắt đầu thực thi từng bước:

⚙ Step 1: Initialize Next.js project - In progress...
⚡ EXECUTE (npx create-next-app@latest my-ecommerce...)
↳ ✓ Success. Output: 15 lines.
☒ Step 1: Initialize Next.js project - Completed
⚙ Step 2: Install dependencies - In progress...
⚡ EXECUTE (npm install prisma @prisma/client...)
↳ ✓ Success. Output: 42 lines.
☒ Step 2: Install dependencies - Installed
⚙ Step 3: Setup database and Prisma - In progress...
📝 APPLY PATCH (prisma/schema.prisma)
↳ Succeeded. File created. (+45 added)
1 + datasource db {
2 + provider = "postgresql"
3 + url = env("DATABASE_URL")
4 + }
5 +
6 + model User {
7 + id String @id @default(cuid())
8 + email String @unique
...
45 + }
📝 APPLY PATCH (.env.local)
↳ Succeeded. File created. (+3 added)
☒ Step 3: Setup database and Prisma - Completed
Created 2 files: schema.prisma, .env.local

Mỗi feature sẽ được implement bởi Code Generate Agent:

⚙ Step 4: Implement Product Catalog - In progress...
🤖 Code Generate Agent executing...
Feature: Product Catalog
Priority: must-have
📝 APPLY PATCH (app/products/page.tsx)
↳ Succeeded. File created. (+127 added)
📝 APPLY PATCH (components/ProductCard.tsx)
↳ Succeeded. File created. (+45 added)
📝 APPLY PATCH (lib/api/products.ts)
↳ Succeeded. File created. (+38 added)
📝 APPLY PATCH (app/api/products/route.ts)
↳ Succeeded. File created. (+62 added)
☒ Step 4: Implement Product Catalog - Completed
Created 4 files: page.tsx, ProductCard.tsx, products.ts, route.ts
  • app/products/page.tsx - Product listing page
  • components/ProductCard.tsx - Product card component
  • components/ProductFilters.tsx - Filter sidebar
  • lib/api/products.ts - API client
  • app/api/products/route.ts - API endpoint
⚙ Step 9: Write unit tests - In progress...
📝 APPLY PATCH (__tests__/ProductCard.test.tsx)
📝 APPLY PATCH (__tests__/Cart.test.tsx)
📝 APPLY PATCH (__tests__/api/products.test.ts)
⚡ EXECUTE (npm test)
↳ ✓ Success. All tests passed.
☒ Step 9: Write unit tests - Completed
⚙ Step 10: Code review & refactoring - In progress...
🔍 Reviewing code...
✅ Code quality: Good
💡 Suggestions:
- Extract repeated validation logic
- Add error boundaries for Suspense
- Optimize images với next/image
☒ Step 10: Code review & refactoring - Completed
✅ All steps completed!
📊 Summary:
- Created 42 files
- 12 React components
- 8 API endpoints
- 15 unit tests
- Database schema with 4 models
🚀 Next steps:
1. Setup PostgreSQL database
2. Run: npm run db:push
3. Add Stripe keys to .env.local
4. Run: npm run dev
5. Visit: http://localhost:3000
📄 Progress saved: /path/to/project/.galaxy/progress.json
  1. Xem cấu trúc project

    Terminal window
    > /pwd
    Working directory: ~/projects/my-ecommerce
    Terminal window
    cd ~/projects/my-ecommerce
    tree -L 2
  2. Setup database

    Terminal window
    # Tạo PostgreSQL database
    createdb my_ecommerce
    # Update .env.local với connection string
    DATABASE_URL="postgresql://user:pass@localhost:5432/my_ecommerce"
    # Push schema
    npx prisma db push
  3. Thêm Stripe keys

    Terminal window
    # Trong .env.local
    STRIPE_SECRET_KEY=sk_test_...
    STRIPE_PUBLISHABLE_KEY=pk_test_...
    STRIPE_WEBHOOK_SECRET=whsec_...
  4. Chạy development server

    Terminal window
    npm run dev
  5. Test ứng dụng

Terminal window
# Kiểm tra PostgreSQL đang chạy
brew services start postgresql
# Test connection
psql -U postgres -h localhost
Terminal window
# Sử dụng Stripe CLI để test webhooks locally
stripe listen --forward-to localhost:3000/api/webhooks/stripe
Terminal window
# Clear cache và rebuild
rm -rf .next
npm run build