# xiamuceer-j/mumuainovel architecture

> Architecture diagram of the GitHub repository xiamuceer-j/mumuainovel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xiamuceer-j/mumuainovel
- Repository: https://github.com/xiamuceer-j/mumuainovel

## Overview

#### 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: [`backend/app/models/project.py`](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/project.py) (Project aggregate), [`backend/app/services/project_agent_service.py`](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/project_agent_service.py) (Agent orchestration), [`backend/app/database.py`](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/database.py) (SQLAlchemy persistence), [`frontend/src/App.tsx`](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/App.tsx) (Workspace & feature pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_spa_entry["SPA entry<br/>React/Vite<br/>[main.tsx]"]
  node_app_shell["Workspace &amp; feature pages<br/>React UI<br/>[App.tsx]"]
  node_api_client["API client<br/>HTTP client<br/>[api.ts]"]
  node_sse_client["Generation stream client<br/>SSE client<br/>[sseClient.ts]"]
  node_agent_panel["Project agent panel<br/>React component"]
end

subgraph group_api["FastAPI boundary"]
  node_fastapi_app["FastAPI application<br/>Python API<br/>[main.py]"]
  node_auth["Auth &amp; identity<br/>route + middleware<br/>[auth_middleware.py]"]
  node_projects_api["Projects API<br/>route module<br/>[projects.py]"]
end

subgraph group_domain["Story domain &amp; AI"]
  node_project_domain["Project aggregate<br/>domain model<br/>[project.py]"]
  node_chapters["Chapters<br/>entity<br/>[chapter.py]"]
  node_characters["Characters &amp; relationships<br/>entity<br/>[character.py]"]
  node_database[("SQLAlchemy persistence<br/>database layer<br/>[database.py]")]
  node_generation_pipeline["Context &amp; generation pipeline<br/>domain services"]
  node_ai_service["Provider-neutral AI<br/>AI service<br/>[ai_service.py]"]
end

subgraph group_agent["Agent extensibility"]
  node_project_agent_api["Project agent API<br/>route module<br/>[project_agent.py]"]
  node_project_agent["Agent orchestration<br/>agent service"]
  node_skills["Writing skills<br/>file-based instructions<br/>[SKILL.md]"]
  node_mcp["MCP plugin facade<br/>plugin boundary<br/>[facade.py]"]
end

subgraph group_infra["Runtime &amp; externals"]
  node_docker["Docker deployment<br/>container runtime<br/>[docker-compose.yml]"]
  node_postgres[("PostgreSQL<br/>production datastore<br/>[init_postgres.sql]")]
  node_ai_providers["AI provider APIs<br/>external service"]
  node_external_integrations["OAuth, SMTP, image &amp; MCP<br/>external services"]
end

node_spa_entry -->|"mounts"| node_app_shell
node_app_shell -->|"uses"| node_api_client
node_app_shell -->|"shows"| node_agent_panel
node_api_client -->|"streams generation"| node_sse_client
node_api_client -->|"HTTP API"| node_fastapi_app
node_agent_panel -->|"agent actions"| node_project_agent_api
node_fastapi_app -->|"enforces identity"| node_auth
node_auth -->|"authorizes requests"| node_projects_api
node_projects_api -->|"manages"| node_project_domain
node_project_domain -->|"contains"| node_chapters
node_project_domain -->|"contains"| node_characters
node_project_domain -->|"persists"| node_database
node_projects_api -->|"generation requests"| node_generation_pipeline
node_generation_pipeline -->|"invokes"| node_ai_service
node_generation_pipeline -->|"updates story state"| node_database
node_ai_service -->|"provider calls"| node_ai_providers
node_project_agent_api -->|"invokes"| node_project_agent
node_project_agent -->|"persists runs and steps"| node_database
node_project_agent -->|"loads instructions"| node_skills
node_project_agent -->|"uses plugins"| node_mcp
node_mcp -->|"MCP endpoints"| node_external_integrations
node_docker -->|"deploys"| node_fastapi_app
node_docker -->|"runs with"| node_postgres
node_database -->|"asyncpg connection"| node_postgres
node_auth -.->|"LinuxDO OAuth"| node_external_integrations

click node_spa_entry "https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/App.tsx"
click node_api_client "https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/services/api.ts"
click node_sse_client "https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/utils/sseClient.ts"
click node_agent_panel "https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/components/project-agent/ProjectAgentPanel.tsx"
click node_fastapi_app "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/main.py"
click node_auth "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/middleware/auth_middleware.py"
click node_projects_api "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/api/projects.py"
click node_project_domain "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/project.py"
click node_chapters "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/chapter.py"
click node_characters "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/character.py"
click node_database "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/database.py"
click node_generation_pipeline "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/chapter_context_service.py"
click node_ai_service "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/ai_service.py"
click node_project_agent_api "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/api/project_agent.py"
click node_project_agent "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/project_agent_service.py"
click node_skills "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/skills/story-long-write/SKILL.md"
click node_mcp "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/mcp/facade.py"
click node_docker "https://github.com/xiamuceer-j/mumuainovel/blob/main/docker-compose.yml"
click node_postgres "https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/scripts/init_postgres.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa_entry,node_app_shell,node_api_client,node_sse_client,node_agent_panel toneBlue
class node_fastapi_app,node_auth,node_projects_api toneAmber
class node_project_domain,node_chapters,node_characters,node_database,node_generation_pipeline,node_ai_service toneMint
class node_project_agent_api,node_project_agent,node_skills,node_mcp toneRose
class node_docker,node_postgres,node_ai_providers,node_external_integrations toneIndigo
```

## Components

### React client

- [SPA entry](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/main.tsx): React/Vite · `frontend/src/main.tsx`
- [Workspace & feature pages](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/App.tsx): React UI · `frontend/src/App.tsx`
- [API client](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/services/api.ts): HTTP client · Centralizes API access and generation requests. · `frontend/src/services/api.ts`
- [Generation stream client](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/utils/sseClient.ts): SSE client · `frontend/src/utils/sseClient.ts`
- [Project agent panel](https://github.com/xiamuceer-j/mumuainovel/blob/main/frontend/src/components/project-agent/ProjectAgentPanel.tsx): React component · `frontend/src/components/project-agent/ProjectAgentPanel.tsx`

### FastAPI boundary

- [FastAPI application](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/main.py): Python API · Hosts routes and API documentation. · `backend/app/main.py`
- [Auth & identity](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/middleware/auth_middleware.py): route + middleware · Supports local accounts, LinuxDO OAuth, and session cookies. · `backend/app/middleware/auth_middleware.py`
- [Projects API](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/api/projects.py): route module · `backend/app/api/projects.py`

### Story domain & AI

- [Project aggregate](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/project.py): domain model · Owns story structure, chapters, characters, memories, and foreshadows. · `backend/app/models/project.py`
- [Chapters](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/chapter.py): entity · `backend/app/models/chapter.py`
- [Characters & relationships](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/models/character.py): entity · `backend/app/models/character.py`
- [SQLAlchemy persistence](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/database.py): database layer · PostgreSQL in production; SQLite supported locally. · `backend/app/database.py`
- [Context & generation pipeline](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/chapter_context_service.py): domain services · Assembles context, regenerates chapters, analyzes plots, and persists updates. · `backend/app/services/chapter_context_service.py`
- [Provider-neutral AI](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/ai_service.py): AI service · Selects configured OpenAI-compatible, Gemini, or Anthropic clients. · `backend/app/services/ai_service.py`

### Agent extensibility

- [Project agent API](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/api/project_agent.py): route module · `backend/app/api/project_agent.py`
- [Agent orchestration](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/services/project_agent_service.py): agent service · Persists executions, selects tools, and performs project actions. · `backend/app/services/project_agent_service.py`
- [Writing skills](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/skills/story-long-write/SKILL.md): file-based instructions · `backend/app/skills/story-long-write/SKILL.md`
- [MCP plugin facade](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/app/mcp/facade.py): plugin boundary · `backend/app/mcp/facade.py`

### Runtime & externals

- [Docker deployment](https://github.com/xiamuceer-j/mumuainovel/blob/main/docker-compose.yml): container runtime · Serves the application on port 8000. · `docker-compose.yml`
- [PostgreSQL](https://github.com/xiamuceer-j/mumuainovel/blob/main/backend/scripts/init_postgres.sql): production datastore · `backend/scripts/init_postgres.sql`
- **AI provider APIs**: external service · OpenAI-compatible, Gemini, and Anthropic endpoints.
- **OAuth, SMTP, image & MCP**: external services

## Connections

- 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
