How cjbshuosi/daoxin works
This repository is a full-stack Next.js application built around an AI-assisted content generation workflow, with a strong separation between UI, domain logic, knowledge content, and persistence.
1) Top-level architecture
The system is organized into four main boundaries:
1. Client-facing application shell and workflows
- Built with Next.js App Router under src/app.
- Most user interaction happens in reusable React components under src/components.
- Global state is managed with Zustand stores under src/store.
2. Server-side API layer
- Route handlers under src/app/api/* expose generation, knowledge matching, search, and performance-analysis capabilities.
- Middleware and API guards enforce request/auth boundaries.
3. Domain and AI orchestration layer
- Core business logic lives in src/lib.
- This includes model selection, prompt construction, calibration, memory handling, and API protection.
4. Data and knowledge layer
- Supabase provides authentication and database persistence.
- The doc/knowledge markdown files act as a curated domain knowledge base for tracks, strategies, and content patterns.
- SQL migrations under supabase/migrations define the backend schema.
2) Primary runtime and framework
• Next.js 15 / React 19 / TypeScript form the main application runtime.
• The app uses the App Router structure, with server-rendered pages, route handlers, and a shared layout.
• Supabase is the backend platform for auth and data storage.
• The README states AI integration is designed around multiple providers, likely via the Vercel AI SDK pattern, with support for Anthropic, OpenAI, and Google models.
3) Frontend structure
Application pages
The src/app tree indicates the main navigation surfaces:
• src/app/page.tsx — main landing/entry page.
• src/app/login/page.tsx — authentication entry.
• src/app/auth/callback/route.ts — OAuth or auth callback handling.
• src/app/test/page.tsx — likely a diagnostics or sandbox page.
Page-level feature containers
Feature screens are grouped under src/components:
• components/workspace/WorkspacePage.tsx — the primary creation workspace.
• components/generation/* — the multi-step generation wizard.
• components/knowledge/KnowledgePage.tsx — browse and manage track knowledge.
• components/tracks/TracksPage.tsx and components/track/* — track list and track detail/profile modals.
• components/performance/* — performance analysis UI.
• components/documents/DocumentsPage.tsx — document browsing/management.
• components/settings/SettingsPage.tsx — application settings.
• components/memory/* — memory visualization and editing.
Shared layout
• components/layout/AppLayout.tsx, SidebarMinimal.tsx, and TopBar.tsx define the shell around the active page.
• This suggests a single-shell application where navigation and top-level controls stay persistent while the main workspace changes.
UI system
• src/components/ui/* contains reusable primitive components such as buttons, dialogs, inputs, textareas, tooltips, badges, and scroll areas.
• components.json suggests the project is using a shadcn/ui-style component setup.
4) Core workflows and data flows
A. AI content generation flow
This is the main product workflow.
User-facing entry points:
• The workspace page
• The 5-step generation wizard in components/generation/StepCards/*
The step sequence is explicitly modeled in the UI:
• Topic confirmation
• Strategy selection
• Topic selection
• Final result generation
• Polish confirmation
Likely flow:
1. User enters a topic or idea in the workspace/wizard.
2. The client collects state across the step cards.
3. A generation API route is called: src/app/api/generate/route.ts.
4. Server logic in src/lib/prompt.ts, src/lib/model.ts, src/lib/calibration.ts, and possibly src/lib/memory.ts prepares the request.
5. The backend sends the request to an AI provider.
6. Generated text is returned to the client and displayed in result components such as ResultCard.tsx.
7. UI elements like EmotionCurve.tsx and Step5PolishConfirm.tsx support refinement before final confirmation.
Important architectural point:
• The client UI is not just a simple editor; it is a guided orchestration layer over server-side AI generation logic.
B. Track matching and knowledge retrieval
This repo is strongly domain-driven around “tracks” — niche content categories like finance, career, fitness, psychology, etc.
Relevant surfaces:
• Track-related components in components/track and components/tracks
• Knowledge page in components/knowledge
• Knowledge files in doc/knowledge
• API routes:
- src/app/api/match-track/route.ts
- src/app/api/search/route.ts
- src/app/api/generate-knowledge/route.ts
Likely flow:
1. User selects or searches for a track.
2. The app matches the input against curated track definitions and patterns.
3. Knowledge files provide track-specific strategy, tone, and structure.
4. The matched track influences generation prompts and output style.
This is an important boundary:
• The knowledge base is not embedded in the UI alone; it is a separate content corpus that informs generation and search behavior.
C. Performance analysis flow
The performance subsystem is a separate analysis pipeline.
Relevant routes:
• src/app/api/performance/parse-screenshot/route.ts
• src/app/api/performance/analyze/route.ts
Relevant UI:
• components/performance/AnalysisPanel.tsx
• PerformanceBadge.tsx
• PerformanceModal.tsx
Likely flow:
1. User uploads or submits a screenshot or performance artifact.
2. The screenshot is parsed server-side.
3. Parsed data is analyzed and converted into structured insights.
4. The UI renders score badges, analysis panels, and modal details.
This subsystem is distinct from generation:
• One creates content.
• The other evaluates content performance and feeds insight back into strategy.
D. Memory / preference feedback loop
The app includes a memory subsystem:
• src/lib/memory.ts
• components/memory/*
This suggests the app stores user preferences, prior successful patterns, or reusable context to improve future generation. In architecture terms, this is a feedback loop:
• Past usage informs future prompts and suggestions.
• The memory layer likely participates in prompt construction or UI defaults.
E. Authentication and session handling
Authentication is split across client and server boundaries:
• src/app/login/page.tsx for the login screen
• src/app/auth/callback/route.ts for callback processing
• src/hooks/useAuth.ts for client auth state
• src/lib/supabase/client.ts and server.ts for Supabase access
• middleware.ts likely guards routes or handles session propagation
This implies:
• Auth state is available both in the UI and in server route handlers.
• Protected actions such as generation, persistence, or analysis likely depend on Supabase session context.
5) Important backend and business logic boundaries
src/lib
This is the most important non-UI boundary in the repo:
• api-guard.ts — protects API routes and likely centralizes auth/rate-limit/validation concerns.
• model.ts — selects and configures AI providers/models.
• prompt.ts — prompt engineering and system instruction assembly.
• calibration.ts — tuning, scoring, or transformation logic used to adapt output quality.
• knowledge-seeds.ts — seed patterns and structured domain hints.
• memory.ts — user/context memory logic.
• constants.ts and utils.ts — shared configuration and helpers.
This layer is what turns the app from “UI plus API routes” into a content-engine product.
src/types
• Shared type definitions for domain objects and performance data live here.
• src/types/performance.ts suggests structured analysis output is a first-class domain model.
6) Persistence and external systems
Supabase
Supabase is the main external backend:
• Authentication
• Database persistence
• Likely storage of user state, settings, generated content, track data, or performance records
The presence of supabase/migrations/001_initial_schema.sql indicates the schema is intentionally versioned and managed as part of the repo.
AI provider layer
The README and src/lib/model.ts imply a multi-provider AI abstraction:
• Anthropic
• OpenAI
Architecturally, this means provider choice is abstracted behind the server-side model layer rather than scattered across the UI.
7) Content and documentation assets as part of the product
A notable part of this repo is that product knowledge is stored in the repository itself:
• doc/knowledge/*.md contains track-specific strategy docs.
• doc/ARCHITECTURE.md and other planning docs describe the intended system design and roadmap.
• doc/guid.pdf and related docs appear to support domain knowledge, design guidance, or operational planning.
This means the repo is not just code:
• It includes a content corpus that functions as an application asset.
• That knowledge content likely feeds generation, browsing, and track matching.
8) Legacy and static assets
• public-legacy/ contains an older static implementation (index.html, app.js, style.css).
• public/ contains current static assets.
Architecturally, the legacy directory suggests a prior non-React implementation was preserved, likely for reference, migration, or fallback purposes.
9) Cross-cutting concerns
State management
• Zustand stores in src/store handle global UI and workflow state:
- navigation
- performance
- settings
- tracks
This reduces prop drilling in a multi-step app with several interconnected panels.
Styling
• src/app/globals.css and src/styles/typewriter.css are the global style entry points.
• Tailwind-based styling is implied by the README and config files.
Request safety
• middleware.ts plus src/lib/api-guard.ts form the boundary that protects server actions and API endpoints.
10) What an architecture diagram should show
A clear diagram for this repository should include:
• User/browser
- interacts with the workspace, generator, knowledge, performance, memory, and settings screens
• Next.js App Router layer
- pages and route handlers
- shared layout
- auth callback and middleware
• Client feature components
- generation wizard
- track/knowledge browsing
- performance analysis panels
- memory UI
- settings and documents
• State layer
- Zustand stores for navigation, performance, settings, and track state
• Server domain layer
- API routes for generate, generate-knowledge, match-track, search, and performance analysis
- prompt/model/calibration/memory utilities
- API guard
• External services
- Supabase auth/database
- AI model providers
• Knowledge corpus
- markdown track docs under doc/knowledge
- seed/pattern data in src/lib/knowledge-seeds.ts
In short, this is a Next.js-based AI content strategy platform where the main architectural pattern is: user workflow UI on the client, server-side AI orchestration in API routes and lib, Supabase for auth/persistence, and a repository-backed knowledge base that shapes generation quality.
Main entry points: layout.tsx App shell · generate/route.ts Generate API · server.ts Supabase · match-track/route.ts Track APIs
Components 22
Client app
Next.js app shell, screens, and shared UI components
- User · Interacts with the app through workspace, tracks, knowledge, performance, and settings
- App shell · Shared Next.js layout and persistent navigation chrome
src/app/layout.tsx - Workspace · Primary creation surface for guided content generation
src/components/workspace/WorkspacePage.tsx - Generator flow · Five-step generation sequence and result presentation
src/components/generation/StepCards/StepContainer.tsx - Knowledge UI · Browse and manage track knowledge and strategy content
src/components/knowledge/KnowledgePage.tsx - Tracks UI · Track browsing, selection, and modal detail views
src/components/tracks/TracksPage.tsx - Performance UI · Screenshot and performance insight presentation
src/components/performance/AnalysisPanel.tsx - Memory UI · Displays and edits stored preferences and context
src/components/memory/MemoryDisplay.tsx - Settings UI · Application settings and configuration surface
src/components/settings/SettingsPage.tsx - Zustand stores · Navigation, performance, settings, and track state
src/store/useNavigationStore.ts
Server API
Route handlers and middleware boundary
- Generate API · Main content generation endpoint
src/app/api/generate/route.ts - Track APIs · Track matching, search, and knowledge generation endpoints
src/app/api/match-track/route.ts - Performance APIs · Parse screenshot and analyze performance artifacts
src/app/api/performance/analyze/route.ts - Auth boundary · Middleware and auth callback handling session flow
middleware.ts
Domain logic
AI orchestration, prompts, calibration, memory, and guards
- API guard · Central request protection and access control
src/lib/api-guard.ts - Prompt model · Model selection, prompt assembly, and provider abstraction
src/lib/model.ts - Calibration · Output shaping and quality adjustment logic
src/lib/calibration.ts - Memory core · Persists and reuses user context and preferences
src/lib/memory.ts - Knowledge seeds · Structured hints and reusable content patterns
src/lib/knowledge-seeds.ts
Data layer
Supabase persistence and repository-backed knowledge content
- Supabase · Authentication and database persistence
src/lib/supabase/server.ts - Knowledge corpus · Repository-managed markdown knowledge for tracks and strategy
doc/knowledge/track-licai.md - DB schema · Versioned Supabase schema and tables
supabase/migrations/001_initial_schema.sql
Connections 29
- User → App shell: uses · User interacts with the application shell
- App shell → Workspace: navigates · Shell routes into the main workspace
- App shell → Knowledge UI: navigates · Shell routes into knowledge browsing
- App shell → Tracks UI: navigates · Shell routes into track management
- App shell → Performance UI: navigates · Shell routes into analysis views
- App shell → Memory UI: navigates · Shell routes into memory views
- App shell → Settings UI: navigates · Shell routes into settings
- Workspace → Generator flow: hosts · Workspace drives the guided generation workflow
- Generator flow → Zustand stores: reads/writes · Wizard state is kept in global stores
- Generator flow → Generate API: calls · Final generation is requested from the server
- Knowledge UI → Track APIs: calls · Knowledge browsing and matching use track APIs
- Tracks UI → Track APIs: calls · Track selection and lookup use track APIs
- Performance UI → Performance APIs: calls · Performance analysis is delegated to server routes
- Generate API → API guard: protected by · Generation requests pass through request protection
- Track APIs → API guard: protected by · Track and search requests are guarded
- Performance APIs → API guard: protected by · Performance requests are guarded
- Generate API → Prompt model: uses · Generation composes prompts and selects models
- Generate API → Calibration: uses · Output quality is tuned before returning
- Generate API → Memory core: uses · Prior context influences generation
- Generate API → Knowledge seeds: uses · Seed patterns inform prompts and style
- Track APIs → Knowledge corpus: reads · Track matching and search consult markdown knowledge
- Knowledge corpus → Prompt model: informs · Knowledge content shapes generation prompts
- Memory UI → Memory core: edits · UI exposes stored memory for review and update
- Memory core → Supabase: persists to · Memory state is stored in the backend
- Auth boundary → Supabase: auths with · Middleware and callback rely on Supabase sessions
- Generate API → Supabase: reads/writes · Generation may persist or retrieve user data
- Track APIs → Supabase: reads/writes · Track data and user state are persisted
- Performance APIs → Supabase: reads/writes · Performance analysis records may be stored
- Supabase → DB schema: defined by · Database structure is versioned in migrations