How disqus/gutter works
Project type and purpose
• This is an open-source Python library (“Gutter”) for feature‐switch management (client for “Gargoyle 2”).
• It provides APIs to define switches, configure storage and autocreation, evaluate switch activation against inputs, hook signals, decorate Django views, and ship testing utilities.
File structure
• Top-level files: setup.py/Gemfile/Makefile and config files (.travis.yml, .arcconfig).
• arguments/: Container base and built-in argument types (Value, Boolean, String).
• operators/: Operator implementations (comparable, identity, string, misc).
• models.py: definitions of Manager, Switch, Condition.
• registry.py: switch registration logic.
• signals.py: Observer hooks (switch_registered, switch_updated, etc.).
• testutils.py: context-manager and decorator for deterministic testing.
• tests/: unit and integration tests covering arguments, operators, registry, signals, testutils.
Review the README for architecture insights
• Core concepts: Manager ↔ StorageEngine (default MemoryDict or pluggable RedisDict), Switch with Conditions, Arguments → Variables → Operators, Namespaces, Decorators, Signals, Testing utilities.
• Extension points: custom storage backends, custom Argument containers, new Operators, signal subscribers, namespaced managers.
a. Main components
• Manager (default & namespaced)
• StorageEngine (MemoryDict, RedisDict)
• Switch (states, hierarchy, concent flag)
• Condition (argument class, attribute, operator, negative flag)
• ArgumentContainer and Variable classes
• Operator implementations
• Registry module (register/update/unregister)
• Signals (switch_registered, switch_updated, switch_unregistered, condition_apply_error)
• Decorator (switch_active)
• TestingUtilities (switches context/decorator)
• External UIs (e.g. gutter-django) and external storage services (Redis)
b. Relationships & data flows
1. Configuration: application code sets storage_engine and autocreate flags via settings.manager.
2. Manager uses StorageEngine to persist/retrieve Switch objects.
3. Application defines ArgumentContainer subclasses; Manager stores them in its registry.
4. To evaluate gutter.active("feature", inputs…):
– Manager fetches Switch from storage
– For each Condition in Switch, it:
• Matches input object → picks appropriate ArgumentContainer
• Calls Argument method → yields Variable
• Applies Operator to Variable → Boolean result
– Applies compounded/concent logic → final decision
5. Manager returns active/inactive; may fire condition_apply_error if exceptions occur.
6. Manager fires switch_registered/switch_updated/switch_unregistered signals on mutations.
7. @switch_active decorator wraps Django views, invoking gutter.active, raising 404 or redirecting.
8. testutils.switches stubs Manager behavior during tests.
c. Architectural patterns & design principles
– Modular components with single responsibility (Manager vs Storage vs Switch vs Argument vs Operator).
– Strategy pattern for Operators and StorageEngines.
– Observer pattern for Signals.
– Decorator pattern for view protection.
– Extensibility: plug in new storage, arguments, operators, signal handlers.
– Separation of concerns: no business logic clutter, translation layer via Arguments.
d. Key technologies, frameworks, libraries
– Python packaging: setup.py, pytest/unittest
– durabledict’s MemoryDict, RedisDict (optional)
– Redis (via redis-py) for persistence
– Django (integration via gutter-django and decorators)
Capturing essential architectural elements
• Lay out the gutter/client/ package as the central hub.
• Surround it with the external environment: application code, storage backends, UI, tests.
• Extension points so the engineer sees where to add custom storage, arguments, or operators.
• Every component that appears in the file tree (arguments, operators, models, registry, signals, testutils) is represented.