|
| 1 | +# Google Sign-In Implementation Plan |
| 2 | + |
| 3 | +## Goal |
| 4 | + |
| 5 | +Add Google sign-in in a way that improves both user experience and product operations. |
| 6 | + |
| 7 | +This should support: |
| 8 | + |
| 9 | +- simple login for end users |
| 10 | +- persistent per-user usage tracking |
| 11 | +- future daily or plan-based limits |
| 12 | +- future billing and paid plans |
| 13 | +- stable identity for saved artifacts and workflow history |
| 14 | + |
| 15 | +## Recommendation |
| 16 | + |
| 17 | +Use Supabase Auth with Google as the first implementation path. |
| 18 | + |
| 19 | +Reasoning: |
| 20 | + |
| 21 | +- it is faster to ship than a custom backend-auth stack |
| 22 | +- it gives both authentication and persistent data storage |
| 23 | +- it fits the app's current stage better than a fully custom auth service |
| 24 | +- it creates a clean path to quotas, account records, and subscriptions later |
| 25 | + |
| 26 | +## Target Architecture |
| 27 | + |
| 28 | +### Frontend |
| 29 | + |
| 30 | +Streamlit remains the product UI. |
| 31 | + |
| 32 | +Responsibilities: |
| 33 | + |
| 34 | +- sign-in and sign-out entry points |
| 35 | +- authenticated session display |
| 36 | +- route gating for protected workflows |
| 37 | +- showing per-user usage and plan state |
| 38 | + |
| 39 | +### Auth and Data Layer |
| 40 | + |
| 41 | +Supabase becomes the source of truth for: |
| 42 | + |
| 43 | +- user identity |
| 44 | +- linked Google account |
| 45 | +- usage records |
| 46 | +- quota state |
| 47 | +- saved workflow metadata |
| 48 | +- future billing/account metadata |
| 49 | + |
| 50 | +### Current Limitation To Fix |
| 51 | + |
| 52 | +Right now assisted-usage tracking is browser-session based. |
| 53 | + |
| 54 | +That is acceptable for a prototype, but not for: |
| 55 | + |
| 56 | +- real quotas |
| 57 | +- per-day limits |
| 58 | +- cross-device usage tracking |
| 59 | +- abuse prevention |
| 60 | +- subscriptions |
| 61 | + |
| 62 | +## Phased Implementation |
| 63 | + |
| 64 | +## Phase 1: Auth Foundation |
| 65 | + |
| 66 | +### Deliverables |
| 67 | + |
| 68 | +- Supabase project setup |
| 69 | +- Google OAuth provider configured in Supabase |
| 70 | +- app config for Supabase URL and anon key |
| 71 | +- auth service wrapper in the codebase |
| 72 | +- UI login/logout surface |
| 73 | +- authenticated user info persisted in UI state |
| 74 | + |
| 75 | +### Code Changes |
| 76 | + |
| 77 | +- add `src/auth_service.py` |
| 78 | +- add auth-related config in `src/config.py` |
| 79 | +- add auth state helpers in `src/ui/state.py` |
| 80 | +- add login/logout and account display in `src/ui/pages.py` or `src/ui/components.py` |
| 81 | +- gate assisted workflows behind login if desired, or allow anonymous read-only behavior |
| 82 | + |
| 83 | +### Product Decisions |
| 84 | + |
| 85 | +- choose whether anonymous usage is allowed at all |
| 86 | +- choose whether resume upload is allowed before login |
| 87 | +- choose whether assisted workflow requires login immediately or only for heavy usage |
| 88 | + |
| 89 | +### Recommended Product Rule |
| 90 | + |
| 91 | +- allow browsing and basic deterministic exploration without login |
| 92 | +- require Google sign-in before assisted workflow runs and persistent artifact history |
| 93 | + |
| 94 | +## Phase 2: Persistent User Record |
| 95 | + |
| 96 | +### Deliverables |
| 97 | + |
| 98 | +- create user profile table in Supabase |
| 99 | +- store app-level metadata per user |
| 100 | +- sync first sign-in and returning sign-in behavior |
| 101 | + |
| 102 | +### Suggested Tables |
| 103 | + |
| 104 | +#### `app_users` |
| 105 | + |
| 106 | +- `id` |
| 107 | +- `email` |
| 108 | +- `display_name` |
| 109 | +- `avatar_url` |
| 110 | +- `created_at` |
| 111 | +- `last_seen_at` |
| 112 | +- `plan_tier` |
| 113 | +- `account_status` |
| 114 | + |
| 115 | +#### `user_sessions` optional |
| 116 | + |
| 117 | +- `id` |
| 118 | +- `user_id` |
| 119 | +- `started_at` |
| 120 | +- `ended_at` |
| 121 | +- `client_fingerprint` optional |
| 122 | + |
| 123 | +### Purpose |
| 124 | + |
| 125 | +This creates a real user object that quotas and billing can attach to later. |
| 126 | + |
| 127 | +## Phase 3: Usage Persistence |
| 128 | + |
| 129 | +### Deliverables |
| 130 | + |
| 131 | +- persist usage per user instead of only per browser session |
| 132 | +- store request counts and token totals server-side |
| 133 | +- store usage by model and by task |
| 134 | + |
| 135 | +### Suggested Tables |
| 136 | + |
| 137 | +#### `usage_events` |
| 138 | + |
| 139 | +- `id` |
| 140 | +- `user_id` |
| 141 | +- `session_id` optional |
| 142 | +- `task_name` |
| 143 | +- `model_name` |
| 144 | +- `request_count` |
| 145 | +- `prompt_tokens` |
| 146 | +- `completion_tokens` |
| 147 | +- `total_tokens` |
| 148 | +- `response_id` |
| 149 | +- `status` |
| 150 | +- `created_at` |
| 151 | + |
| 152 | +#### `usage_rollups_daily` |
| 153 | + |
| 154 | +- `user_id` |
| 155 | +- `date` |
| 156 | +- `request_count` |
| 157 | +- `prompt_tokens` |
| 158 | +- `completion_tokens` |
| 159 | +- `total_tokens` |
| 160 | + |
| 161 | +### Code Changes |
| 162 | + |
| 163 | +- add a persistence hook in `src/openai_service.py` |
| 164 | +- add a usage repository module such as `src/usage_store.py` |
| 165 | +- continue showing session capacity in the UI, but source enforcement from persisted quota checks |
| 166 | + |
| 167 | +## Phase 4: Quotas and Limits |
| 168 | + |
| 169 | +### Deliverables |
| 170 | + |
| 171 | +- per-user daily limits |
| 172 | +- plan-tier-based limits |
| 173 | +- admin override support |
| 174 | +- soft warning and hard stop behavior |
| 175 | + |
| 176 | +### Suggested Rules |
| 177 | + |
| 178 | +- free tier: conservative daily assisted runs |
| 179 | +- paid tier: larger daily or monthly allowance |
| 180 | +- admin tier: unrestricted or high cap |
| 181 | + |
| 182 | +### Enforcement Order |
| 183 | + |
| 184 | +1. check account status |
| 185 | +2. check plan tier |
| 186 | +3. check daily quota remaining |
| 187 | +4. allow or block the assisted step |
| 188 | + |
| 189 | +### UI Behavior |
| 190 | + |
| 191 | +- show users remaining assisted capacity |
| 192 | +- do not show internal dollar cost |
| 193 | +- show friendly upgrade or retry messaging only when relevant |
| 194 | + |
| 195 | +## Phase 5: Saved History and Artifacts |
| 196 | + |
| 197 | +### Deliverables |
| 198 | + |
| 199 | +- save workflow summaries per user |
| 200 | +- save report metadata and tailored resume metadata |
| 201 | +- optional download history |
| 202 | +- optional restore last session state |
| 203 | + |
| 204 | +### Suggested Tables |
| 205 | + |
| 206 | +#### `workflow_runs` |
| 207 | + |
| 208 | +- `id` |
| 209 | +- `user_id` |
| 210 | +- `job_title` |
| 211 | +- `fit_score` |
| 212 | +- `review_approved` |
| 213 | +- `model_policy` |
| 214 | +- `created_at` |
| 215 | + |
| 216 | +#### `artifacts` |
| 217 | + |
| 218 | +- `id` |
| 219 | +- `workflow_run_id` |
| 220 | +- `artifact_type` |
| 221 | +- `storage_path` |
| 222 | +- `created_at` |
| 223 | + |
| 224 | +## Phase 6: Billing Readiness |
| 225 | + |
| 226 | +### Deliverables |
| 227 | + |
| 228 | +- Stripe or similar billing integration |
| 229 | +- plan tier sync into user profile |
| 230 | +- billing webhook handling |
| 231 | +- entitlement checks before assisted runs |
| 232 | + |
| 233 | +### Important Rule |
| 234 | + |
| 235 | +Billing should attach to account entitlements, not to raw token display in the UI. |
| 236 | + |
| 237 | +## Security and Privacy Requirements |
| 238 | + |
| 239 | +- never store raw Google access tokens in app-visible state longer than needed |
| 240 | +- keep Supabase session handling server-trusted where possible |
| 241 | +- treat uploaded resumes and JDs as sensitive user data |
| 242 | +- define retention and deletion behavior early |
| 243 | +- add row-level security for all user-owned records |
| 244 | + |
| 245 | +## Streamlit-Specific Notes |
| 246 | + |
| 247 | +Because this app is Streamlit-first, auth should not rely only on local session state. |
| 248 | + |
| 249 | +Session state should cache authenticated UI context, but the durable source of truth must be: |
| 250 | + |
| 251 | +- Supabase auth session |
| 252 | +- Supabase user record |
| 253 | +- persisted usage tables |
| 254 | + |
| 255 | +## Proposed File-Level Implementation Sequence |
| 256 | + |
| 257 | +1. `src/config.py` |
| 258 | +Add Supabase and Google auth env settings. |
| 259 | + |
| 260 | +2. `src/auth_service.py` |
| 261 | +Add sign-in, sign-out, current-user, and session validation helpers. |
| 262 | + |
| 263 | +3. `src/ui/state.py` |
| 264 | +Add authenticated user/session state keys. |
| 265 | + |
| 266 | +4. `src/ui/pages.py` |
| 267 | +Add login screen, account panel, and workflow gating. |
| 268 | + |
| 269 | +5. `src/openai_service.py` |
| 270 | +Attach authenticated user context to usage logging and persistent usage writes. |
| 271 | + |
| 272 | +6. `src/ui/workflow.py` |
| 273 | +Block assisted workflow runs if policy requires login or quota is exhausted. |
| 274 | + |
| 275 | +7. `tests/` |
| 276 | +Add tests for auth state, quota enforcement, and assisted workflow gating. |
| 277 | + |
| 278 | +## Recommended Rollout |
| 279 | + |
| 280 | +### Step 1 |
| 281 | + |
| 282 | +Ship Google sign-in and basic authenticated session support. |
| 283 | + |
| 284 | +### Step 2 |
| 285 | + |
| 286 | +Persist user records and usage events. |
| 287 | + |
| 288 | +### Step 3 |
| 289 | + |
| 290 | +Add daily limits. |
| 291 | + |
| 292 | +### Step 4 |
| 293 | + |
| 294 | +Add plan tiers and billing. |
| 295 | + |
| 296 | +This order keeps the implementation honest. A daily limit before persistent identity would be weak and easy to bypass. |
| 297 | + |
| 298 | +## Immediate Next Build Task |
| 299 | + |
| 300 | +Implement Phase 1 only: |
| 301 | + |
| 302 | +- Supabase config |
| 303 | +- Google sign-in flow |
| 304 | +- authenticated user state |
| 305 | +- basic account panel in the UI |
| 306 | + |
| 307 | +Do not implement billing or daily quota enforcement in the same pass. |
0 commit comments