|
| 1 | +# Architecture |
| 2 | + |
| 3 | +## Project structure |
| 4 | + |
| 5 | +``` |
| 6 | +bbscope/ |
| 7 | +├── cmd/ # CLI commands (Cobra) |
| 8 | +│ ├── root.go # Root command, global flags |
| 9 | +│ ├── poll.go # bbscope poll |
| 10 | +│ ├── poll_*.go # Platform-specific poll subcommands |
| 11 | +│ ├── db.go # bbscope db |
| 12 | +│ ├── db_*.go # DB subcommands (stats, changes, find, etc.) |
| 13 | +│ ├── serve.go # bbscope serve |
| 14 | +│ └── dev.go # bbscope dev |
| 15 | +├── pkg/ # Library packages (importable) |
| 16 | +│ ├── platforms/ # Platform interface + implementations |
| 17 | +│ │ ├── platform.go # PlatformPoller interface |
| 18 | +│ │ ├── hackerone/ |
| 19 | +│ │ ├── bugcrowd/ |
| 20 | +│ │ ├── intigriti/ |
| 21 | +│ │ ├── yeswehack/ |
| 22 | +│ │ ├── immunefi/ |
| 23 | +│ │ └── dev/ |
| 24 | +│ ├── polling/ # Shared polling orchestrator |
| 25 | +│ │ └── polling.go |
| 26 | +│ ├── storage/ # PostgreSQL persistence |
| 27 | +│ │ ├── storage.go # DB operations |
| 28 | +│ │ ├── types.go # Entry, Change, UpsertEntry, etc. |
| 29 | +│ │ ├── normalize.go # Target normalization |
| 30 | +│ │ ├── transform.go # Aggressive transforms |
| 31 | +│ │ └── extra.go # Additional queries |
| 32 | +│ ├── scope/ # Core types and category normalization |
| 33 | +│ ├── targets/ # Target extraction (wildcards, domains, etc.) |
| 34 | +│ ├── ai/ # AI normalization |
| 35 | +│ ├── whttp/ # HTTP client wrapper (retryablehttp) |
| 36 | +│ └── otp/ # TOTP generation |
| 37 | +├── website/ # Web server |
| 38 | +│ ├── pkg/core/ # Server core (routes, handlers, poller) |
| 39 | +│ ├── static/ # CSS, JS, images |
| 40 | +│ ├── docker-compose.yml |
| 41 | +│ └── Dockerfile |
| 42 | +├── internal/ |
| 43 | +│ └── utils/ # Logging setup |
| 44 | +└── docs/ # This documentation (mdBook) |
| 45 | +``` |
| 46 | + |
| 47 | +## Data flow |
| 48 | + |
| 49 | +### CLI polling (`bbscope poll --db`) |
| 50 | + |
| 51 | +``` |
| 52 | +Platform API |
| 53 | + ↓ ListProgramHandles() |
| 54 | + ↓ FetchProgramScope() × N (concurrent workers) |
| 55 | + ↓ |
| 56 | +pkg/polling.PollPlatform() |
| 57 | + ↓ AI normalize (optional, with DB cache) |
| 58 | + ↓ BuildEntries() |
| 59 | + ↓ UpsertProgramEntries() → changes |
| 60 | + ↓ LogChanges() |
| 61 | + ↓ OnProgramDone callback → printChanges() |
| 62 | + ↓ |
| 63 | + ↓ SyncPlatformPrograms() → removed program changes |
| 64 | + ↓ |
| 65 | +stdout (change output) |
| 66 | +``` |
| 67 | + |
| 68 | +### Web server (`bbscope serve`) |
| 69 | + |
| 70 | +``` |
| 71 | +Background goroutine (every N hours) |
| 72 | + ↓ buildPollers() from env vars |
| 73 | + ↓ For each platform (concurrent): |
| 74 | + │ polling.PollPlatform() |
| 75 | + ↓ invalidateProgramsCache() |
| 76 | +
|
| 77 | +HTTP requests |
| 78 | + ↓ /api/v1/* → query DB → JSON response (cached) |
| 79 | + ↓ /programs, /program/* → query DB → HTML (gomponents) |
| 80 | +``` |
| 81 | + |
| 82 | +## Key design decisions |
| 83 | + |
| 84 | +- **Platform interface**: All platforms implement `PlatformPoller`. Adding a new platform means implementing 4 methods. |
| 85 | +- **Shared orchestrator**: `pkg/polling` contains the polling logic used by both CLI and web server, avoiding duplication. |
| 86 | +- **Change detection in DB**: `UpsertProgramEntries` does an atomic compare-and-update, returning only what changed. |
| 87 | +- **Safety checks**: Multiple layers prevent accidental data loss (scope wipe detection, platform-level 0-program check). |
| 88 | +- **AI caching**: Normalized targets are stored in `targets_ai_enhanced` so only new/changed targets hit the API. |
| 89 | +- **Category unification**: Platform-specific category names are mapped to a unified set in `pkg/scope`. |
0 commit comments