codewiki
Data Layer

Database Models & Schema

Overview

DeepDoc uses SQLAlchemy as its primary ORM for database modeling and schema management. All core models are defined in deepdoc/scan_v2.py, which acts as the central schema file. The system supports evidence-driven clustering, endpoint bundling, and integration discovery, with models representing both business entities and artifact tracking.

Migrations are managed via SQLAlchemy-compatible migration tools (e.g., Alembic), with migration files auto-detected and tracked. For a high-level system context, see DeepDoc Architecture & System Overview.

SQLAlchemy is detected as the primary ORM. All models are Python dataclasses, suitable for both relational and document-style storage.

Entity-Relationship Diagram

Below is a complete ER diagram showing all detected models, their key fields, and relationships:


Tables / Models

SymbolCluster (deepdoc/scan_v2.py:47)

Column / FieldTypeConstraintsDescription
cluster_namestringNOT NULLBusiness domain cluster name (e.g., "checkout")
descriptionstringCluster description
symbolslist[string]Symbol names in this cluster
line_rangeslist[tuple]Line ranges per symbol
related_importslist[string]Imports related to this cluster

Relationships:

  • Referenced by GiantFileAnalysis.clusters (one-to-many)

Indexes: None declared.

Used by: Parsing & Source Analysis, Pipeline & Generation Engine


GiantFileAnalysis (deepdoc/scan_v2.py:57)

Column / FieldTypeConstraintsDescription
file_pathstringNOT NULLPath to analyzed file
line_countintTotal lines in file
total_symbolsintNumber of detected symbols
clusterslistList of SymbolCluster objects

Relationships:

  • has_many SymbolCluster (via clusters)

Indexes: None declared.

Used by: Parsing & Source Analysis


EvidenceUnit (deepdoc/scan_v2.py:272)

Column / FieldTypeConstraintsDescription
file_pathstringNOT NULLPath to evidence file
rolestringRole (handler, service, model, etc.)
symbolslist[string]Relevant symbols
relevancefloatRelevance score (0.0–1.0)

Relationships:

  • Referenced by EndpointBundle.evidence (one-to-many)

Indexes: None declared.

Used by: Pipeline & Generation Engine, Public API Endpoints


EndpointBundle (deepdoc/scan_v2.py:281)

Column / FieldTypeConstraintsDescription
endpoint_familystringNOT NULLResource family (e.g., "orders")
methods_pathslist[string]Methods and paths (e.g., "POST /orders")
handler_filestringHandler file path
handler_symbolslist[string]Handler symbol names
evidencelistList of EvidenceUnit objects
integration_edgeslist[string]Integration names touched

Relationships:

  • has_many EvidenceUnit (via evidence)
  • has_many IntegrationIdentity (via integration_edges)

Indexes: None declared.

Used by: Public API Endpoints, Pipeline & Generation Engine


IntegrationCandidate (deepdoc/scan_v2.py:551)

Column / FieldTypeConstraintsDescription
signal_typestringType (http_client, sdk_import, etc.)
name_hintstringIntegration name hint
file_pathstringFile where signal was found
evidencestringEvidence line/pattern
confidencefloatConfidence score

Relationships: None.

Indexes: None declared.

Used by: Integration Discovery, Integration Discovery


IntegrationIdentity (deepdoc/scan_v2.py:561)

Column / FieldTypeConstraintsDescription
namestringNOT NULLCanonical integration name
display_namestringHuman-readable name
descriptionstringIntegration description
fileslist[string]Files involved
evidencelist[string]Evidence lines
is_substantialboolStandalone doc page flag
partystring"third_party", etc.

Relationships: None.

Indexes: None declared.

Used by: Integration Discovery, Integration Discovery


ModelFileInfo (deepdoc/scan_v2.py:854)

Column / FieldTypeConstraintsDescription
file_pathstringNOT NULLModel/schema file path
orm_frameworkstringORM framework name
model_nameslist[string]Detected model/class names
is_migrationboolMigration file flag

Relationships: None.

Indexes: None declared.

Used by: Setup & Getting Started


DatabaseScan (deepdoc/scan_v2.py:863)

Column / FieldTypeConstraintsDescription
model_fileslistList of ModelFileInfo objects
migration_fileslist[string]Migration file paths
schema_fileslist[string]Schema definition files
orm_frameworkstringPrimary ORM framework
total_modelsintTotal detected models

Relationships:

  • has_many ModelFileInfo (via model_files)

Indexes: None declared.

Used by: Setup & Getting Started


ArtifactScan (deepdoc/scan_v2.py:873)

Column / FieldTypeConstraintsDescription
setup_artifactslist[string]Setup artifact files
deploy_artifactslist[string]Deployment artifact files
test_artifactslist[string]Test artifact files
ci_artifactslist[string]CI artifact files
ops_artifactslist[string]Ops artifact files
database_scanDatabaseScanDatabase scan results

Relationships:

  • has_one DatabaseScan (via database_scan)

Indexes: None declared.

Used by: Setup & Getting Started, Testing & Continuous Integration


Relationships Summary

The schema is highly modular, with most relationships expressed via lists of objects (one-to-many). There are no explicit foreign keys, but logical relationships are enforced via object references.

Source ModelTarget ModelRelationship TypeField
GiantFileAnalysisSymbolClusterone-to-manyclusters
EndpointBundleEvidenceUnitone-to-manyevidence
EndpointBundleIntegrationIdentityone-to-manyintegration_edges
DatabaseScanModelFileInfoone-to-manymodel_files
ArtifactScanDatabaseScanone-to-onedatabase_scan
All relationships are managed in-memory via Python lists. There are no enforced DB-level foreign keys.

If you need a visual class relationship diagram:


Migrations

Migrations are detected and tracked via the DatabaseScan.migration_files field (deepdoc/scan_v2.py:863). Migration files are auto-discovered based on common patterns (e.g., Alembic, Django, Prisma, TypeORM, Sequelize). Manual and data migrations should be placed in recognized migration directories.

Run migrations Use your ORM's migration tool (e.g., Alembic for SQLAlchemy) to apply schema changes.

Verify migration files Ensure all migration files are detected by DatabaseScan.migration_files.

Check for manual migrations If you have manual SQL/data migrations, document them in the migration directory.

For setup details, see Setup & Getting Started.


Query Patterns & Performance

  • Query Patterns: Most queries are simple object traversals (list, filter, group). Heavy joins are avoided by design; relationships are managed via in-memory lists.
  • N+1 Risks: Minimal, since evidence and integration edges are batch-loaded.
  • Denormalisation: Artifact and evidence scans are denormalized for performance.
  • Caching: No explicit caching layer is present in the schema. If you need caching strategies, refer to Pipeline & Generation Engine.
Batch processing is recommended for large evidence sets — see Pipeline & Generation Engine.

Configuration

Database connection settings are managed via environment variables and config files, auto-detected by setup patterns (e.g., .env.example, pyproject.toml). For connection pooling and read replicas, configure your SQLAlchemy engine accordingly.

Variable / FileRequiredDefaultDescription
DATABASE_URLYesNoneConnection string
ORM_FRAMEWORKNosqlalchemyORM framework name
MIGRATION_DIRNoNoneMigration directory path

For environment setup, see Setup & Getting Started.


See Also

Ask the codebase

Open a dedicated answer page with grounded citations.

Ask from any docs page and keep reading without losing context.