Skip to content

Conversation

@Peehu1308
Copy link
Contributor

@Peehu1308 Peehu1308 commented Dec 28, 2025

Closes #97

Description
This pull request addresses Issue #97 by documenting and formalizing the database schema used in the project. It provides a clear overview of all existing tables, their relationships, and the corresponding SQL commands required to create them. The goal is to improve clarity, maintainability, and onboarding for contributors by ensuring the database structure is well-documented and consistent with the implemented codebase.

Changes Made
Added comprehensive database schema documentation in README format
Listed all tables currently used in the project
Documented relationships between entities (teams, users, tasks, tickets, meetings)
Included SQL editor commands for creating each table
Ensured alignment between Dart models and database tables

Screenshots or Visual Changes (if applicable)
Not applicable. This pull request focuses on documentation and schema definitions.

✅ Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if applicable).
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • Documentation

    • Added comprehensive database schema docs covering entities, relationships, security model, SQL table definitions, and extensibility roadmap.
  • New Features

    • Added resend-timer and 60s cooldown for OTP, plus automatic enable/disable of Verify button when OTP entry is complete.
  • Bug Fixes / UX

    • Improved OTP error/success feedback with user-friendly messages and ensured resend timer is cleaned up on navigation.
  • Style

    • Reduced vertical spacing in authentication layout.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 28, 2025

📝 Walkthrough

Walkthrough

Adds an authoritative database schema document and updates auth UI: new Database_Schema.md describing tables, relationships, RLS, and design notes; lib/screens/auth/verify_otp_screen.dart gains a 60s resend cooldown, OTP-completion tracking, and improved SnackBar UX; minor spacing tweak in auth layout.

Changes

Cohort / File(s) Summary
Database Schema Documentation
Database_Schema.md
New file: authoritative Supabase/Postgres schema for Ell-ena (teams, users, tasks, tickets, meetings, comments), per-table SQL CREATE statements, relationships, Row-Level Security notes, design decisions, and extensibility suggestions.
OTP verification screen (auth)
lib/screens/auth/verify_otp_screen.dart
Adds 60s resend cooldown with timer lifecycle (start/cancel/dispose), _canResend flag and countdown UI, OTP completion detection to enable/disable Verify action, improved SnackBar messages for success/error, preserves existing verification branches.
Auth layout spacing
lib/widgets/custom_widgets.dart
Minor UI spacing change: reduced vertical gap after subtitle in AuthScreenWrapper (40px → 30px).
Documentation index
README.md
Adds "Database Schema" section with link/reference to the new schema docs; trailing blank line added.

Sequence Diagram(s)

(Skipped — changes are documentation and UI tweaks that don't introduce new multi-component control flows requiring a sequence diagram.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through tables, seeds, and light,
I named each column by moonlit night.
A timer ticks, the code arrives—so neat,
Snacks of success and fields complete.
Hop on, friends, the schema's bright and right! 🥕✨

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Minor spacing adjustment in custom_widgets.dart (40→30px) is tangentially related to documentation polish but unrelated to database schema objectives; other changes (README, OTP improvements) are scope-creep beyond issue #97. Remove or separate unrelated changes (OTP verification improvements, custom widget spacing) into dedicated PRs to keep this PR focused solely on database schema documentation.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main addition of the PR: comprehensive database schema documentation with security policies and automation overview.
Linked Issues check ✅ Passed The PR fully meets issue #97's requirements: adds centralized schema documentation with table-by-table breakdown, field descriptions, relationships, security model (RLS), and clear guidance on read-only vs. updateable tables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
Database_Schema.md (1)

235-235: Reference or include RLS policy definitions.

Line 235 states: "RLS policies are defined in dedicated SQL files and applied per table." For future contributors and to ensure this documentation remains authoritative, either:

  • Link to the location of those SQL files (e.g., backend/migrations/rls_policies.sql)
  • Include a brief example of a representative RLS policy so readers understand the enforcement model
  • Cross-reference an adjacent document or section that contains the policies
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cd90f2 and 005cb9e.

📒 Files selected for processing (1)
  • Database_Schema.md
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
Database_Schema.md

45-45: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Comment on lines +45 to +50
```
teams ──< users
teams ──< tasks ──< task_comments
teams ──< tickets ──< ticket_comments
teams ──< meetings
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Specify language for code fence (MD040).

The ASCII diagram fence is missing a language identifier. Add text or ascii after the opening backticks to comply with markdown linting standards.

🔎 Proposed fix
-```
+```text
 teams ──< users
 teams ──< tasks ──< task_comments
 teams ──< tickets ──< ticket_comments
 teams ──< meetings
</details>

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

45-45: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

In Database_Schema.md around lines 45 to 50, the fenced ASCII diagram is missing
a language identifier which triggers MD040; update the opening code fence to
include a language tag such as text (e.g., change totext or ```ascii) so
the fence declares the language, keeping the diagram contents unchanged.


</details>

<!-- fingerprinting:phantom:triton:mongoose -->

<!-- This is an auto-generated comment by CodeRabbit -->

email text not null unique,
team_id uuid not null references teams(id) on delete cascade,
role text not null check (role in ('admin', 'member')),
google_refresh_token text,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's find and read the Database_Schema.md file
find . -name "Database_Schema.md" -type f

Repository: AOSSIE-Org/Ell-ena

Length of output: 82


🏁 Script executed:

# Also search for any Supabase or authentication-related configuration files
fd -t f -e "md" -e "sql" -e "ts" -e "js" | grep -iE "(schema|migration|auth|token|secret)" | head -20

Repository: AOSSIE-Org/Ell-ena

Length of output: 814


🏁 Script executed:

# Search for token handling and encryption patterns in the codebase
rg -i "google_refresh_token" -A 3 -B 3

Repository: AOSSIE-Org/Ell-ena

Length of output: 1765


🏁 Script executed:

# Search for RLS (Row Level Security) policies
rg -i "row level security|rls|enable rls" -A 2

Repository: AOSSIE-Org/Ell-ena

Length of output: 47927


🏁 Script executed:

# Search for secrets manager or encryption configurations
rg -i "secrets|vault|encryption|encrypt" -t ts -t js -t sql | head -30

Repository: AOSSIE-Org/Ell-ena

Length of output: 44


🏁 Script executed:

# Check the RLS policies for users table
cat supabase/migrations/20251021020000_user_auth_policies.sql

Repository: AOSSIE-Org/Ell-ena

Length of output: 2021


🏁 Script executed:

# Search for token refresh/rotation logic
rg -i "refresh.*token|rotate.*token|token.*refresh|token.*rotate" -A 3 -B 1

Repository: AOSSIE-Org/Ell-ena

Length of output: 4591


🏁 Script executed:

# Check if there's any encryption or secrets manager configuration
rg -i "encrypt|secret|vault|aws|credentials" -t ts -t js -t dart --max-count=50

Repository: AOSSIE-Org/Ell-ena

Length of output: 287


Implement encryption for sensitive OAuth tokens and restrict token field access.

google_refresh_token is stored as plaintext and accessible to all team members via RLS policies that allow viewing other team members' profiles. This is a critical security vulnerability. Either:

  1. Implement field-level encryption (PostgreSQL pgcrypto or application-level encryption) before storing tokens
  2. Offload token management to a secrets manager (AWS Secrets Manager, HashiCorp Vault) and store only a reference in the database
  3. Restrict google_refresh_token column access via PostgreSQL column-level security or separate it into a restricted table with stricter RLS policies

Also document and implement a token rotation/refresh strategy for long-lived refresh tokens.

Comment on lines +130 to +131
created_by uuid not null references auth.users(id),
assigned_to uuid references auth.users(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "Database_Schema.md" -o -name "*database*schema*.md" -o -name "*schema*.md" | head -20

Repository: AOSSIE-Org/Ell-ena

Length of output: 82


🏁 Script executed:

wc -l ./Database_Schema.md

Repository: AOSSIE-Org/Ell-ena

Length of output: 86


🏁 Script executed:

cat -n ./Database_Schema.md | sed -n '125,135p; 162,172p; 208,218p'

Repository: AOSSIE-Org/Ell-ena

Length of output: 1609


Document ON DELETE behavior for auth.users references.

The tasks (lines 130–131), tickets (lines 167–168), and meetings (line 213) tables all reference auth.users(id) without explicit ON DELETE constraints. If an authenticated user is deleted, the current schema does not specify what happens to their associated records—resulting in orphaned rows and potential referential integrity violations. This is inconsistent with the team_id references, which use ON DELETE CASCADE.

Specify the intended behavior: ON DELETE CASCADE, ON DELETE SET NULL, ON DELETE RESTRICT, or implement soft deletes. Update the SQL definitions and document this decision.

description text,
meeting_date timestamptz not null,
meeting_url text,
transcription text,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cd /root && find . -name "Database_Schema.md" -type f 2>/dev/null | head -20

Repository: AOSSIE-Org/Ell-ena

Length of output: 117


🏁 Script executed:

cd /root && git ls-files | grep -i database

Repository: AOSSIE-Org/Ell-ena

Length of output: 117


🏁 Script executed:

git ls-files | grep -i "database_schema\|schema" | head -20

Repository: AOSSIE-Org/Ell-ena

Length of output: 404


🏁 Script executed:

cat -n Database_Schema.md | sed -n '200,230p'

Repository: AOSSIE-Org/Ell-ena

Length of output: 1076


🏁 Script executed:

cat -n Database_Schema.md | head -100

Repository: AOSSIE-Org/Ell-ena

Length of output: 3368


🏁 Script executed:

cat -n Database_Schema.md | grep -A 50 "### meetings"

Repository: AOSSIE-Org/Ell-ena

Length of output: 1769


🏁 Script executed:

grep -n "transcription" Database_Schema.md

Repository: AOSSIE-Org/Ell-ena

Length of output: 274


🏁 Script executed:

cat -n Database_Schema.md | sed -n '193,240p'

Repository: AOSSIE-Org/Ell-ena

Length of output: 1566


🏁 Script executed:

rg -i "transcription|final_transcription" --type md --type sql -B 3 -A 3

Repository: AOSSIE-Org/Ell-ena

Length of output: 25659


Document the relationship between transcription and final_transcription fields.

The schema defines both transcription (text) and final_transcription (jsonb) but provides no explanation of their purpose or relationship. The schema documentation should clarify:

  • transcription stores the raw transcription data in JSON format (as text type)
  • final_transcription stores the processed/cleaned transcription extracted from transcription via a database trigger
  • A database trigger (update_final_transcription) automatically populates final_transcription whenever transcription is inserted or updated
  • final_transcription is then used for downstream AI processing (summarization, embeddings, semantic search)
🤖 Prompt for AI Agents
In Database_Schema.md around line 207, add documentation that explains the
relationship between transcription (text) and final_transcription (jsonb): state
that transcription holds raw transcription JSON as text, final_transcription
stores the processed/cleaned JSON extracted from transcription, and a DB trigger
named update_final_transcription populates/updates final_transcription on
insert/update of transcription; also note that final_transcription is used for
downstream AI workflows (summarization, embeddings, semantic search).

Disabled the Resend OTP button for 60 seconds after an OTP request

Added a visible countdown timer (e.g., “Resend available in 52s”) to indicate cooldown state

Prevented AuthApiException (429 over_email_send_rate_limit) from being surfaced to users

Improved UX by replacing raw API errors with clear, user-friendly behavior

Added helper text guiding users to check spam/junk folders

Automatically re-enabled the resend button once the cooldown expires
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
lib/screens/auth/verify_otp_screen.dart (5)

33-41: Follow Dart naming conventions for variables.

Several new state variables use non-standard naming (e.g., _resendseconds, _canresend, _otpcomplete, _showtimertext). Dart style guidelines require camelCase for variable names.

🔎 Suggested naming improvements
-  Timer? _resendTimer;
-  bool _showtimertext = false;
-  bool _timerStarted = false;
+  Timer? _resendTimer;
+  bool _showTimerText = false;
+  bool _timerStarted = false;
   bool _isLoading = false;
-  int _resendseconds = 60;
-  bool _canresend = true;
+  int _resendSeconds = 60;
+  bool _canResend = true;
   
   String? _errorMessage;
-  bool _otpcomplete = false;
+  bool _otpComplete = false;

Update all references throughout the file accordingly.


79-102: LGTM! Timer implementation is sound.

The resend timer correctly prevents multiple concurrent timers and manages its lifecycle properly. The countdown logic and state updates work as intended.

💡 Optional: Extract timer duration as a constant

Consider defining the 60-second duration as a named constant for better maintainability:

static const int _resendCooldownSeconds = 60;

This makes it easier to adjust the cooldown period in the future.


182-195: Redundant state update on Line 186.

Line 186 sets _showtimertext = true, but _startResendTimer() called immediately after on Line 191 also sets this value to true (Line 85). The first assignment is unnecessary.

🔎 Proposed simplification
   if (!_canresend) {
-    setState(() {
-      _showtimertext = true;
-    });
     return;
   }
   
   _startResendTimer();

The timer start method already handles showing the timer text.


204-210: Consider breaking long string for readability.

The success message on Line 207 is quite long. While the content is excellent (it reminds users to check spam), consider splitting it for better code readability.

💡 Optional formatting suggestion
         ScaffoldMessenger.of(context).showSnackBar(
-          const SnackBar(
-            content: Text('Verification code resent successfully. Please check your inbox and spam folder.'),
+          SnackBar(
+            content: Text(
+              'Verification code resent successfully. '
+              'Please check your inbox and spam folder.'
+            ),
             backgroundColor: Colors.green,
           ),
         );

339-359: Remove commented-out code.

Lines 340-348 contain commented-out error message display code. Since the error feedback is now handled via snackbars (which is a better UX choice), this dead code should be removed. Version control preserves the history if needed.

🔎 Proposed cleanup
       children: [
         
-        // if (_errorMessage != null)
-        //   Padding(
-        //     padding: const EdgeInsets.only(bottom: 16),
-        //     child: Text(
-        //       _errorMessage!,
-        //       style: const TextStyle(color: Colors.red),
-        //       textAlign: TextAlign.center,
-        //     ),
-        //   ),
         if (_showtimertext && _timerStarted)
           Padding(
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 005cb9e and 17aa52c.

📒 Files selected for processing (2)
  • lib/screens/auth/verify_otp_screen.dart
  • lib/widgets/custom_widgets.dart
🔇 Additional comments (8)
lib/widgets/custom_widgets.dart (1)

171-171: LGTM! Minor spacing adjustment improves layout density.

The reduction from 40px to 30px provides tighter spacing after the subtitle, which can improve the visual flow of the authentication screens.

lib/screens/auth/verify_otp_screen.dart (7)

44-54: LGTM! Proper resource cleanup.

The timer is correctly canceled in the dispose method, preventing memory leaks. This follows Flutter best practices for StatefulWidget cleanup.


56-65: LGTM! Efficient completion check with state optimization.

The implementation correctly checks all OTP fields and only triggers a rebuild when the completion state actually changes, avoiding unnecessary UI updates.


66-76: LGTM! Well-designed error feedback mechanism.

Clearing existing snackbars before displaying new ones prevents message stacking and ensures users see the most recent error. The styling and duration are appropriate for error notifications.


104-180: LGTM! Enhanced error handling improves user experience.

The addition of user-friendly error messages and snackbar notifications significantly improves the verification flow. The pattern matching for different error types (expired, invalid, etc.) provides appropriate feedback to users.


387-397: LGTM! OTP field behavior is well-balanced.

The integration of completion checking while maintaining auto-advance between fields provides a good user experience. The commented line on 393 should be removed (as noted in the earlier comment about dead code).


403-407: LGTM! Button state management prevents premature verification.

Disabling the Verify button when the OTP is incomplete or during loading provides clear feedback and prevents unnecessary API calls. The condition logic is correct.


349-358: LGTM! Clear countdown display for resend cooldown.

The timer text provides immediate visual feedback about when users can request another code. The formatting and conditional rendering are implemented correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
README.md (1)

67-73: Consider cross-referencing the detailed Database Schema documentation file in the README.

The README currently links only to the external dbdiagram.io visual diagram, but a comprehensive Database_Schema.md file exists in the repository with detailed table definitions, relationships, security models, and design decisions. Adding a link to this documentation alongside the diagram will improve discoverability and provide developers with a complete reference during onboarding.

Suggested update
  ## ✨ Database Schema
  
  Ell-ena uses PostgreSQL (via Supabase) with strict Row-Level Security (RLS) and
  AI-optimized vector search tables.
  
  **Database Schema Diagram & Docs**  
- 👉 [View Database Schema](https://dbdiagram.io/d/69525ba139fa3db27bb9e56c)
+ 👉 [View Visual Diagram](https://dbdiagram.io/d/69525ba139fa3db27bb9e56c) | [Detailed Documentation](./Database_Schema.md)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17aa52c and ffc7aa7.

📒 Files selected for processing (1)
  • README.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-06T10:06:27.181Z
Learnt from: SharkyBytes
Repo: AOSSIE-Org/Ell-ena PR: 11
File: sqls/03_task_schema.sql:57-78
Timestamp: 2025-07-06T10:06:27.181Z
Learning: SharkyBytes prefers to keep separate database RLS policies during the development phase in the Ell-ena project for clarity and debugging purposes, even when they might be combined for better security. They handle complex authorization logic on the application side during development, with plans to optimize database-level security later when focusing on production readiness.

Applied to files:

  • README.md
🔇 Additional comments (1)
README.md (1)

67-73: Well-placed addition that improves documentation clarity.

The new "Database Schema" section successfully introduces Ell-ena's PostgreSQL/Supabase infrastructure with RLS, aligning with the PR's goal of reducing contributor friction during onboarding. The placement between the architecture overview and feature list is logical and maintains good document flow.

Note: The RLS mention is consistent with the project's development-phase approach (per learnings, separate policies are maintained for clarity and debugging purposes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCS UPDATE:Supabase Database Schema Documentation

1 participant