CannaiQ Backend Codebase Map
Last Updated: 2025-12-12
Purpose: Help Claude and developers understand which code is current vs deprecated
Quick Reference: What to Use
For Crawling/Scraping
| Task |
Use This |
NOT This |
| Fetch products |
src/tasks/handlers/payload-fetch.ts |
src/hydration/* |
| Process products |
src/tasks/handlers/product-refresh.ts |
src/scraper-v2/* |
| GraphQL client |
src/platforms/dutchie/client.ts |
src/dutchie-az/services/graphql-client.ts |
| Worker system |
src/tasks/task-worker.ts |
src/dutchie-az/services/worker.ts |
For Database
| Task |
Use This |
NOT This |
| Get DB pool |
src/db/pool.ts |
src/dutchie-az/db/connection.ts |
| Run migrations |
src/db/migrate.ts (CLI only) |
Never import at runtime |
| Query products |
store_products table |
products, dutchie_products |
| Query stores |
dispensaries table |
stores table |
For Discovery
| Task |
Use This |
| Discover stores |
src/discovery/*.ts |
| Run discovery |
npx tsx src/scripts/run-discovery.ts |
Directory Status
ACTIVE DIRECTORIES (Use These)
DEPRECATED DIRECTORIES (DO NOT USE)
DEPRECATED FILES (DO NOT USE)
Key Files Reference
Entry Points
| File |
Purpose |
Status |
src/index.ts |
Main Express server |
ACTIVE |
src/dutchie-az/services/worker.ts |
Worker process entry |
ACTIVE |
src/tasks/task-worker.ts |
Task worker (new system) |
ACTIVE |
Dutchie Integration
| File |
Purpose |
Status |
src/platforms/dutchie/client.ts |
GraphQL client, hashes, curl |
PRIMARY |
src/platforms/dutchie/queries.ts |
High-level query functions |
ACTIVE |
src/platforms/dutchie/index.ts |
Re-exports |
ACTIVE |
Task Handlers
| File |
Purpose |
Status |
src/tasks/handlers/payload-fetch.ts |
Fetch products from Dutchie |
PRIMARY |
src/tasks/handlers/product-refresh.ts |
Process payload into DB |
PRIMARY |
src/tasks/handlers/menu-detection.ts |
Detect menu type |
ACTIVE |
src/tasks/handlers/id-resolution.ts |
Resolve platform IDs |
ACTIVE |
src/tasks/handlers/image-download.ts |
Download product images |
ACTIVE |
Database
| File |
Purpose |
Status |
src/db/pool.ts |
Canonical DB pool |
PRIMARY |
src/db/migrate.ts |
Migration runner (CLI only) |
CLI ONLY |
src/db/auto-migrate.ts |
Auto-run migrations on startup |
ACTIVE |
Configuration
| File |
Purpose |
Status |
.env |
Environment variables |
ACTIVE |
package.json |
Dependencies |
ACTIVE |
tsconfig.json |
TypeScript config |
ACTIVE |
GraphQL Hashes (CRITICAL)
The correct hashes are in src/platforms/dutchie/client.ts:
ALWAYS use Status: 'Active' for FilteredProducts (not null or 'All').
Scripts Reference
Useful Scripts (in src/scripts/)
| Script |
Purpose |
run-discovery.ts |
Run Dutchie discovery |
crawl-single-store.ts |
Test crawl a single store |
test-dutchie-graphql.ts |
Test GraphQL queries |
One-Off Scripts (probably don't need)
| Script |
Purpose |
harmonize-az-dispensaries.ts |
One-time data cleanup |
bootstrap-stores-for-dispensaries.ts |
One-time migration |
backfill-*.ts |
Historical backfill scripts |
API Routes
Active Routes (in src/routes/)
| Route File |
Mount Point |
Purpose |
auth.ts |
/api/auth |
Login/logout/session |
stores.ts |
/api/stores |
Store CRUD |
dashboard.ts |
/api/dashboard |
Dashboard stats |
workers.ts |
/api/workers |
Worker monitoring |
pipeline.ts |
/api/pipeline |
Crawl triggers |
discovery.ts |
/api/discovery |
Discovery management |
analytics.ts |
/api/analytics |
Analytics queries |
wordpress.ts |
/api/v1/wordpress |
WordPress plugin API |
Documentation Files
Current Docs (in backend/docs/)
| Doc |
Purpose |
Currency |
TASK_WORKFLOW_2024-12-10.md |
Task system architecture |
CURRENT |
WORKER_TASK_ARCHITECTURE.md |
Worker/task design |
CURRENT |
CRAWL_PIPELINE.md |
Crawl pipeline overview |
CURRENT |
ORGANIC_SCRAPING_GUIDE.md |
Browser-based scraping |
CURRENT |
CODEBASE_MAP.md |
This file |
CURRENT |
ANALYTICS_V2_EXAMPLES.md |
Analytics API examples |
CURRENT |
BRAND_INTELLIGENCE_API.md |
Brand API docs |
CURRENT |
Root Docs
| Doc |
Purpose |
Currency |
CLAUDE.md |
Claude instructions |
PRIMARY |
README.md |
Project overview |
NEEDS UPDATE |
Common Mistakes to Avoid
-
Don't use src/hydration/ - It's an old approach that was superseded by the task system
-
Don't use src/dutchie-az/db/connection.ts - Use src/db/pool.ts instead
-
Don't import src/db/migrate.ts at runtime - It will crash. Only use for CLI migrations.
-
Don't query stores table - It's empty. Use dispensaries.
-
Don't query products table - It's empty. Use store_products.
-
Don't use wrong GraphQL hash - Always get hash from GRAPHQL_HASHES in client.ts
-
Don't use Status: null - It returns 0 products. Use Status: 'Active'.
When in Doubt
- Check if the file is imported in
src/index.ts - if not, it may be deprecated
- Check the last modified date - older files may be stale
- Look for
DEPRECATED comments in the code
- Ask: "Is there a newer version of this in
src/tasks/ or src/platforms/?"
- Read the relevant doc in
docs/ before modifying code