本文将带你从 0 到 1 实战搭建一个基于 Nuxt 3 和 Node.js 的全栈博客系统,支持用户登录、文章创作、AI 写作辅助、私信通信等功能。
🧱 项目技术栈
层级
技术选型
前端
Nuxt 3(Vue 3 + SSR)、Pinia、Arco Design
后端
Node.js、Express
数据库
MongoDB(Mongoose)/ 可替换为 MySQL
AI 能力
DeepSeek/CopilotKit(AI 写作助手)
部署
Vercel(前端)、Render(后端)或 Railway 全栈托管
1️⃣ Nuxt 3 前端架构设计
页面设计:
-
/login登录页(支持账号密码 + Cookie 持久化) -
/editor文章创作页(富文本 + AI 生成) -
/article/[id]文章详情页 -
/message私信界面(双人私聊) -
/search全文搜索与分类筛选
状态管理:
使用 Pinia 管理用户状态、主题配置等:
tsCopyEdit// store/user.ts
export const useUserStore = defineStore('user', {
state: () => ({ userInfo: null }),
actions: {
setUser(info) {
this.userInfo = info
}
}
})
组件封装:
-
全局组件如
AppHeader.vue、EditorInput.vue封装统一风格 -
使用 Arco Design 实现美观响应式 UI
2️⃣ Node.js 后端 API 设计
使用 Express + Mongoose 设计 RESTful API:
主要接口:
接口
描述
POST /api/auth/login
用户登录,返回 token
POST /api/article/create
创建文章
GET /api/article/list
获取文章列表
POST /api/message/send
发送私信消息
GET /api/search?q=xxx
搜索文章关键词
示例代码:
jsCopyEditapp.post('/api/article/create', async (req, res) => {
const { title, content, authorId } = req.body;
const newArticle = await Article.create({ title, content, author: authorId });
res.json({ success: true, data: newArticle });
});
3️⃣ AI 写作助手接入(DeepSeek)
你可以在编辑器页面添加 AI 按钮,让用户输入提示词后调用 AI API 自动补全文章内容。
tsCopyEditconst generateContent = async (prompt: string) => {
const { data } = await axios.post('/api/ai/generate', { prompt });
editorContent.value += data.result;
};
后端使用代理调用 LLM(例如 DeepSeek、CopilotKit):
jsCopyEditapp.post('/api/ai/generate', async (req, res) => {
const prompt = req.body.prompt;
const response = await fetch('https://api.deepseek.com/v1/chat', {
headers: { Authorization: `Bearer ${API_KEY}` },
body: JSON.stringify({ messages: [{ role: 'user', content: prompt }] })
});
const result = await response.json();
res.json({ result: result.choices[0].message.content });
});
4️⃣ 数据库结构设计
以 MongoDB 为例:
jsCopyEdit// Article Schema
{
title: String,
content: String,
author: ObjectId,
tags: [String],
createdAt: Date,
}
jsCopyEdit// Message Schema
{
from: ObjectId,
to: ObjectId,
content: String,
timestamp: Date,
}
5️⃣ 项目部署策略
前端部署到 Vercel:
bashCopyEditnpm run build
vercel deploy
后端部署到 Render:
-
创建 Node.js 服务
-
绑定环境变量(Mongo URI、AI KEY)
-
支持 webhook 自动部署
可选方案:Railway 一键全栈部署
✅ 项目亮点总结
-
使用 Nuxt 3 + SSR 实现 SEO 友好的博客系统
-
完整的用户系统、文章模块、AI 写作功能
-
私信通信系统(可扩展为 WebSocket 实时聊天)
-
前后端分离部署,适合实际生产开发
🏁 结语
这个项目是我在学习 Nuxt 3 和 Node.js 过程中总结的成果,欢迎交流与建议!
如果你也对前端全栈开发、AI 技术落地感兴趣,可以关注我,后续还会分享更细致的模块拆解与优化技巧。