Extract the schema of a Firestore database, identify relationships between collections, and generate visual representations of the schema and relationships using PlantUML and Mermaid.
Note: this is an exploratory project and not meant for production usage.
See Samples for sample schema, relationship, plantUML, image, and mermaid diagram files.
- Extract Firestore Schema: Retrieve the schema of a Firestore database, including collection names and their fields. Retrieve either a simple list of fields or a full schema with types and occurrence counts.
- Identify Relationships: Use OpenAI's GPT models to identify foreign key relationships between collections.
- Generate PlantUML / Mermaid text: Auto-create textual diagram blocks or full UML diagram definitions (using PlantUML or Mermaid ER shapes) for visualization tools.
-
Clone the repository
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables inside your
.envfile or export them directly:export OPENAI_API_KEY='your-api-key' export GOOGLE_APPLICATION_CREDENTIALS='path/to/service-account.json'
This tool now runs via a CLI script called fsviz.py providing multiple commands.
python fsviz.py [-h] [-v] {schema,subcollections,relationships,plantuml,schema-diagram,mermaid} ...-v,--verbose: Enable verbose output.
Extracts the database schema. Can output a simple list of fields or a full structure indicating object data types and counts.
python fsviz.py schema [--out output_file.json] [--full]--out: Overrides default output filename (which defaults to<project_id>.schema.json).--full: Outputs a full schema dict indicating types and occurrence counts.
Extracts the database schema for sub-collections of a specific parent collection.
python fsviz.py subcollections <collection_name> [--out output_file.json] [--full] [--limit 100]<collection_name>: Name of the parent collection.--out: Overrides default output filename (defaults to<project_id>.<collection_name>.schema.json).--full: Outputs a full schema dict indicating types and occurrence counts.--limit: Number of documents to sample from each collection (defaults to 100).
Analyzes the schema JSON via OpenAI LLMs to identify the implicit connections between models.
python fsviz.py relationships --schema <schema.json> [--out output_rels.json]Generates the specific commands used to visualize via PlantUML tools.
python fsviz.py plantuml --schema <schema.json> --relationships <rels.json> [--out output.puml]
#: example
python fsviz.py plantuml --schema samples/sample.schema.json --relationships samples/sample.relationships.json --out samples/sample.pumlGenerates markdown standard Mermaid ER representations.
python fsviz.py mermaid --schema <schema.json> --relationships <rels.json> [--out output.mmd]fsviz.py: The main argparse CLI router.schema_handler.py: Dedicated file encapsulating Firestore authentication initialization,get_schema, andget_subcollections_schemaiterations.utils.py: Reusable utilities and generator classes covering OpenAI requests (identify_relationships_llm) and Diagram generations (generate_plantuml_text,generate_mermaid_text).
Credits: I was inspired by the earlier draft of schema visualizer from https://github.com/analyticalmonk/firestore-schema-visualizer This code enhances and prepares it for the latest version of OpenAI gpt-5.1 models and adds mermaid diagrams besides some other improvements.
