eden/mononoke/docs/1.4-navigating-the-codebase.md
This guide helps developers find their way around Mononoke's approximately 55-60 top-level directories. Rather than providing an exhaustive catalog, this document teaches the organizational principles and patterns that make the codebase navigable.
Mononoke's codebase is organized around two key architectural concepts explained in the Architecture Overview:
This document focuses on the code architecture and directory organization. The library code is organized into architectural layers, with each layer building on the ones below it. Understanding this layered structure is key to knowing where to find (or add) functionality:
Servers & Tools (Entry points for users and operators)
↓
API Layer (High-level source control abstractions)
↓
Features Layer (Source control operations)
↓
Repo Attributes Layer (Repository facets and capabilities)
↓
Base Components Layer (Fundamental building blocks)
This layering principle guides the directory organization. Lower layers know nothing about higher layers - for example, base components know nothing about repositories, and repository attributes don't implement complete features.
Almost all components follow a two-level structure:
blobstore/, repo_attributes/)Each component directory typically contains:
src/ - Rust source filesBUCK - Build definitionsCargo.toml for OSS buildsRust uses a flat namespace for crate names, so Mononoke components use descriptive names to avoid collisions. For example, the fsnodes component is named fsnodes_derivation rather than just fsnodes, and SQL storage implementations often use database-related prefixes (e.g., dbbookmarks, sql_commit_graph_storage).
All BUCK files start with oncall("scm_server_infra") to designate ownership. This is standard across the entire codebase.
The lowest layer provides fundamental building blocks that know nothing about repositories or source control concepts.
common/ - Shared utilities and libraries
futures_watchdog, async_limiterscuba_ext, logger_extdedupmap, uniqueheaptime_measuring, reloadertopo_sortblobstore/ - Immutable key-value storage
fileblob/, memblob/, sqlblob/, s3blob/cacheblob/multiplexedblob/, multiplexedblob_wal/packblob/ (see its README.md for details)redactedblobstore/, throttledblob/, prefixblob/chaosblob/, delayblob/ephemeral_blobstore/mononoke_types/ - Core data type definitions
mononoke_types/docs/ for detailed type documentationcmdlib/ - Command-line application framework
mononoke_app/ - Standard framework for new binaries (use this!)base_app/ - Base application primitivesconfig_args/, commit_id/, sharding/environment/, logging/, log/caching/, scrubbing/, cross_repo/These directories provide the foundation but contain no repository-specific logic.
The repo_attributes/ directory contains all the facets that compose a repository. Each subdirectory implements one aspect of repository functionality.
Finding facets: All repository attributes live in repo_attributes/. If you need to understand or modify a specific repository capability, start here.
Key facet categories:
Identity and Configuration
repo_identity/ - Repository name and IDrepo_bookmark_attrs/ - Bookmark configuration attributesStorage Access
repo_blobstore/ - Repository-specific blobstore accessfilestore/ - File content storage and retrievalmutable_blobstore/ - Mutable blob operationsCommit Graph and History
commit_graph/ - Contains commit_graph/ for reading and sql_commit_graph_storage/ for storagephases/ - Commit phase tracking (public, draft, etc.)Derived Data
repo_derived_data/ - Per-repository derived data managementrepo_derivation_queues/ - Derivation work queuesVCS Mappings
bonsai_hg_mapping/ - Bonsai ↔ Mercurial changeset mappingbonsai_git_mapping/ - Bonsai ↔ Git commit mappingbonsai_globalrev_mapping/ - Bonsai ↔ GlobalRev mappingbonsai_svnrev_mapping/ - Bonsai ↔ SVN revision mappingbonsai_tag_mapping/ - Tag object mappingsbonsai_blob_mapping/ - Blob content mappingsBookmarks (Branches)
bookmarks/ - Contains bookmarks/ for bookmark access and dbbookmarks/ for storageGit-Specific Attributes
git_ref_content_mapping/ - Git reference to content mappingsgit_source_of_truth/ - Tracks Git source of truthgit_symbolic_refs/ - Git symbolic reference handlingOperations and Metadata
hook_manager/ - Hook execution managementpushrebase_mutation_mapping/ - Pushrebase mutation trackingdeletion_log/ - Deleted commit trackingmutable_counters/ - Repository countersmutable_renames/ - File rename trackingrepo_cross_repo/ - Cross-repository sync attributesrepo_lock/ - Repository lockingrepo_permission_checker/ - Permission checkingrepo_sparse_profiles/ - Sparse profile managementrestricted_paths/ - Path access restrictionssql_query_config/ - SQL query configurationrepo_metadata_checkpoint/ - Metadata checkpointingrepo_event_publisher/ - Event publishingLegacy Filenode Storage
filenodes/ - Legacy filenode interfacenewfilenodes/ - Newer filenode implementationPattern for using facets: Features and higher layers access repository capabilities through facet traits. Look at the dependencies in a feature's BUCK file to see which facets it uses.
The features/ directory contains source control operations implemented by combining repository facets. Features are stateless - they operate on facets but don't hold repository state themselves.
Current features in features/:
async_requests/ - Asynchronous request handlingcache_warmup/ - Repository cache preloadingchangesets_creation/ - Changeset creation operationscommit_cloud/ - Commit cloud synchronizationcommit_rewriting/ - Commit transformation and rewritingcommit_transformation/ - Commit rewriting and transformationcross_repo_sync/ - Cross-repository synchronizationdiff/ - Diff computationhistory_traversal/ - History walking and traversalhooks/ - Pre-commit and other hooksmicrowave/ - Fast cache warmingpushrebase/ - Server-side rebasingredaction/ - Content redactionrepo_metadata/ - Repository metadata operationsrepo_stats_logger/ - Repository statistics loggingrepo_update_logger/ - Repository update loggingOther feature locations: Some feature-related functionality is in other locations:
bookmarks/bookmarks_movement/ - Bookmark updates (within repo_attributes)The features layer is being gradually populated as code is refactored.
The derived_data/ directory contains the derived data framework and all derived data type implementations.
Framework Components
manager/ - Derived data manager and coordinationremote/ - Remote derivation servicebulk_derivation/ - Batch derivationconstants/ - Shared constantstest_utils/ - Testing utilitiesDerived Data Types (partial list - there are ~22 total)
fsnodes/, unodes/, skeleton_manifest/, skeleton_manifest_v2/, basename_suffix_skeleton_manifest_v3/, deleted_manifest/, case_conflict_skeleton_manifest/, content_manifest_derivation/filenodes_derivation/, blame/, fastlog/mercurial_derivation/changeset_info/, inferred_copy_from/test_manifest/, test_sharded_manifest/Finding derived data types: All implementations are subdirectories of derived_data/. Each type has its own directory with source and BUCK file.
The mononoke_api/ directory provides high-level abstractions over Mononoke's internal data structures:
There's also mononoke_api_hg/ for Mercurial-specific API extensions.
Note: The API layer is intended to be the primary interface for servers and tools, though many components still access lower layers directly for historical reasons.
These directories contain the application binaries that use the library layers described above. As explained in the Architecture Overview, Mononoke is deployed as a collection of services (frontend servers and microservices) plus tools and background jobs. Each application uses the same layered library code.
Servers are organized under the servers/ directory, grouped by protocol. Each protocol has its own subdirectory:
Frontend Servers (serve external clients)
servers/slapi/slapi_server/ - Main Mononoke server (SLAPI for Sapling and EdenFS clients)
repo_listener/, context/, qps/ subdirectoriesBUCK filescs/ - Source Control Service (Thrift API for programmatic access)
scs_server/ for the server and if/ for Thrift definitionsservers/git/git_server/ - Git protocol server (HTTP-based)servers/lfs/lfs_server/ - Git LFS protocol serverMicroservices (handle expensive operations)
servers/land_service/ - Landing (merge) servicederived_data/remote/ - Remote derivation service (within derived_data)Protocol Handlers (libraries used by servers)
servers/slapi/wireproto_handler/ - Mercurial wire protocol handlingservers/slapi/slapi_service/ - SLAPI service implementationservers/sshrelay/ - SSH relay serverhgproto/ - Mercurial protocol definitionsThe jobs/ directory contains long-running background jobs for maintenance and async operations:
walker/ - Graph traversal, validation, scrubbing (see walker/src/README.md)blobstore_healer/ - Storage durability and repaircas_sync/ - Content-addressed storage synchronizationmodern_sync/ - Modern sync jobstatistics_collector/ - Repository statistics collectionJobs are distinct from servers (which handle client requests) and tools (which are run on-demand).
The tools/ directory contains command-line utilities for operators and developers:
Administrative Tools
admin/ - Main admin CLI (primary operational tool)testtool/ - Testing and debugging utilityImport/Export
blobimport/ - Import Mercurial repositoriesimport/ - Import utilitiesrepo_import/ - Repository import toolVerification
aliasverify/ - Verify content-addressed aliasesbonsai_verify/ - Bonsai changeset verificationcheck_git_wc/ - Git working copy verificationMaintenance
packer/ - Packblob utilitiessqlblob_gc/ - SQL blobstore garbage collectionbackfill_mapping/ - Backfill mapping tablesOther
streaming_clone/ - Streaming clone generationexecutor/ - Task executorexample/ - Example tooltail-to-cloudwatch/ - CloudWatch log tailingThe admin/ tool is the primary interface for most operational tasks. Other tools are more specialized.
The clients/ directory contains client tools and libraries for interacting with Mononoke servers:
clients/scsc/ - Source Control Service CLI client (scsc command-line tool)clients/git_pushrebase/ - Git pushrebase client utilitiesclients/facebook/ - Facebook-internal client implementationsThese client tools provide command-line and programmatic interfaces to Mononoke's various services.
Git Support - git/ directory
git_types/ - Git-specific type definitionsprotocol/, packfile/, packetline/ - Git protocol implementationgitimport/, gitexport/ - Import and exportimport_direct/, import_tools/ - Import utilitiesgit_env/ - Git environment setupbundle_uri/ - Bundle URI supportgit-pool/ - Git object poolingcheck_git_wc/ - Working copy checkingMercurial Support - mercurial/ directory
LFS Support
lfs_protocol/ - LFS protocol definitionsservers/lfs/lfs_server/ - LFS server implementationlfs_import_lib/ - LFS import utilitiesmetaconfig/ - Repository metadata configuration (legacy name, should be config/)mononoke_configs/ - Global configuration systemmononoke_macros/ - Rust procedural macrosIntegration Tests - tests/integration/
.t test files (Mercurial-style test format)tests/fixtures/library.sh, library-commit.sh, library-git-lfs.sh, etc.dott_test targets for each test suitetests/integration/README.md for comprehensive documentationTest Utilities - tests/utils/
Unit Tests: Embedded in each component's src/ directory (standard Rust practice)
Operations
observability/ - Observability infrastructurerate_limiting/ - Rate limiting implementationspermission_checker/ - Permission checking (base component)repo_authorization/ - Repository authorizationAdditional Components
blobrepo/, blobrepo_utils/ - Legacy repository abstraction (being phased out in favor of facets)repo_factory/ - Repository creation and initializationmanifest/ - Manifest handling utilitiesmegarepo_api/ - Megarepo (monorepo) operationsacl_regions/ - ACL region managementcas_client/ - Content-addressed storage clientcats/ - Configuration as a Service integrationrepo_client/ - Repository client implementationgotham_ext/ - Gotham web framework extensionsquiet_stream/ - Stream utilitiestime_window_counter/ - Time-windowed countersadaptive_rate_limiter/ - Adaptive rate limitingbenchmarks/ - Performance benchmarksthird_party/ - Third-party codeFacebook-Internal: facebook/ contains Facebook-specific implementations mirroring the main hierarchy.
OSS Builds: public_autocargo/ contains auto-generated Cargo.toml files for open-source builds.
repo_attributes/repo_identity, bookmarks, commit_graph)sql_* subdirectory within the facetExample: To find bookmark implementation:
repo_attributes/bookmarks/src/dbbookmarks within the bookmarks directoryderived_data/derived_data/manager/ and derived_data/remote/Example: To find fsnodes derivation:
derived_data/fsnodes/derived_data/manager/ for registrationUnit tests: Look in the component's source directory
src/ filestest/ directoriesIntegration tests: Look in tests/integration/
.t extensiontest-pushrebase.t, test-gitimport.t)dott_test targetsExample: To find pushrebase tests:
features/pushrebase/src/ may contain #[test] functionstests/integration/test-pushrebase*.tServers are organized under the servers/ directory by protocol:
servers/slapi/slapi_server/, servers/slapi/slapi_service/servers/git/git_server/servers/lfs/lfs_server/scs/scs_server/ (not yet migrated to servers/)Blobstore backends: All in blobstore/ with descriptive names
blobstore/fileblob/blobstore/sqlblob/blobstore/s3blob/blobstore/memblob/Metadata storage: Look for sql_* subdirectories within facets
repo_attributes/bookmarks/ arearepo_attributes/commit_graph/sql_commit_graph_storage/repo_attributes/phases/BUCK files follow consistent patterns:
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")
oncall("scm_server_infra")
rust_library(
name = "component_name",
srcs = glob(["src/**/*.rs"]),
autocargo = {"cargo_toml_dir": "component_name"}, # For OSS
deps = [
# Dependencies listed here
],
)
Key patterns:
oncall("scm_server_infra") appears in every fileautocargo metadata enables OSS buildsglob(["src/**/*.rs"]) is standard for sources"//eden/mononoke/mononoke_types:mononoke_types")"fbsource//third-party/rust:crate_name"Finding dependencies: Look at the deps field in a component's BUCK file to see what it uses.
Integration tests: Use dott_test targets that reference test files and their binary dependencies.
repo_attributes/features/, then top-level directoriesblobstore/derived_data/jobs/ directorytools/ directory (especially tools/admin/)git/ or mercurial/ directoriescommon/ directorytests/integration/ for integration, src/ for unit testsmetaconfig/ or mononoke_configs/repo_attributes/bookmarks/repo_attributes/bookmarks/bookmarks_movement/repo_attributes/bookmarks/bookmarks_cache/, repo_attributes/bookmarks/warm_bookmarks_cache/servers/slapi/, servers/git/, scs/, etc.servers/slapi/slapi_service/, servers/slapi/wireproto_handler/, etc.tests/integration/derived_data/derived_data/fsnodes/) as examplesderived_data/manager/blobstore/ + check decorators like cacheblob/, multiplexedblob/repo_attributes/ and its SQL implementationwalker/ for validation toolsjobs/blobstore_healer/ for healing logicgit/protocol/, git/packfile/, git/packetline/hgproto/, servers/slapi/wireproto_handler/servers/slapi/slapi_service/lfs_protocol/, servers/lfs/lfs_server/scs/if/source_control.thrift for interface definitiondocs/ (this document and architecture docs)walker/src/README.md, blobstore/packblob/README.md)mononoke_types/docs/tests/integration/README.mdMononoke's directory structure follows consistent principles:
When navigating the codebase:
The codebase is large, but its organization is systematic. Understanding the layers and patterns makes it navigable.