How xiamuceer-j/mumuainovel works
Purpose and Entry Points
MuMuAINovel is a full-stack AI-assisted novel-writing system: projects hold story structure, characters, relationships, chapters, memories, foreshadows, styles, and AI-generation history. The FastAPI backend starts at backend/app/main.py; the React SPA starts at frontend/src/main.tsx and frontend/src/App.tsx. Production packaging serves the application through Docker on port 8000.
Client Application
The React 18/TypeScript frontend provides authenticated project workspaces and feature pages for project creation, outline/world-building, chapter editing, character and relationship management, imports, prompts, and settings. API access and streaming-generation handling are centralized in frontend/src/services/api.ts and frontend/src/utils/sseClient.ts. Project-agent interaction is surfaced through frontend/src/components/project-agent/ProjectAgentPanel.tsx.
HTTP, Authentication, and API Boundary
FastAPI route modules expose domain APIs, with authentication and request identity enforced before business handling. Key boundary paths are backend/app/api/auth.py, backend/app/middleware/auth_middleware.py, and backend/app/api/projects.py. Authentication supports local accounts and LinuxDO OAuth; session/cookie settings are environment-controlled. API documentation is available from the FastAPI application.
Story Project Domain and Persistence
Projects are the aggregate around which outlines, chapters, characters, careers, relationships, memories, and foreshadows are managed. SQLAlchemy persistence is initialized in backend/app/database.py; core entities include backend/app/models/project.py, backend/app/models/chapter.py, and backend/app/models/character.py. Separate Alembic tracks support production PostgreSQL and local SQLite, including schema evolution for agent execution, asynchronous tasks, and analysis archives.
AI Generation and Context Pipeline
Generation-oriented APIs invoke a provider-neutral AI layer that selects configured OpenAI-compatible, Gemini, or Anthropic clients. The primary abstraction and provider implementations reside in backend/app/services/ai_service.py, backend/app/services/ai_clients/base_client.py, and backend/app/services/ai_providers/base_provider.py. Domain services assemble story context, generate or regenerate chapters, analyze plots, update character state, and persist resulting project data; representative paths are backend/app/services/chapter_context_service.py, backend/app/services/chapter_regenerator.py, and backend/app/services/plot_analyzer.py. Long-running interactions can return SSE progress to the frontend.
Agent, Skills, and Extensibility
A project-agent subsystem persists agents and execution steps, chooses tools, and exposes operational/extended project actions. Its orchestration boundary is backend/app/services/project_agent_service.py, with tool definitions in backend/app/services/project_agent_tools.py and API exposure in backend/app/api/project_agent.py. File-based writing skills provide curated instructions and references for long/short story analysis and writing, for example backend/app/skills/story-long-write/SKILL.md. MCP plugin support is isolated behind backend/app/mcp/facade.py and plugin APIs.
Infrastructure and External Services
The runtime is Python 3.12/FastAPI plus React/Vite, deployed by docker-compose.yml and built through Dockerfile. PostgreSQL 18 is the intended production datastore, initialized with backend/scripts/init_postgres.sql; async database URLs use asyncpg. External dependencies are AI APIs (OpenAI, Gemini, Anthropic), optional LinuxDO OAuth, SMTP/email capability, MCP endpoints, and image/cover providers. Local ONNX embeddings support semantic functionality through backend/app/services/onnx_embedding.py; the model is bundled in published images but required separately for source builds.
Main entry points: project.py Project aggregate · project_agent_service.py Agent orchestration · database.py SQLAlchemy persistence · App.tsx Workspace & feature pages
Components 22
React client
- SPA entry
frontend/src/main.tsx - Workspace & feature pages
frontend/src/App.tsx - API client · Centralizes API access and generation requests.
frontend/src/services/api.ts - Generation stream client
frontend/src/utils/sseClient.ts - Project agent panel
frontend/src/components/project-agent/ProjectAgentPanel.tsx
FastAPI boundary
- FastAPI application · Hosts routes and API documentation.
backend/app/main.py - Auth & identity · Supports local accounts, LinuxDO OAuth, and session cookies.
backend/app/middleware/auth_middleware.py - Projects API
backend/app/api/projects.py
Story domain & AI
- Project aggregate · Owns story structure, chapters, characters, memories, and foreshadows.
backend/app/models/project.py - Chapters
backend/app/models/chapter.py - Characters & relationships
backend/app/models/character.py - SQLAlchemy persistence · PostgreSQL in production; SQLite supported locally.
backend/app/database.py - Context & generation pipeline · Assembles context, regenerates chapters, analyzes plots, and persists updates.
backend/app/services/chapter_context_service.py - Provider-neutral AI · Selects configured OpenAI-compatible, Gemini, or Anthropic clients.
backend/app/services/ai_service.py
Agent extensibility
- Project agent API
backend/app/api/project_agent.py - Agent orchestration · Persists executions, selects tools, and performs project actions.
backend/app/services/project_agent_service.py - Writing skills
backend/app/skills/story-long-write/SKILL.md - MCP plugin facade
backend/app/mcp/facade.py
Runtime & externals
- Docker deployment · Serves the application on port 8000.
docker-compose.yml - PostgreSQL
backend/scripts/init_postgres.sql - AI provider APIs · OpenAI-compatible, Gemini, and Anthropic endpoints.
- OAuth, SMTP, image & MCP
Connections 25
- SPA entry → Workspace & feature pages: mounts
- Workspace & feature pages → API client: uses
- Workspace & feature pages → Project agent panel: shows
- API client → Generation stream client: streams generation
- API client → FastAPI application: HTTP API
- Project agent panel → Project agent API: agent actions
- FastAPI application → Auth & identity: enforces identity
- Auth & identity → Projects API: authorizes requests
- Projects API → Project aggregate: manages
- Project aggregate → Chapters: contains
- Project aggregate → Characters & relationships: contains
- Project aggregate → SQLAlchemy persistence: persists
- Projects API → Context & generation pipeline: generation requests
- Context & generation pipeline → Provider-neutral AI: invokes
- Context & generation pipeline → SQLAlchemy persistence: updates story state
- Provider-neutral AI → AI provider APIs: provider calls
- Project agent API → Agent orchestration: invokes
- Agent orchestration → SQLAlchemy persistence: persists runs and steps
- Agent orchestration → Writing skills: loads instructions
- Agent orchestration → MCP plugin facade: uses plugins
- MCP plugin facade → OAuth, SMTP, image & MCP: MCP endpoints
- Docker deployment → FastAPI application: deploys
- Docker deployment → PostgreSQL: runs with
- SQLAlchemy persistence → PostgreSQL: asyncpg connection
- Auth & identity → OAuth, SMTP, image & MCP: LinuxDO OAuth