-
Notifications
You must be signed in to change notification settings - Fork 40
feat: initial release #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XiaokiYolo
wants to merge
1
commit into
code-with-antonio:master
Choose a base branch
from
XiaokiYolo:main
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| node_modules | ||
| .next | ||
| build | ||
| .env | ||
| Dockerfile | ||
| README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FROM node:18-alpine | ||
| WORKDIR /app | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
| COPY package*.json ./ | ||
| RUN npm ci | ||
| COPY . . | ||
| RUN npm run build | ||
| EXPOSE 3000 | ||
| CMD ["npm", "start"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| # Lingo - 离线移动端 App 架构文档 | ||
|
|
||
| ## 📱 项目概述 | ||
|
|
||
| 本项目已成功从纯 Web 应用改造为**支持离线运行的移动端应用**,使用 Capacitor + SQLite 技术栈。 | ||
|
|
||
| ### 核心架构 | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────┐ | ||
| │ Next.js 14 App │ | ||
| │ (React Server + Client Components) │ | ||
| └──────────────┬──────────────────────┘ | ||
| │ | ||
| │ Capacitor Bridge | ||
| ▼ | ||
| ┌─────────────────────────────────────┐ | ||
| │ Capacitor Native Layer │ | ||
| │ ┌─────────────┐ ┌───────────────┐ │ | ||
| │ │ SQLite DB │ │ Native APIs │ │ | ||
| │ │ (Local) │ │ (Network, │ │ | ||
| │ │ │ │ Storage, │ │ | ||
| │ │ │ │ etc.) │ │ | ||
| │ └─────────────┘ └───────────────┘ │ | ||
| └─────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## 🗂️ 新增文件结构 | ||
|
|
||
| ``` | ||
| nextjs-duolingo-clone/ | ||
| ├── capacitor.config.ts # Capacitor 配置文件 | ||
| ├── db/ | ||
| │ ├── offline-db.ts # SQLite 数据库核心服务 | ||
| │ └── offline-queries.ts # 离线数据查询操作 | ||
| ├── hooks/ | ||
| │ └── use-sync-engine.ts # 数据同步引擎 Hook | ||
| ├── lib/ | ||
| │ └── mobile-app.ts # 移动端工具函数 | ||
| ├── providers/ | ||
| │ ├── database-provider.tsx # 数据库初始化 Provider | ||
| │ └── offline-provider.tsx # 离线状态管理 Provider | ||
| ├── scripts/ | ||
| │ └── seed-offline.ts # 离线数据库种子脚本 | ||
| └── components/ | ||
| └── network-status.tsx # 网络状态提示组件 | ||
| ``` | ||
|
|
||
| ## 🚀 快速开始 | ||
|
|
||
| ### 1. 环境要求 | ||
|
|
||
| - Node.js >= 18 | ||
| - npm >= 9 | ||
| - **Android 开发**: Android Studio + SDK | ||
| - **iOS 开发**: Xcode (macOS only) | ||
|
|
||
| ### 2. 安装依赖 | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| ### 3. 添加移动平台 | ||
|
|
||
| ```bash | ||
| # 添加 Android 平台 | ||
| npx cap add android | ||
|
|
||
| # 添加 iOS 平台 (macOS) | ||
| npx cap add ios | ||
| ``` | ||
|
|
||
| ### 4. 开发与构建 | ||
|
|
||
| ```bash | ||
| # Web 开发模式 (保留原有 Server 功能) | ||
| npm run dev | ||
|
|
||
| # 构建并同步到移动端 | ||
| npm run cap:sync | ||
|
|
||
| # 打开 Android Studio | ||
| npm run cap:android | ||
|
|
||
| # 打开 Xcode | ||
| npm run cap:ios | ||
|
|
||
| # 直接运行到设备 | ||
| npm run cap:run:android | ||
| npm run cap:run:ios | ||
| ``` | ||
|
|
||
| ## 📦 核心依赖 | ||
|
|
||
| | 包名 | 用途 | | ||
| |------|------| | ||
| | `@capacitor/core` | Capacitor 核心 | | ||
| | `@capacitor-community/sqlite` | SQLite 数据库 | | ||
| | `@capacitor/network` | 网络状态检测 | | ||
| | `@capacitor/splash-screen` | 启动画面 | | ||
| | `@capacitor/preferences` | 本地偏好设置 | | ||
| | `@capacitor/app` | 应用生命周期 | | ||
| | `@capacitor/haptics` | 触觉反馈 | | ||
| | `@capacitor/keyboard` | 键盘管理 | | ||
|
|
||
| ## 💾 离线数据架构 | ||
|
|
||
| ### SQLite 数据表 | ||
|
|
||
| | 表名 | 说明 | | ||
| |------|------| | ||
| | `courses` | 语言课程 | | ||
| | `units` | 学习单元 | | ||
| | `lessons` | 课程章节 | | ||
| | `challenges` | 练习题 | | ||
| | `challenge_options` | 题目选项 | | ||
| | `challenge_progress` | 答题进度 | | ||
| | `user_progress` | 用户进度 | | ||
| | `user_subscription` | 订阅信息 | | ||
| | `sync_queue` | 同步队列 (离线时暂存,联网后同步) | | ||
|
|
||
| ### 数据同步机制 | ||
|
|
||
| 1. **离线状态**: 所有数据变更写入本地 SQLite 和 `sync_queue` | ||
| 2. **联网检测**: 自动检测网络状态变化 | ||
| 3. **增量同步**: 将 `sync_queue` 中的待同步数据发送到服务器 | ||
| 4. **冲突处理**: 基于时间戳和服务端优先级解决冲突 | ||
|
|
||
| ## 🔧 使用示例 | ||
|
|
||
| ### 1. 在组件中使用离线数据库 | ||
|
|
||
| ```tsx | ||
| import { dbService } from '@/db/offline-db'; | ||
| import { offlineQueries } from '@/db/offline-queries'; | ||
|
|
||
| export async function getMyProgress(userId: string) { | ||
| return await offlineQueries.getUserProgress(userId); | ||
| } | ||
|
|
||
| export async function saveChallengeProgress(userId: string, challengeId: number) { | ||
| await offlineQueries.upsertChallengeProgress(userId, challengeId, true); | ||
| } | ||
| ``` | ||
|
|
||
| ### 2. 使用同步引擎 Hook | ||
|
|
||
| ```tsx | ||
| import { useSyncEngine } from '@/hooks/use-sync-engine'; | ||
|
|
||
| function MyComponent() { | ||
| const { isOnline, isSyncing, forceSync } = useSyncEngine(); | ||
|
|
||
| return ( | ||
| <div> | ||
| <p>Network: {isOnline ? 'Online' : 'Offline'}</p> | ||
| <button onClick={forceSync} disabled={isSyncing || !isOnline}> | ||
| {isSyncing ? 'Syncing...' : 'Sync Now'} | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### 3. 使用离线 Provider | ||
|
|
||
| ```tsx | ||
| import { DatabaseProvider } from '@/providers/database-provider'; | ||
| import { OfflineProvider } from '@/providers/offline-provider'; | ||
| import { NetworkStatus } from '@/components/network-status'; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <DatabaseProvider> | ||
| <OfflineProvider> | ||
| <NetworkStatus /> | ||
| <YourAppContent /> | ||
| </OfflineProvider> | ||
| </DatabaseProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## 🌐 部署选项 | ||
|
|
||
| ### 选项 A: 纯离线模式 (推荐) | ||
|
|
||
| - 完全离线运行 | ||
| - 首次安装时包含种子数据 | ||
| - 适合无服务器部署 | ||
|
|
||
| ### 选项 B: 混合模式 | ||
|
|
||
| - 优先使用本地数据 | ||
| - 联网时同步到云端 | ||
| - 支持多设备数据同步 | ||
|
|
||
| ## 📊 性能优化建议 | ||
|
|
||
| 1. **数据库索引**: 已为高频查询字段创建索引 | ||
| 2. **连接池**: SQLite 自动管理连接 | ||
| 3. **批量操作**: 使用事务减少 I/O 次数 | ||
| 4. **缓存策略**: 配合 React Query 实现智能缓存 | ||
| 5. **图片优化**: 使用 Capacitor 文件系统缓存 | ||
|
|
||
| ## ⚠️ 注意事项 | ||
|
|
||
| 1. **Android 构建**: 需要安装 Android Studio 和 SDK | ||
| 2. **iOS 构建**: 需要 macOS 和 Xcode | ||
| 3. **SQLite 插件**: 在模拟器上可能需要额外配置 | ||
| 4. **首次启动**: 数据库初始化可能需要几秒 | ||
|
|
||
| ## 🔮 未来扩展 | ||
|
|
||
| - [ ] 端到端加密同步 | ||
| - [ ] 多用户支持 | ||
| - [ ] 课程包下载/导入 | ||
| - [ ] 语音识别离线支持 | ||
| - [ ] 学习数据分析和导出 | ||
|
|
||
| ## 📞 技术支持 | ||
|
|
||
| 如有问题,请查看: | ||
| - [Capacitor 文档](https://capacitorjs.com/docs) | ||
| - [SQLite 插件文档](https://github.com/capacitor-community/sqlite) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Current Node.js release schedule and end-of-life date for Node 18, plus recommended active LTS version for production Docker images💡 Result:
Current Node.js release schedule (as of 2026-04-29): - Node.js 25.x (Current): Initial release Oct 15, 2025; Maintenance starts Apr 1, 2026; EOL Jun 1, 2026. - Node.js 24.x (Active LTS, Krypton): Initial release May 6, 2025; Active LTS start Oct 28, 2025; Maintenance starts Oct 20, 2026; EOL Apr 30, 2028. - Node.js 22.x (Maintenance LTS, Jod): Initial release Apr 24, 2024; Active LTS start Oct 29, 2024; Maintenance starts Oct 21, 2025; EOL Apr 30, 2027. - Node.js 20.x (Maintenance LTS, Iron): Initial release Apr 18, 2023; Active LTS start Oct 24, 2023; Maintenance starts Oct 22, 2024; EOL Apr 30, 2026. Starting with Node.js 27.x (Apr 2027), the schedule evolves to one major release per year in April, with LTS promotion in October, and every release becoming LTS (no odd/even distinction). Node.js 18 (Hydrogen) end-of-life: April 30, 2025. It is now EOL and receives no updates or security patches. Recommended active LTS version for production Docker images: Node.js 24.x (Active LTS). Official Node.js Docker images support versions under active support per the release schedule. Use tags like node:24-bookworm-slim for production (slim variants recommended for smaller size). Production applications should use Active LTS or Maintenance LTS releases; avoid Current or EOL versions.
Citations:
Node.js 18 is end-of-life; upgrade to an active LTS version immediately.
Line 1 pins
node:18-alpine, which reached end-of-life on April 30, 2025 and no longer receives security patches. Usenode:22-alpine(Maintenance LTS) ornode:24-alpine(Active LTS) instead, and updatepackage.jsonengines to match.🧰 Tools
🪛 Trivy (0.69.3)
[error] 1-1: Image user should not be 'root'
Specify at least 1 USER command in Dockerfile with non-root user as argument
Rule: DS-0002
Learn more
(IaC/Dockerfile)
🤖 Prompt for AI Agents