This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Data lineage analysis system (数据血缘分析系统) — a FastAPI backend that parses Oracle .tab/.prc files, warehouse SQL files, and indicator xlsx files to build field-level lineage graphs, caliber tracing chains, and reliability indicators. Frontend is vanilla JS + D3.js v7 served as static files.
# Install dependencies
pip install -r requirements.txt
# Run dev server (port 8899, auto-reload)
python run_app.py
# Start/stop via shell scripts
./start.sh # sources .env, then runs python run_app.py
./stop.sh # kills the uvicorn process
# Run full test suite
python -m pytest tests/
# Run a single test file
python -m pytest tests/test_lineage_api.py -v
# Run specific test by name
python -m pytest tests/test_sqlite_store.py::test_save_and_load -v
# Lint (ruff)
ruff check app/ core/ tests/
# Type check (mypy)
mypy app/ core/
# Coverage is configured in pyproject.toml (--cov-fail-under=35)Three-layer design: API → Service → Core. core/ must stay framework-agnostic (no FastAPI imports).
SOURCE_DATA/ (.tab, .prc, .sql, .ctl, .xlsx)
→ ParserRegistry routes by file extension → FileParser implementations
→ ParseOutput (unified dict lists) → ParserService.ParseResult
→ CacheStore (SQLite or legacy pickle/json) persists results
→ DataRepository (in-memory index) serves queries
→ LineageService / CaliberTracer / IndicatorEngine
→ API responses (Pydantic models)
app/ — FastAPI application layer
api/— Route handlers (keep thin; business logic goes in services)services/— Orchestration:ParserService,LineageService,IndicatorService,TracerFactoryservices/storage/—CacheStorefacade delegates toSQLiteResultStore(default) orLegacyJsonPickleStoreviaResultStoreProtocolmodels/— Pydantic request/response schemasdependencies.py—@lru_cachesingleton providers for FastAPIDepends()injectionconfig.py—AppConfigdataclass, reads env vars andSOURCE_DATA/manifest.ymlrepository.py—DataRepository: in-memory search index (倒排索引) for tables/procedures
core/ — Domain logic (no framework dependencies)
models.py— Core dataclasses:TableInfo,ColumnInfo,CaliberInfo,CaliberChain,FieldMapping,ProcedureInfo,PipelineView,StepDetail, etc.parser_protocol.py—FileParser(typing.Protocol) +ParseOutput— the contract all parsers implementparser_registry.py—ParserRegistrymaps file extensions → parser instances; new file types justregister()adapters/— Oracle parsers:oracle_tab_adapter.py(.tab),oracle_prc_adapter.py(.prc),indicator_adapter.py(.xlsx)warehouse/— Warehouse SQL parser with two-phase DDL→DML logic:warehouse_parser.py,ddl_parser.py,dml_parser.py,schema_resolver.pypam/— Pipeline Analysis Module:pam_parser.py,pam_ddl_parser.py,pam_dml_parser.pycaliber_*.py— Caliber extraction/tracing modules (condition, expression, metadata, tracer, exporter)lineage/—chain_builder.py,graph_converter.pylayer_detector.py— Detects data layer (ODS/DWD/DWS/ADS/EAST) from table naming patternstable_name_resolver.py— Resolves short table names to full qualified names
CacheStore in app/services/cache_store.py is a facade that delegates to:
- SQLite (default):
SQLiteResultStoreatoutput/lineage.db, schema version tracked viaCACHE_SCHEMA_VERSION = "v4"inprotocol.py - Legacy:
LegacyJsonPickleStoreusing pickle + JSON files
Config: storage_backend, sqlite_db_path, enable_legacy_cache_write, enable_json_export (env vars or AppConfig)
Data sources are auto-discovered from SOURCE_DATA/manifest.yml (YAML list of sources with name, path, file_extensions, parser type). Falls back to hardcoded defaults in AppConfig.datasource_configs. Env vars TDH_DATA_DIR / GBASE_DATA_DIR add extra sources at runtime.
- Python 3.11+,
from __future__ import annotationsin all files - Type hints required;
snake_casefor functions/variables,PascalCasefor models - Route handlers in
app/api/must be thin — delegate to services core/must not import fromapp/- New parsers: implement
FileParserprotocol (duck typing, no inheritance required), thenregistry.register(instance) - Ruff: line-length 120, select E/F/W/I/N/UP/B/SIM;
core/has relaxed rules (SIM, N, B007, UP045 ignored) - Mypy:
ignore_missing_imports = true,core/allows untyped defs - Conventional Commits with Chinese summaries:
feat: ...,fix: ...,refactor: ... - Chinese comments are standard throughout the codebase
- pytest with
testpaths = tests, patterntest_*.py conftest.pyprovides basic fixtures (sample table/field names, test data dirs, sample .tab/.prc content)- API tests use
httpx.AsyncClientwith mocked services (~60s for full API suite) - Unit tests for
core/changes; API-level tests forapp/api/changes - Coverage configured in pyproject.toml:
--cov=app --cov=core --cov-fail-under=35 - Key test files:
test_sqlite_store.py,test_repository_search.py,test_lineage_api.py,test_caliber_api.py,test_parse_api.py,test_indicator_api.py
Key env vars (all optional, with defaults in AppConfig):
DEBUG— enable debug modePORT— server port (default 8899)DATA_DIR/SOURCE_DATA_DIR— data directoriesSTORAGE_BACKEND—sqliteorlegacySQLITE_DB_PATH— SQLite database pathTDH_DATA_DIR/GBASE_DATA_DIR— add extra warehouse data sources