AgentSkillsCN

server-guide

FastAPI 服务器与 REST API 概览

SKILL.md
--- frontmatter
name: server-guide
description: Overview of the FastAPI server and REST API
user-invocable: false

Server Layer Guide

Overview of the server layer in narrativegraphs/server/.

Components

ComponentPurpose
app.pyFastAPI application with routes and static file serving
backgroundserver.pyRun server in notebooks or background
requests.pyPydantic request models
routes/API endpoint handlers by entity type
static/Frontend visualization assets

Running the Server

Standalone: Set DB_PATH env var, run with uvicorn

In notebooks:

python
from narrativegraphs.server import BackgroundServer
server = BackgroundServer(db_engine, port=8001)
server.start()

Route Organization

RouterPrefixService
graph/graphGraphService
entities/entitiesEntityService
documents/docsDocService
relations/relationsRelationService
cooccurrences/cooccurrencesCooccurrenceService

All routes use QueryService via dependency injection.

Architecture

code
FastAPI App
    ├── Lifespan: DB engine + QueryService init
    ├── Routes (routes/) → QueryService sub-services
    └── Static Files → Frontend visualization

BackgroundServer → Wraps app for notebook usage