-
Notifications
You must be signed in to change notification settings - Fork 3
[LFX-V2-199] Query Service: org search endpoint implementation #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
766055b
dd8af13
a78bd0c
9ddff86
56e85ac
38ca5a9
f253456
03cc2ad
e13d3b1
1cb2201
e7cecee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ The implementation follows the clean architecture principles where: | |||||||||||||||||||||||||||||||||||||||||||
| β βββ domain/ # Domain logic layer | ||||||||||||||||||||||||||||||||||||||||||||
| β β βββ model/ # Domain models and entities | ||||||||||||||||||||||||||||||||||||||||||||
| β β βββ port/ # Domain interfaces/ports | ||||||||||||||||||||||||||||||||||||||||||||
| β βββ usecase/ # Business logic/use cases layer | ||||||||||||||||||||||||||||||||||||||||||||
| β βββ service/ # Business logic/use cases layer | ||||||||||||||||||||||||||||||||||||||||||||
| β βββ infrastructure/ # Infrastructure layer | ||||||||||||||||||||||||||||||||||||||||||||
| β βββ middleware/ # HTTP middleware components | ||||||||||||||||||||||||||||||||||||||||||||
| βββ pkg/ # Shared packages for internal and external services | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -47,10 +47,10 @@ The implementation follows the clean architecture principles where: | |||||||||||||||||||||||||||||||||||||||||||
| - **ResourceSearcher Interface**: Defines the contract for resource search operations | ||||||||||||||||||||||||||||||||||||||||||||
| - **AccessControlChecker Interface**: Defines the contract for access control operations | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ### Use Case Layer (`internal/usecase/`) | ||||||||||||||||||||||||||||||||||||||||||||
| ### Service Layer (`internal/service/`) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - **Business Logic**: Application-specific business rules and operations | ||||||||||||||||||||||||||||||||||||||||||||
| - **Use Case Orchestration**: Coordinates between domain models and infrastructure | ||||||||||||||||||||||||||||||||||||||||||||
| - **Service Orchestration**: Coordinates between domain models and infrastructure | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ### Infrastructure Layer (`internal/infrastructure/`) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,6 +62,10 @@ The OpenSearch implementation includes query templates, a searcher, and a client | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The NATS implementation consists of a client, access control logic, and request/response models for messaging and access control. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### Clearbit Implementation | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The Clearbit implementation provides organization search capabilities using the Clearbit Company API. It includes a client for API communication, searcher for organization queries, and configuration management for API credentials and settings. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ## Dependency Injection | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Dependency injection is performed in `cmd/main.go`, where the concrete implementations for resource search and access control are selected based on configuration and then injected into the service constructor. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -106,15 +110,21 @@ SEARCH_SOURCE=mock ACCESS_CONTROL_SOURCE=mock go run cmd/main.go | |||||||||||||||||||||||||||||||||||||||||||
| SEARCH_SOURCE=mock ACCESS_CONTROL_SOURCE=mock go run cmd/main.go -p 3000 | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### With OpenSearch and NATS | ||||||||||||||||||||||||||||||||||||||||||||
| #### With Production Services | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||||
| # Using OpenSearch and NATS (production-like setup) | ||||||||||||||||||||||||||||||||||||||||||||
| # production-like setup | ||||||||||||||||||||||||||||||||||||||||||||
| SEARCH_SOURCE=opensearch \ | ||||||||||||||||||||||||||||||||||||||||||||
| ORG_SEARCH_SOURCE=clearbit \ | ||||||||||||||||||||||||||||||||||||||||||||
| ACCESS_CONTROL_SOURCE=nats \ | ||||||||||||||||||||||||||||||||||||||||||||
| OPENSEARCH_URL={{placeholder}} \ | ||||||||||||||||||||||||||||||||||||||||||||
| OPENSEARCH_INDEX=resources \ | ||||||||||||||||||||||||||||||||||||||||||||
| NATS_URL{{placeholder}} \ | ||||||||||||||||||||||||||||||||||||||||||||
| CLEARBIT_CREDENTIAL=your_clearbit_api_key \ | ||||||||||||||||||||||||||||||||||||||||||||
| CLEARBIT_BASE_URL=https://company.clearbit.com \ | ||||||||||||||||||||||||||||||||||||||||||||
| CLEARBIT_TIMEOUT=30s \ | ||||||||||||||||||||||||||||||||||||||||||||
| CLEARBIT_MAX_RETRIES=5 \ | ||||||||||||||||||||||||||||||||||||||||||||
| CLEARBIT_RETRY_DELAY=2s \ | ||||||||||||||||||||||||||||||||||||||||||||
| go run cmd/main.go | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix NATS_URL typo in production example. Missing '=' will break copy/paste. OPENSEARCH_INDEX=resources \
-NATS_URL{{placeholder}} \
+NATS_URL={{placeholder}} \
CLEARBIT_CREDENTIAL=your_clearbit_api_key \
CLEARBIT_BASE_URL=https://company.clearbit.com \
CLEARBIT_TIMEOUT=30s \
CLEARBIT_MAX_RETRIES=5 \
CLEARBIT_RETRY_DELAY=2s \π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -124,6 +134,10 @@ go run cmd/main.go | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - `SEARCH_SOURCE`: Choose between "mock" or "opensearch" (default: "opensearch") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| **Organization Search Implementation:** | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - `ORG_SEARCH_SOURCE`: Choose between "mock" or "clearbit" (default: "clearbit") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| **OpenSearch Configuration:** | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - `OPENSEARCH_URL`: OpenSearch URL (default: `http://localhost:9200`) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -140,6 +154,14 @@ go run cmd/main.go | |||||||||||||||||||||||||||||||||||||||||||
| - `NATS_MAX_RECONNECT`: Maximum reconnection attempts (default: "3") | ||||||||||||||||||||||||||||||||||||||||||||
| - `NATS_RECONNECT_WAIT`: Time between reconnection attempts (default: "2s") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| **Clearbit Configuration:** | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - `CLEARBIT_CREDENTIAL`: Clearbit API key (required for organization search) | ||||||||||||||||||||||||||||||||||||||||||||
| - `CLEARBIT_BASE_URL`: Clearbit API base URL (default: `https://company.clearbit.com`) | ||||||||||||||||||||||||||||||||||||||||||||
| - `CLEARBIT_TIMEOUT`: HTTP client timeout for API requests (default: "10s") | ||||||||||||||||||||||||||||||||||||||||||||
| - `CLEARBIT_MAX_RETRIES`: Maximum number of retry attempts for failed requests (default: "3") | ||||||||||||||||||||||||||||||||||||||||||||
| - `CLEARBIT_RETRY_DELAY`: Delay between retry attempts (default: "1s") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+157
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Verification agent π§© Analysis chainVerify Clearbit default values match code. Ensure docs and internal/infrastructure/clearbit/config.go are consistent for timeout, retries, and delay. π Script executed: #!/bin/bash
# Confirm documented defaults vs. code
rg -nP -C2 '(TIMEOUT|RETRY|DELAY|CREDENTIAL|BASE_URL)' internal/infrastructure/clearbit/config.goLength of output: 0 π Script executed: #!/bin/bash
# Locate Clearbit config file(s)
fd config.go -t f | grep -i clearbit
# Inspect default values in the located file(s)
fd config.go -t f | grep -i clearbit | xargs -r rg -nP -C2 'Default.*|Base_URL|Timeout|Retries|Delay'Length of output: 1305 Update Clearbit timeout default in README. Change π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| **Server Configuration:** | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - `-p`: HTTP port (default: "8080") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -184,6 +206,59 @@ GET /query/resources?name=committee&type=committee&v=1 | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ## Clearbit API Integration | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The service integrates with Clearbit's Company API to provide enriched organization data for search operations. This integration allows the service to fetch detailed company information including industry classification, employee count, and domain information. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ### Clearbit API Setup | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### 1. Obtain API Credentials | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| To use Clearbit integration, you need to obtain an API key from Clearbit: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 1. Sign up for a Clearbit account at [https://clearbit.com](https://clearbit.com) | ||||||||||||||||||||||||||||||||||||||||||||
| 2. Navigate to your API settings to generate an API key | ||||||||||||||||||||||||||||||||||||||||||||
| 3. Copy the API key for use in your environment configuration | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### 2. Configure Environment Variables | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Set the required environment variables for Clearbit integration: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||||
| # Required: Clearbit API key | ||||||||||||||||||||||||||||||||||||||||||||
| export CLEARBIT_CREDENTIAL=your_clearbit_api_key_here | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Optional: Custom configuration (defaults shown) | ||||||||||||||||||||||||||||||||||||||||||||
| export CLEARBIT_BASE_URL=https://company.clearbit.com | ||||||||||||||||||||||||||||||||||||||||||||
| export CLEARBIT_TIMEOUT=30s | ||||||||||||||||||||||||||||||||||||||||||||
| export CLEARBIT_MAX_RETRIES=3 | ||||||||||||||||||||||||||||||||||||||||||||
| export CLEARBIT_RETRY_DELAY=1s | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Set organization search source to use Clearbit | ||||||||||||||||||||||||||||||||||||||||||||
| export ORG_SEARCH_SOURCE=clearbit | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### 3. API Usage and Features | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The Clearbit integration supports the following search operations: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| **Search by Company Name:** | ||||||||||||||||||||||||||||||||||||||||||||
| - Searches for companies using their registered business name | ||||||||||||||||||||||||||||||||||||||||||||
| - Falls back to domain-based search for additional data enrichment | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| **Search by Domain:** | ||||||||||||||||||||||||||||||||||||||||||||
| - More accurate search method using company domain names | ||||||||||||||||||||||||||||||||||||||||||||
| - Provides comprehensive company information | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #### 4. Error Handling | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The Clearbit integration includes robust error handling: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - **404 Not Found**: Returns appropriate "organization not found" errors | ||||||||||||||||||||||||||||||||||||||||||||
| - **Rate Limiting**: Automatic retry with exponential backoff | ||||||||||||||||||||||||||||||||||||||||||||
| - **Network Issues**: Configurable retry attempts with delays | ||||||||||||||||||||||||||||||||||||||||||||
| - **API Errors**: Proper error propagation with context | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+254
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Verification agent π§© Analysis chainConfirm retry strategy; align wording if not exponential backoff. Docs promise βAutomatic retry with exponential backoff.β Verify implementation matches (e.g., backoff algorithm and jitter). If linear or fixed, adjust wording. π Script executed: #!/bin/bash
# Inspect Clearbit client for retry/backoff strategy
rg -nP -C3 '(retry|backoff|exponential|jitter)' internal/infrastructure/clearbit/Length of output: 3119 π Script executed: #!/bin/bash
# Inspect Clearbit client for backoff logic by finding sleep calls
rg -nP -C3 'Sleep' internal/infrastructure/clearbit/Length of output: 0 #!/bin/bash
# Locate and display the Clearbit searcher implementation to inspect retry/backoff logic
fd -e go searcher.go internal/infrastructure/clearbit
sed -n '1,200p' internal/infrastructure/clearbit/searcher.goUpdate documentation to reflect fixed retry delays π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ### Testing | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| The clean architecture makes testing straightforward: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ Verification agent
π§© Analysis chain
Rename to Service layer looks good; verify no lingering "usecase" references.
The directory rename aligns with the refactor. Please confirm there are no stale references to internal/usecase across docs and code.
π Script executed:
Length of output: 0
π Script executed:
Length of output: 363
Update stale βUse caseβ reference in CLAUDE.md
π€ Prompt for AI Agents