Skip to content

refactor: simplify feature flags to lib/server/cli#110

Merged
digizeph merged 10 commits intomainfrom
database-cli-consistency
Feb 10, 2026
Merged

refactor: simplify feature flags to lib/server/cli#110
digizeph merged 10 commits intomainfrom
database-cli-consistency

Conversation

@digizeph
Copy link
Member

Summary

This PR simplifies the feature flag system from 6 complex tiers to 3 clear options:

Before (6 tiers)

  • databaselens-corelens-bgpkitlens-full + displaycli

After (3 tiers)

  • lib - Complete library (database + all lenses + display)
  • server - WebSocket server (implies lib)
  • cli - Full CLI binary (implies lib and server)

Changes

Feature Flag Refactoring

  • Simplified to 3 mutually-understandable features
  • display (tabled) now always included with lib
  • Clear dependency chain: cli → server → lib

Examples Reorganization

  • Flat structure: one example per lens (time_lens.rs, rpki_lens.rs, etc.)
  • Removed verbose multi-example files
  • All examples use lib or server features

Database API Standardization

  • Consistent RefreshResult struct for all data sources
  • Unified needs_*_refresh(ttl) pattern
  • Both URL and path loading methods for all repositories
  • Renamed methods: bootstrap_asinfo()refresh_asinfo(), update_as2rel()refresh_as2rel()

Configurable Cache TTLs

  • 7-day default for all data sources
  • Configurable via ~/.monocle/monocle.toml or environment variables
  • Consistent TTL handling across ASInfo, AS2Rel, RPKI, and Pfx2as

Breaking Changes

  • Feature flags: old 6-tier system replaced with 3-tier
  • CLI flag: --no-refresh renamed to --no-update
  • Config subcommands: removed db- prefix (db-refreshupdate)
  • Database methods: standardized naming (old methods have deprecated aliases)

Testing

All tests pass with new feature flags:

  • cargo build --all-features
  • cargo test --all-features
  • cargo clippy --all-features -- -D warnings

BREAKING CHANGE: Replace 6-tier feature system with 3 simple features:
- lib: Complete library (database + all lenses + display)
- server: WebSocket server (implies lib)
- cli: Full CLI binary (implies lib and server)

Changes:
- Remove database, lens-core, lens-bgpkit, lens-full, display features
- Move country.rs to country/mod.rs for consistency
- Remove all #[cfg(feature = display)] gates (now always included)
- Update all documentation (ARCHITECTURE.md, AGENTS.md, lens/README.md, examples/README.md)
- Update example feature requirements in Cargo.toml

All tests pass, clippy clean.
Add clear 'need X? use Y' guidance to documentation:
- ARCHITECTURE.md: Quick guide at top of feature section
- src/lens/mod.rs: Quick guide in module documentation
- examples/README.md: Quick guide in feature tiers section
- CHANGELOG.md: Document feature flag simplification as breaking change

All examples use 'lib' feature, making it simple for users to understand.
Simplify all examples to be more concise and practical:

**Standalone:**
- time_parsing.rs: Reduced from 9 examples to 1 focused example
- output_formats.rs: Reduced from 8 examples to essential formats only

**Database:**
- Merged database_basics.rs, as2rel_queries.rs, pfx2as_search.rs into single database.rs
- Focus on practical database operations

**BGPKIT:**
- country_lookup.rs: Reduced from 13 examples to 2 focused examples
- rpki_validation.rs: Reduced from 12 examples to practical validation use cases
- mrt_parsing.rs: Reduced from 8 examples to focused parsing demo
- search_bgp_messages.rs: Simplified to core search functionality

**Full:**
- inspect_unified.rs → inspect.rs: Simplified to core inspection features
- Removed progress_callbacks.rs (too verbose)

**Documentation:**
- Updated examples/README.md with cleaner organization
- Updated Cargo.toml with new example list

All examples now use  feature exclusively.
All tests pass, clippy clean.
Restructure examples directory to have one example per lens:

**New structure (flat, with _lens suffix):**
- time_lens.rs - TimeLens
- country_lens.rs - CountryLens
- ip_lens.rs - IpLens (NEW)
- parse_lens.rs - ParseLens
- search_lens.rs - SearchLens
- rpki_lens.rs - RpkiLens
- pfx2as_lens.rs - Pfx2asLens (NEW)
- as2rel_lens.rs - As2relLens (NEW)
- inspect_lens.rs - InspectLens
- database.rs - Database operations
- ws_client_all.rs - WebSocket client

**Changes:**
- Removed subdirectories (standalone/, database/, bgpkit/, full/)
- Removed output_formats.rs (redundant)
- Added 3 new lens examples for IpLens, Pfx2asLens, As2relLens
- Updated Cargo.toml with new example names
- Updated examples/README.md with table-based documentation

All examples use lib feature exclusively.
All tests pass, clippy clean.
Standardize the database interface for updating/refreshing data:

**New consistent API:**
- needs_*_refresh(ttl) - Check if data needs refresh (all repositories)
- refresh_*() - Load from default URL
- refresh_*_from(path) - Load from custom path
- RefreshResult - Consistent return type for refresh operations

**Changes:**
- Added RefreshResult struct with records_loaded, source, timestamp, details
- Renamed bootstrap_asinfo() to refresh_asinfo() (with deprecated alias)
- Renamed update_as2rel() to refresh_as2rel() (with deprecated alias)
- Added refresh_asinfo_from() for loading ASInfo from custom path
- Added refresh_rpki() and refresh_pfx2as() methods to MonocleDatabase
- Removed hardcoded should_update() from AS2Rel (use needs_refresh(ttl))
- Removed SEVEN_DAYS_SECS constant from AS2Rel
- Added load_from_path() to ASInfo repository
- Updated all lenses to use new API
- Updated all CLI commands to use new API
- Updated tests to use new API

**Benefits:**
- Consistent naming across all repositories (refresh_* pattern)
- Consistent return type (RefreshResult)
- Configurable TTL for all data sources
- No hardcoded TTL values
- All repositories have both URL and path loading methods

All tests pass, clippy clean.
- Add database API standardization changes to CHANGELOG
- Add examples reorganization changes to CHANGELOG
- Add CHANGELOG update requirement to AGENTS.md guidelines
@digizeph digizeph merged commit 54a44c8 into main Feb 10, 2026
1 check passed
@digizeph digizeph deleted the database-cli-consistency branch February 10, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant