How yazeedr1425/ahsem works
Purpose and runtime
Arabic-first decision-assistant built with Next.js App Router/React. It combines deterministic weighted scoring with Gemini-generated explanations and decision agents; Supabase supplies identity, PostgreSQL persistence, RLS, and live group-vote signaling. Primary UI entry is app/page.js; specialized flows are /plan, /analyze, and /vote/[code].
Individual decision flow
The main client flow collects 2–5 options, category, weighted criteria, ratings, and mood, then renders a recommendation and transparent score breakdown. Deterministic logic must remain authoritative so the UI can complete if AI fails.
• app/page.js
• app/components/QuestionStep.js
• lib/engine/score.js
• lib/engine/categories.js
• app/api/decide/route.js
Mood modifies one criterion weight; local “oversized decision” detection diverts consequential questions into a staged breakdown rather than the standard three-question flow.
• lib/engine/mood.js
• lib/engine/oversized.js
• app/components/BreakdownFlow.js
• app/api/breakdown/route.js
AI boundary and decision agents
Gemini 2.5 Flash is server-only and is used for constrained JSON outputs: final recommendation, third-option suggestion, large-decision decomposition/verdict, voice assistance, plan generation, and risk analysis. Local engines calculate scores/statistics; model output explains or structures results rather than inventing numerical facts.
• app/api/decide/route.js
• app/api/third/route.js
• lib/engine/explain.js
• lib/insight/prompt.js
Rate limiting and cache behavior protect selected expensive endpoints.
• lib/rate-limit.js
• lib/services/third.js
Persistence, identity, and history insights
Supabase browser and service-role clients separate client access from trusted server operations. The schema models profiles, decisions/options/answers, feedback, analyses, votes, and an immutable winner history. Authenticated history is aggregated in code, then presented by Gemini as a “decision personality.”
• lib/supabase.js
• lib/supabase-server.js
• lib/services/decisions.js
• lib/insight/stats.js
• supabase/migrations/20260818140000_add_decision_winners.sql
Signup is a server flow integrating Supabase Auth and Mailtrap verification email; failure is compensated by removing the incomplete account.
• app/api/signup/route.js
• app/api/magic-link/route.js
• email send/verification.html
Collaborative voting
A creator creates or closes a decision group; guests join through a short code without accounts and cast votes through database security-definer functions. Realtime Broadcast is only a refresh signal and Presence reports active participants; clients re-fetch authoritative vote state rather than trusting broadcast payloads.
• app/vote/[code]/page.js
• app/api/group/route.js
• lib/services/group.js
• supabase/migrations/20260818120000_harden_functions_and_policies.sql
Planning and risk-analysis products
/plan orchestrates Gemini planning with external factual enrichment: Google Places, Google Routes travel times, and Open-Meteo weather, with graceful degradation around weather. /analyze produces persisted SWOT and path-tree analysis for one major decision.
• app/plan/page.js
• app/api/plan/route.js
• lib/places/client.js
• lib/routing/travel.js
• lib/weather/client.js
• app/api/analyze/route.js
• lib/analyze/agents.js
Client interaction layers
The UI is RTL-oriented and composed as staged decision screens, result/reveal views, optional voice interaction, and global auth/mood providers. Browser speech recognition/synthesis is encapsulated separately from the server AI assistant endpoint.
• app/layout.js
• app/components/Result.js
• lib/auth/AuthProvider.js
• lib/theme/MoodProvider.js
• lib/voice/VoiceProvider.js
• app/api/assist/route.js
Main entry points: route.js Decision endpoint · explain.js Gemini decision agents · page.js Decision questionnaire · decisions.js Decisions and personality
Components 21
RTL client experience
App Router screens and client-side decision flows.
- App shell · RTL layout and global providers.
app/layout.js - Decision questionnaire · Collects options, criteria, ratings, and mood.
app/page.js - Question stages
app/components/QuestionStep.js - Oversized breakdown · Staged alternative for consequential decisions.
app/components/BreakdownFlow.js - Recommendation reveal · Shows recommendation and score transparency.
app/components/Result.js - Auth, mood, and voice · Global identity, mood, and browser speech interaction.
lib/auth/AuthProvider.js
Server decision APIs
Trusted routes coordinate engines, AI, and persistence.
- Decision endpoint · Combines authoritative scores with constrained AI explanation.
app/api/decide/route.js - Breakdown endpoint
app/api/breakdown/route.js - Voice assistant endpoint · Server-side Gemini assistance for voice UI.
app/api/assist/route.js
AI and local intelligence
Deterministic scoring remains authoritative over generated explanations.
- Weighted score engine · Calculates recommendation and transparent numerical breakdown.
lib/engine/score.js - Categories and mood rules · Category criteria and mood-adjusted weight logic.
lib/engine/mood.js - Oversized detector · Routes large decisions away from the standard flow.
lib/engine/oversized.js - Gemini decision agents · Produces constrained JSON explanations, decompositions, and verdicts.
lib/engine/explain.js
Identity and persistence
Supabase provides auth, RLS-protected data, functions, and realtime.
- Supabase clients · Separates browser access from trusted service-role operations.
lib/supabase-server.js - Auth and signup · Signup compensates by deleting incomplete accounts after email failure.
app/api/signup/route.js - Decisions and personality · Persists decisions and aggregates history into decision insights.
lib/services/decisions.js - Immutable winners
supabase/migrations/20260818140000_add_decision_winners.sql
Specialized products
Planning, analysis, and collaborative voting flows.
- Group voting · Creator-managed groups joined by short code.
app/vote/[code]/page.js - Authoritative vote state · Clients re-fetch state after Broadcast; Presence reports participants.
lib/services/group.js - Travel-aware planning · Gemini plans are enriched with places, routes, and optional weather.
app/api/plan/route.js - SWOT and path analysis · Persists analysis for a major decision.
app/api/analyze/route.js
Connections 26
- App shell → Decision questionnaire
- App shell → Auth, mood, and voice: mounts providers
- Decision questionnaire → Question stages: renders
- Decision questionnaire → Oversized detector: screens decision
- Oversized detector → Oversized breakdown: diverts large decisions
- Decision questionnaire → Decision endpoint: submits decision
- Oversized breakdown → Breakdown endpoint: submits stages
- Decision endpoint → Weighted score engine: calculates scores
- Decision endpoint → Categories and mood rules: applies weights
- Decision endpoint → Gemini decision agents: requests explanation
- Weighted score engine → Recommendation reveal: authoritative result
- Decision endpoint → Recommendation reveal: returns explanation
- Breakdown endpoint → Gemini decision agents: requests decomposition
- Auth, mood, and voice → Voice assistant endpoint: voice assistance
- Voice assistant endpoint → Gemini decision agents: constrained response
- Decision endpoint → Decisions and personality: persists decision
- Decisions and personality → Immutable winners: records winner
- Decisions and personality → Gemini decision agents: history insight prompt
- Auth, mood, and voice → Supabase clients: browser auth
- Auth and signup → Supabase clients: Auth and service role
- Group voting → Authoritative vote state: join, vote, refresh
- Authoritative vote state → Supabase clients: security-definer functions and realtime
- Travel-aware planning → Gemini decision agents: generates plan
- Travel-aware planning → SWOT and path analysis
- SWOT and path analysis → Gemini decision agents: generates SWOT and paths
- SWOT and path analysis → Decisions and personality: persists analysis