{"id":240,"date":"2026-06-19T19:10:07","date_gmt":"2026-06-19T11:10:07","guid":{"rendered":"https:\/\/erishen.cn\/?page_id=240"},"modified":"2026-06-19T19:28:55","modified_gmt":"2026-06-19T11:28:55","slug":"monorepo-nextjs-fastapi-knowledge-base","status":"publish","type":"page","link":"https:\/\/erishen.cn\/?page_id=240","title":{"rendered":"Building a Full-Stack Knowledge Base Platform: Monorepo + Next.js 14 + FastAPI in Practice"},"content":{"rendered":"<p><\/p>\n<p>A full-stack development practice based on Turborepo + Next.js 14 + FastAPI, suitable as an architecture reference for small to medium-sized projects.<\/p>\n<p><\/p>\n<h2>Project Background<\/h2>\n<p><\/p>\n<p>After years of development, I found my technical knowledge scattered across projects and notes. To systematically organize this knowledge, I built a technical knowledge base platform \u2014 not just for personal knowledge management, but also as an open-source reference for other developers.<\/p>\n<p><\/p>\n<p><strong>Core requirements<\/strong>: unified note management, online editing with real-time preview, elegant documentation display, and exploration of full-stack best practices.<\/p>\n<p><\/p>\n<h2>Technology Selection &#038; Architecture<\/h2>\n<p><\/p>\n<h3>Why Monorepo?<\/h3>\n<p><\/p>\n<table>\n<thead>\n<tr>\n<td>Dimension<\/td>\n<td>Multi-repo<\/td>\n<td>Monorepo (Turborepo)<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Code sharing<\/td>\n<td>Publish npm packages<\/td>\n<td>Workspace direct reference<\/td>\n<\/tr>\n<tr>\n<td>Version control<\/td>\n<td>Independent versions<\/td>\n<td>Unified versioning<\/td>\n<\/tr>\n<tr>\n<td>CI\/CD<\/td>\n<td>Multiple pipelines<\/td>\n<td>Single build process<\/td>\n<\/tr>\n<tr>\n<td>Dependency mgmt<\/td>\n<td>Version conflicts likely<\/td>\n<td>Unified dependency management<\/td>\n<\/tr>\n<tr>\n<td>Cross-package testing<\/td>\n<td>Difficult<\/td>\n<td>Straightforward<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<h3>Core Tech Stack<\/h3>\n<p><\/p>\n<p>&#8211; <strong>Frontend<\/strong>: Next.js 14 (App Router), React 18, TypeScript 5, Turborepo<\/p>\n<p>&#8211; <strong>Backend<\/strong>: FastAPI, Python 3.10+, Pydantic v2, SQLAlchemy, Alembic, Uvicorn<\/p>\n<p>&#8211; <strong>Data<\/strong>: MySQL 8.0, Redis, Supabase (auth)<\/p>\n<p>&#8211; <strong>Content<\/strong>: next-mdx-remote, @tailwindcss\/typography<\/p>\n<p>&#8211; <strong>Styling<\/strong>: Tailwind CSS, styled-components<\/p>\n<p>&#8211; <strong>Dev tools<\/strong>: ESLint + Prettier, Storybook, Changeset<\/p>\n<p>&#8211; <strong>Deploy<\/strong>: Vercel (frontend), Docker + Nginx (backend), pnpm<\/p>\n<p><\/p>\n<h3>Architecture Overview<\/h3>\n<p><\/p>\n<pre><code>\nUser Access Layer\n  web.erishen.cn (Frontend)  |  admin.erishen.cn (Admin)\n              \u2193\nAPI Gateway: api.erishen.cn (FastAPI)\n  - Items API  |  Auth API  |  Docs API  |  Redis API\n              \u2193\n    MySQL 8.0          Redis\n<\/code><\/pre>\n<p><\/p>\n<h3>Monorepo Structure<\/h3>\n<p><\/p>\n<pre><code>\napps\/\n\u251c\u2500\u2500 web\/          # Main app (port 3000) - doc browsing\n\u2514\u2500\u2500 admin\/        # Admin panel (port 3003) - doc editing\n\npackages\/\n\u251c\u2500\u2500 ui\/           # Shared UI component library\n\u251c\u2500\u2500 api-client\/   # API client\n\u251c\u2500\u2500 utils\/        # Utility functions\n\u251c\u2500\u2500 types\/        # Type definitions\n\u2514\u2500\u2500 config\/       # Shared configuration\n\ndocs\/             # Knowledge base Markdown source files\nscripts\/          # Utility scripts\n<\/code><\/pre>\n<p><\/p>\n<h3>Backend Layered Architecture<\/h3>\n<p><\/p>\n<pre><code>\nfastapi-web\/\n\u251c\u2500\u2500 app\/\n\u2502   \u251c\u2500\u2500 routers\/       # API routing layer\n\u2502   \u251c\u2500\u2500 crud.py        # Database operations\n\u2502   \u251c\u2500\u2500 models.py      # SQLAlchemy models\n\u2502   \u251c\u2500\u2500 schemas.py     # Pydantic validation\n\u2502   \u251c\u2500\u2500 security.py    # JWT, auth\n\u2502   \u251c\u2500\u2500 middleware.py   # Logging, rate limiting\n\u2502   \u251c\u2500\u2500 factory.py     # App factory pattern\n\u2502   \u2514\u2500\u2500 ...\n\u251c\u2500\u2500 alembic\/           # Database migrations\n\u251c\u2500\u2500 tests\/\n\u251c\u2500\u2500 Dockerfile\n\u2514\u2500\u2500 docker-compose.yml\n<\/code><\/pre>\n<p><\/p>\n<h2>Core Features<\/h2>\n<p><\/p>\n<h3>Frontend Knowledge Base<\/h3>\n<p><\/p>\n<p>&#8211; Structured document browsing with MDX rendering<\/p>\n<p>&#8211; Document loading from Admin API with local filesystem fallback<\/p>\n<p>&#8211; Search, code highlighting, responsive design<\/p>\n<p><\/p>\n<h3>Admin Application<\/h3>\n<p><\/p>\n<p>&#8211; Online Markdown editor for docs\/<\/p>\n<p>&#8211; Dual authentication demo (NextAuth.js + Passport.js)<\/p>\n<p>&#8211; CSRF protection, Redis cache demos<\/p>\n<p>&#8211; FastAPI service proxy<\/p>\n<p><\/p>\n<h3>FastAPI Backend<\/h3>\n<p><\/p>\n<p>Full CRUD REST API with JWT auth, rate limiting, suspicious access detection, CORS, SQL injection prevention (ORM), XSS protection.<\/p>\n<p><\/p>\n<h3>Shared Component Library<\/h3>\n<p><\/p>\n<pre><code>\n\/\/ Import in any app with full TypeScript support\nimport { Button, Card, Input } from \"@interview\/ui\";\n&lt;Button variant=\"primary\" size=\"large\"&gt;Click Me&lt;\/Button&gt;\n<\/code><\/pre>\n<p><\/p>\n<h2>Deployment<\/h2>\n<p><\/p>\n<h3>Frontend: Vercel<\/h3>\n<p>&#8211; Auto-deploy on git push<\/p>\n<p>&#8211; Serverless functions<\/p>\n<p>&#8211; Global CDN, automatic HTTPS<\/p>\n<p><\/p>\n<h3>Backend: Docker + Nginx<\/h3>\n<p><\/p>\n<pre><code>\n# docker-compose.prod.yml\nservices:\n  app:\n    build: .\n    container_name: fastapi-web-app\n    network_mode: host\n    restart: always\n    environment:\n      - APP_ENV=production\n      - PORT=8086\n    healthcheck:\n      test: [\"CMD\", \"curl\", \"-f\", \"http:\/\/localhost:8086\/health\"]\n      interval: 30s\n      retries: 3\n<\/code><\/pre>\n<p><\/p>\n<h2>Key Takeaways<\/h2>\n<p><\/p>\n<p>&#8211; <strong>Monorepo suits small-medium teams<\/strong>: Code sharing and unified dependencies, but evaluate carefully for massive projects<\/p>\n<p>&#8211; <strong>Pragmatic tech choices<\/strong>: Next.js 14 + FastAPI is efficient for medium projects<\/p>\n<p>&#8211; <strong>Engineering matters<\/strong>: Turborepo, Docker, CI\/CD significantly improve dev efficiency and deployment reliability<\/p>\n<p>&#8211; <strong>Iterate from simple<\/strong>: Implement core features first, then progressively enhance<\/p>\n<p>&#8211; <strong>Security throughout<\/strong>: Even small projects need basic security (JWT, rate limiting, CORS)<\/p>\n<p><\/p>\n<h2>Links<\/h2>\n<p><\/p>\n<p>&#8211; Frontend: <a href=\"https:\/\/github.com\/erishen\/interview\">github.com\/erishen\/interview<\/a><\/p>\n<p>&#8211; Backend: <a href=\"https:\/\/github.com\/erishen\/fastapi-web\">github.com\/erishen\/fastapi-web<\/a><\/p>\n<p>&#8211; Web App: <a href=\"https:\/\/web.erishen.cn\">web.erishen.cn<\/a><\/p>\n<p>&#8211; Admin: <a href=\"https:\/\/admin.erishen.cn\">admin.erishen.cn<\/a><\/p>\n<p>&#8211; API: <a href=\"https:\/\/api.erishen.cn\">api.erishen.cn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A full-stack development practice based on Turborepo +  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"english_url":"","chinese_url":"https:\/\/erishen.cn\/?p=180","footnotes":""},"class_list":["post-240","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/pages\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/erishen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=240"}],"version-history":[{"count":3,"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/pages\/240\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/erishen.cn\/index.php?rest_route=\/wp\/v2\/pages\/240\/revisions\/256"}],"wp:attachment":[{"href":"https:\/\/erishen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}