{"id":50458126,"url":"https://github.com/ikennarichard/insighta","last_synced_at":"2026-06-01T03:30:34.108Z","repository":{"id":350530152,"uuid":"1207161455","full_name":"ikennarichard/insighta","owner":"ikennarichard","description":"a demographic intelligence platform that stores structured profile data (e.g., age, gender, country) and allows users to query and analyze this data.","archived":false,"fork":false,"pushed_at":"2026-05-16T21:04:48.000Z","size":693,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2026-05-16T23:26:28.157Z","etag":null,"topics":["agify-api","genderize","go"],"latest_commit_sha":null,"homepage":"https://genderize-plum.vercel.app","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikennarichard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-10T16:35:11.000Z","updated_at":"2026-05-16T21:04:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ikennarichard/insighta","commit_stats":null,"previous_names":["ikennarichard/genderize","ikennarichard/insighta"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ikennarichard/insighta","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikennarichard%2Finsighta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikennarichard%2Finsighta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikennarichard%2Finsighta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikennarichard%2Finsighta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikennarichard","download_url":"https://codeload.github.com/ikennarichard/insighta/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikennarichard%2Finsighta/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33759178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agify-api","genderize","go"],"created_at":"2026-06-01T03:30:33.321Z","updated_at":"2026-06-01T03:30:34.102Z","avatar_url":"https://github.com/ikennarichard.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Insighta Lab\n\na demographic intelligence platform that stores structured profile data (e.g., age, gender, country) and allows users to query and analyze this data.\n\n## Features\n\n- **Advanced Filtering:** Multi-condition queries (gender, age ranges, country, probability thresholds).\n- **Intelligent Sorting \u0026 Pagination:** Optimized for large datasets using PostgreSQL window functions.\n- **Natural Language Query (NLQ):** Plain English search interpretation without LLM overhead.\n\n## Natural Language Query (NLQ) Engine\n\nThe engine uses a **Rule-Based Tokenizer** to translate plain English strings into structured database filters. This allows for low-latency, deterministic queries.\n\n### Supported Keywords \u0026 Mapping\n\n| Keyword | Filter Mapping | Logic |\n|---|---|---|\n| `male` / `female` | `gender` | Strict string match (case-insensitive) |\n| `young` | `min_age: 16`, `max_age: 24` | Hardcoded age range |\n| `above {N}` | `min_age: N` | Regex extraction of digits after \"above\" |\n| `from {country}` | `country_id` | Dictionary lookup (e.g., `\"nigeria\"` → `\"NG\"`) |\n| `adult`, `teenager`, etc. | `age_group` | Matches stored classification groups |\n\n### How the Logic Works\n\n1. **Normalization:** The query is lowercased and stripped of special characters.\n2. **Tokenization:** The system scans for specific \"Trigger Keywords\" (e.g., `\"young\"`).\n3. **Regex Extraction:** For dynamic values like `\"above 30\"`, a regular expression `above (\\d+)` identifies the numeric value.\n4. **Filter Aggregation:** All identified intents are merged into a single `ProfileFilters` struct and passed to the PostgreSQL engine.\n\n## Limitations \u0026 Edge Cases\n\nWhile powerful, the current rule-based parser has specific constraints:\n\n### 1. Linguistic Limitations\n\n- **No Negation:** Queries like `\"not from Nigeria\"` or `\"not male\"` are not supported. The parser looks for positive presence of keywords.\n- **Conjunction Ambiguity:** Using `\"and/or\"` (e.g., `\"males and females\"`) will result in the last identified gender overriding the first, as the system currently supports strict single-value filtering per field.\n- **Strict \"Above\" Logic:** We currently only support `\"above\"`. `\"Below\"`, `\"under\"`, or `\"older than\"` are not yet implemented in the regex layer.\n\n### 2. Edge Cases\n\n- **Unknown Countries:** If a country is mentioned that isn't in the internal ISO mapping dictionary, it will be ignored.\n- **Conflicting Age Logic:** If a user searches `\"young adult\"`, the system will apply both the `\"young\"` range (16–24) and the `\"adult\"` group filter, which may return zero results if they don't overlap in the data.\n- **Non-English Queries:** The parser is strictly tuned for English keywords.\n\n## Authentication Flow\n\n1. User hits `GET /auth/github` — redirected to GitHub with PKCE `code_challenge`\n2. GitHub redirects to `/auth/github/callback` with `code` + `state`\n3. Backend exchanges code for GitHub user info\n4. Issues JWT access token (15 min) + refresh token (7 days)\n5. Web: tokens stored in HTTP-only cookies\n6. CLI: tokens stored in `~/.insighta/credentials.json`\n\nTo refresh: `POST /auth/refresh` with `refresh_token` in body or `rt` cookie.\nReturns new `access_token` and `refresh_token`.\n\n## Role Enforcement\n\n| Role | Permissions |\n|---|---|\n| `analyst` | Read-only — GET profiles, search, export |\n| `admin` | Full access — create and delete profiles |\n\nAll `/api/profiles` routes require `X-API-Version: 1` header.\nRequests without it receive `400 Bad Request`.\n\n## CLI Usage\n\n```bash\ninsighta login                          # opens GitHub in browser\ninsighta profiles list --gender male    # list with filters\ninsighta profiles export --format csv   # export to CSV\n```\n\n## API Endpoints\n\n### 1. Advanced Search (Standard Filters)\n\n```\nGET /api/profiles\n```\n\n**Query Parameters:**\n\n| Param | Description |\n|---|---|\n| `gender` | Filter by gender |\n| `age_group` | Filter by age group |\n| `country_id` | Filter by country ISO code |\n| `min_age` | Minimum age |\n| `max_age` | Maximum age |\n| `min_gender_probability` | Minimum gender probability threshold |\n| `sort_by` | Field to sort results by |\n| `page` | Page number for pagination |\n| `limit` | Results per page |\n\n### 2. Natural Language Search\n\n```\nGET /api/profiles/search?q=young+males+from+nigeria\n```\n\n## Local Development\n\n### Seed Database\n\nThe system automatically seeds **2026 unique profiles** on the first run using `go:embed` to prevent duplicates.\n\n```bash\ngo run cmd/api/main.go\n```\n\n## Quick Test Links\n\nUse these links to verify the filtering, sorting, and NLP parsing logic.\n\n1. **Natural Language Search**\n\n- Young Nigerians: https://genderize-plum.vercel.app/api/profiles/search?q=young+males+from+nigeria\n- Age \u0026 Gender Intent: https://genderize-plum.vercel.app/api/profiles/search?q=females+above+30\n- Specific Demographics: https://genderize-plum.vercel.app/api/profiles/search?q=adult+males+from+kenya\n\n2. **Advanced Filtering**\n\n- Combined Filters: https://genderize-plum.vercel.app/api/profiles?gender=male\u0026country_id=NG\u0026min_age=25\n- Confidence Thresholds: https://genderize-plum.vercel.app/api/profiles?min_gender_probability=0.95\n\n3. **Sorting \u0026 Pagination**\n\n- Sort by Age (Desc): https://genderize-plum.vercel.app/api/profiles?sort_by=age\u0026order=desc\n- Paginated Results (Page 2): https://genderize-plum.vercel.app/api/profiles?page=2\u0026limit=10\n\n4. **Validation \u0026 Error Handling**\n\n- Invalid Type (422 Error): https://genderize-plum.vercel.app/api/profiles?min_age=abc\n- Logic Error (400 Error): https://genderize-plum.vercel.app/api/profiles?min_age=50\u0026max_age=20\n\n## Deployment\n\nLive on Vercel: [https://genderize-plum.vercel.app](https://genderize-plum.vercel.app)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikennarichard%2Finsighta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikennarichard%2Finsighta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikennarichard%2Finsighta/lists"}