Skip to content

C-end Web (ArchForgeWeb)

ArchForgeWeb is the consumer-facing Next.js client for ArchForge. It talks only to server-web (:8081) and covers i18n, Sa-Token authentication, articles, dashboards, and Playwright E2E tests.

Tech Stack

CategoryTechnologyVersionPurpose
FrameworkNext.js16.2.12React framework with App Router
UIReact19.2.8Component library
LanguageTypeScript5.8.3Type-safe JavaScript
StylingTailwind CSS4.3.3Utility-first CSS
Componentsshadcn/ui + lucide-reactHeadless UI primitives and icons
i18nnext-intl4.13.4English / Chinese localization
AuthSa-Token (server-web)Token-based C-end authentication
Markdownreact-markdown + remark-gfm + rehype-highlightArticle content rendering
E2E TestsPlaywright1.61.1End-to-end testing
BuildTurborepo + pnpm workspacesMonorepo orchestration

Project Structure

apps/web/
├── src/
│   ├── app/                    # Next.js App Router pages
│   │   ├── page.tsx            # Dashboard / home
│   │   ├── articles/           # Article list and detail
│   │   ├── articles/me/        # My articles
│   │   ├── write/              # Create article
│   │   ├── login/              # Login page
│   │   ├── profile/            # User profile
│   │   ├── change-password/    # Change password
│   │   └── notifications/      # Notifications
│   ├── components/             # React components
│   │   ├── Header.tsx          # Top navigation (desktop)
│   │   ├── BottomNav.tsx       # Bottom navigation (mobile)
│   │   ├── ArticleCard.tsx     # Article list card
│   │   ├── LocaleSwitcher.tsx  # Language switcher
│   │   ├── Markdown.tsx        # Markdown renderer
│   │   └── providers/
│   │       └── AuthProvider.tsx # Auth context provider
│   ├── components/ui/          # shadcn/ui primitives
│   └── lib/                    # API client and utilities
│       ├── api.ts              # server-web API calls
│       └── utils.ts            # cn() and helpers
├── messages/
│   ├── en.json                 # English translations
│   └── zh.json                 # Chinese translations
├── i18n/
│   ├── request.ts              # next-intl request config
│   └── routing.ts              # next-intl routing config
├── middleware.ts               # next-intl middleware
├── e2e/                        # Playwright E2E tests
├── next.config.ts
└── package.json

Features

Authentication

  • Login with the same admin/dev credentials (admin / admin123 in dev).
  • Sa-Token session stored in localStorage (token, tokenName) for C-end APIs.
  • Auth provider guards protected routes (/articles/me, /write, /profile, /notifications, /change-password).
  • Unauthenticated visits to protected pages are redirected to /login.

Internationalization

  • Default locale: English (en).
  • Supported locales: en, zh.
  • Translations live in apps/web/messages/.
  • next-intl is configured with localePrefix: 'never', so URLs stay the same across languages.
  • The language button in the header sets a NEXT_LOCALE cookie and refreshes the page.

Dashboard

The home page (/) shows:

  • Time-based greeting (Good morning/afternoon/evening).
  • Operation metrics: user total, online now, today login, today operation.
  • Quick links: articles, write, profile, notifications.
  • Latest notices and operation logs.

Articles

  • Public article list (/articles) with category filter and pagination.
  • Article detail (/articles/{slug}) with Markdown rendering and cover image.
  • My articles (/articles/me) for logged-in users.
  • Write article (/write) with title, summary, category, cover image upload, and Markdown content.

Profile & Settings

  • /profile — display current user info.
  • /change-password — change password with old/new/confirm fields.
  • /notifications — list system notices.

Responsive Layout

  • Desktop: top header with navigation and language switcher.
  • Mobile: bottom tab navigation.
  • Tailwind CSS utility classes adapt spacing and grids.

API Base

The frontend talks to server-web (default http://localhost:8081).

text
# apps/web/.env.local
NEXT_PUBLIC_API_BASE_URL=http://localhost:8081

Admin (:8080) wraps success as {code, message, data}. C-end (:8081) errors use RFC 9457 ProblemDetail.

Main API Endpoints

EndpointMethodDescription
/web/loginPOSTLogin with username/password
/web/logoutPOSTLogout current session
/web/user/profileGETGet current user profile
/web/user/change-passwordPOSTChange password
/web/user/articlesGETMy articles (paginated)
/web/dashboard/metricsGETDashboard metrics
/web/noticesGETLatest notices
/web/operation-logsGETRecent operation logs
/web/categoriesGETArticle categories
/web/articlesGETPublic articles (paginated)
/web/articles/{slug}GETArticle detail
/web/articlesPOSTCreate article
/web/file/uploadPOSTUpload cover image

Available Scripts

bash
pnpm dev              # Start Next.js dev server (port 3000)
pnpm build            # Production build
pnpm start            # Start production server
pnpm typecheck        # TypeScript type checking
pnpm lint             # Next.js lint
pnpm test:e2e         # Run Playwright E2E tests
pnpm test:e2e:ui      # Run Playwright in UI mode
pnpm test:e2e:debug   # Run Playwright in debug mode

Testing

Playwright E2E

The e2e/ directory covers the core user paths:

  • home.spec.ts — dashboard greeting and navigation to articles.
  • locale.spec.ts — switching between English and Chinese.
  • articles.spec.ts — article list and detail pages.
  • auth.spec.ts — login, access protected page, logout.

Playwright config starts pnpm dev automatically via webServer and targets Chromium.

Quick Start

  1. Configure the API base:
bash
cp .env.example .env.local
# Edit apps/web/.env.local
  1. Install dependencies:
bash
pnpm install
  1. Start the backend (server-web on port 8081):
bash
# In the ArchForge repo
./gradlew :archforge-server-web:bootRun
  1. Start the dev server:
bash
pnpm dev

Open http://localhost:3000.

Notes

  • C-end and admin are two sa-token login types (StpWebUtil vs StpAdminUtil), not JWT vs sa-token.
  • Article detail pages are server-rendered with next-intl and react-markdown.
  • Auth cookies (token, tokenName, refreshToken) are mirrored in localStorage. Errors from server-web are RFC 9457 ProblemDetail.

Released under the MIT License.