Cartography Overview
Relevant source files
The following files were used as context for generating this wiki page:
Cartography consolidates technical infrastructure assets and their relationships into a Neo4j graph database. It supports over 30 platforms, including AWS, GCP, Azure, Kubernetes, GitHub, and Okta, to provide a unified view of an organization's security posture and asset inventory. The tool enables users to query complex relationships, such as identifying compute instances exposed to the internet or mapping identities to specific datastores across multiple cloud providers.
The project operates as a Python-based tool that executes a structured synchronization process to fetch data from external APIs, transform it into a graph-compatible format, and load it into Neo4j. It also includes a rules engine to run security checks against the populated graph.
Sources: README.md:1-25, cartography/cli.py:347-353
System Architecture
Cartography consists of four primary layers: the Command Line Interface (CLI), the Sync Engine, Intel Modules, and the Neo4j Storage Layer.
The diagram above shows the high-level flow from configuration and execution through data ingestion to graph analysis.
Core Components
| Component | Description |
|---|---|
CLI (cli.py) | Handles argument parsing, logging configuration, and initiates the sync process using Typer. |
| Sync Engine | Manages the execution flow of selected modules and coordinates the update tags for data consistency. |
| Intel Modules | Service-specific components (e.g., aws, okta) that implement the logic for fetching and preparing data. |
| Graph Schemas | Declarative models that define nodes, properties, and relationships in the graph. |
| Neo4j Database | The underlying storage layer where infrastructure assets are represented as nodes and edges. |
Sources: cartography/cli.py:330-345, AGENTS.md:18-35, README.md:1-10
Intel Module Sync Pattern
Every intel module follows a standard synchronous execution pattern to ensure data integrity and facilitate cleanup.
The sequence diagram illustrates the standard lifecycle of an ingestion task within a module.
Execution Phases
- Get: Fetches raw data from the external provider's API. This phase must be decorated with
@timeit. - Transform: (Optional) Normalizes or shapes the raw API output into a list of dictionaries suitable for the data model.
- Load: Uses the declarative
CartographyNodeSchemaandCartographyRelSchemato ingest data into Neo4j. - Cleanup: Executes a
GraphJobto delete nodes and relationships that were not updated in the current sync (identified by a differentupdate_tag). - Analysis: Runs post-ingestion Cypher queries to create enrichment relationships, such as mapping humans to user accounts.
Sources: AGENTS.md:79-105, cubic.yaml:104-108, CONTRIBUTING.md:120-125
Data Modeling
Cartography uses a declarative approach for defining the graph schema. Each entity is defined by a CartographyNodeSchema and its associated relationships by CartographyRelSchema.
Node Requirements
Every node schema must include specific mandatory properties:
- id: A unique identifier for the resource.
- lastupdated: A timestamp (Unix epoch or ISO 8601) used for tracking the most recent sync.
Relationship Direction
Relationships are defined with a specific direction:
- OUTWARD:
(:Source)-[:REL]->(:Target) - INWARD:
(:Source)<-[:REL]-(:Target)
Example: Notion Page Model
The Notion module defines a page node and its relationship to its creator.
@dataclass(frozen=True)
class NotionPageNodeProperties(CartographyNodeProperties):
id: PropertyRef = PropertyRef("id")
lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
title: PropertyRef = PropertyRef("title")
url: PropertyRef = PropertyRef("url")
@dataclass(frozen=True)
class NotionPageSchema(CartographyNodeSchema):
label: str = "NotionPage"
properties: NotionPageNodeProperties = NotionPageNodeProperties()
# Relationships are defined here
Sources: cubic.yaml:26-34, cartography/models/notion/page.py:15-104, AGENTS.md:154-162
Command Line Interface (CLI)
The cartography command-line tool provides a unified entry point for all synchronization tasks. Options are organized into specific panels for readability.
| Panel | Primary Purpose |
|---|---|
| Core Options | Debugging (-d), quiet mode, selecting modules, and update tags. |
| Neo4j Connection | URI, credentials, and connection pool settings (e.g., --neo4j-uri). |
| Service Options | Specific credentials and filters for AWS, Azure, GCP, Okta, GitHub, etc. |
| Analysis Options | Paths to custom analysis job directories to run at the end of a sync. |
Module Selection
You use the --selected-modules flag to limit sync to specific providers. If omitted, Cartography attempts to run all available modules. It is recommended to run create-indexes first and analysis last.
Sources: cartography/cli.py:46-135, cartography/cli.py:382-396, README.md:46-52
Development and Testing
The project requires Python 3.13 and uses uv for dependency management. Docker is required for running integration tests against a real Neo4j container.
Test Layering
- Unit Tests: Prove pure transforms, normalization, and small helper behaviors without a database.
- Integration Tests: Prove behavior depending on Neo4j writes, relationship creation, and cleanup. These should exercise the complete
sync()path when practical. - Assertions: Use
check_nodes()andcheck_rels()helpers to verify graph state.
Sources: CONTRIBUTING.md:45-56, tests/AGENTS.md:8-25, tests/AGENTS.md:38-45
Conclusion
Cartography serves as a central hub for infrastructure visibility by transforming disparate API data into a unified graph. Its standardized sync pattern and declarative data model ensure that new integrations remain consistent and manageable, while the Neo4j backend enables complex security analysis through Cypher queries. The project emphasizes focused changes, mandatory cleanup, and real-environment testing to maintain data accuracy.
Sources: README.md:1-15, CONTRIBUTING.md:120-135