How weedymallick-nwu/learn_chinese works
Purpose and entry points
This is a Next.js 15 App Router PWA providing a terminal-style English-to-Simplified-Chinese translator. The browser entry route is src/app/page.tsx; shared document shell and global styling are defined in src/app/layout.tsx and src/app/globals.css. Translation requests enter through the server route src/app/api/translate/route.ts.
Application shell and visual system
The root layout establishes application-wide metadata, fonts, and shared client behavior. The main page renders the translator experience rather than a conventional multi-page web application. Styling is primarily global/Tailwind-driven, with the black terminal canvas and accent design applied through:
• src/app/layout.tsx
• src/app/globals.css
• src/app/page.tsx
Terminal interaction engine
Terminal is the central interactive client component. It owns the command-line UX: input at the ~/translate prompt, Enter submission, animated translation output, sentence history via arrow keys, screen clearing via Ctrl+L, and local commands such as /help, /clear, and /about.
• src/components/Terminal.tsx
• src/app/page.tsx
Its boundary is the translation API: commands and UI-only state remain client-side, while actual language conversion is delegated to the server endpoint.
Translation API and provider fallback
The API handler accepts browser POSTs and returns Chinese translation data to the terminal. Its provider sequence is Google’s public translation endpoint first, followed by MyMemory when Google is unavailable. This avoids application-managed API keys but makes translation quality/availability dependent on public external services.
• src/app/api/translate/route.ts
The server also computes pinyin offline using pinyin-pro, producing romanization independently of the remote translation provider. The response supports both full-sentence pinyin and word-level Chinese/pinyin/meaning display.
Primary request and rendering flow
1. User submits English text in src/components/Terminal.tsx.
2. The client POSTs text to /api/translate.
3. src/app/api/translate/route.ts calls Google, or MyMemory on failure, and enriches the result with offline pinyin.
4. The terminal receives the result and progressively types/render translations, sentence pinyin, and word breakdowns.
5. Submitted inputs remain in client-side history for keyboard recall.
PWA and offline boundary
The app is installable through a web manifest and service worker registration. Offline support is principally for the UI/app shell; live translations still require network access because the translation providers are remote.
• src/app/manifest.ts
• src/components/PwaRegister.tsx
• public/sw.js
Runtime and deployment model
The project runs as a Node.js/Next.js application with TypeScript and Tailwind CSS. The App Router serves both the rendered UI and same-origin API endpoint, making deployment suitable for platforms such as Vercel. The service worker and manifest enable mobile installation without a native runtime.
• package.json
• next.config.mjs
• src/app/api/translate/route.ts
Main entry points: route.ts Translate endpoint · layout.tsx Root layout · package.json Next.js Node runtime · Terminal.tsx Terminal
Components 14
Next.js web app
- Root layout · Sets metadata, fonts, and shared client behavior.
src/app/layout.tsx - Translator page · Hosts the terminal translator experience.
src/app/page.tsx - Terminal styling · Defines the terminal canvas and accent visual system.
src/app/globals.css - Terminal · Owns commands, input history, submission, and progressive output.
src/components/Terminal.tsx
Translation service
- Translate endpoint · Returns translated text, pinyin, and word-level data.
src/app/api/translate/route.ts - Google Translate
- MyMemory
- pinyin-pro · Computes pinyin independently of remote translation.
PWA offline shell
- Web manifest
src/app/manifest.ts - PWA registration · Registers the service worker.
src/components/PwaRegister.tsx - Service worker · Supports installable UI; live translation remains network-bound.
public/sw.js
Other components
- Browser user
- Next.js Node runtime · Serves the App Router UI and same-origin API.
package.json - Next configuration
next.config.mjs
Connections 15
- Browser user → Root layout: loads app
- Root layout → Translator page: renders
- Root layout → Terminal styling: applies
- Translator page → Terminal: hosts
- Terminal → Translate endpoint: POST text
- Translate endpoint → Google Translate: primary translation
- Translate endpoint → MyMemory: fallback on failure
- Translate endpoint → pinyin-pro: computes pinyin
- Translate endpoint → Terminal: translation result
- Root layout → PWA registration: shared client behavior
- PWA registration → Service worker: registers
- Service worker → Web manifest: supports installation
- Next.js Node runtime → Root layout: serves UI
- Next.js Node runtime → Translate endpoint: serves API
- Next configuration → Next.js Node runtime: configures