Skip to content

🧹 Refactor: Split database.ts by Domain#16

Merged
codewithaman07 merged 2 commits into
mainfrom
refactor-database-split-domain-17851207981027042725
Feb 26, 2026
Merged

🧹 Refactor: Split database.ts by Domain#16
codewithaman07 merged 2 commits into
mainfrom
refactor-database-split-domain-17851207981027042725

Conversation

@codewithaman07
Copy link
Copy Markdown
Owner

This PR splits the monolithic app/lib/database.ts file into smaller, domain-specific modules located in app/lib/db/. This improves code maintainability and testability by separating concerns. Existing functionality is preserved, and all imports have been updated to point to the new locations.

What:

  • Created app/lib/db/ directory.
  • Created mood.ts, chat.ts, quotes.ts, user.ts, peer.ts in app/lib/db/ with content from database.ts.
  • Updated import paths in consuming files.
  • Removed app/lib/database.ts.

Why:

  • Better organization and separation of concerns.
  • Easier to navigate and maintain the database logic.
  • Reduced file size and complexity.

Verification:

  • npm run build passed successfully.
  • Code review confirmed correct refactoring and import updates.

PR created automatically by Jules for task 17851207981027042725 started by @codewithaman07

- Split app/lib/database.ts into:
  - app/lib/db/mood.ts (Mood entries)
  - app/lib/db/chat.ts (Chat sessions & messages)
  - app/lib/db/quotes.ts (Saved quotes)
  - app/lib/db/user.ts (User stats)
  - app/lib/db/peer.ts (Peer support)
- Updated imports in app/context/ChatContext.tsx, app/affirmations/page.tsx, app/mood/page.tsx, and app/community/page.tsx
- Deleted app/lib/database.ts
- Verified with npm run build

Co-authored-by: codewithaman07 <135147451+codewithaman07@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings February 26, 2026 17:06
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stablemind Error Error Feb 26, 2026 5:23pm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR successfully refactors the monolithic app/lib/database.ts file into smaller, domain-specific modules within the app/lib/db/ directory. The refactoring improves code organization, maintainability, and follows the single responsibility principle by separating database operations by domain.

Changes:

  • Created app/lib/db/ directory with five domain-specific modules (mood, chat, quotes, user, peer)
  • Updated all import statements across the codebase to reference the new module locations
  • Removed the original monolithic app/lib/database.ts file

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/lib/database.ts Removed monolithic database file containing all database operations
app/lib/db/mood.ts Created new module for mood entry database operations (saveMoodEntry, getMoodEntries)
app/lib/db/chat.ts Created new module for chat session and message database operations
app/lib/db/quotes.ts Created new module for saved quotes database operations
app/lib/db/user.ts Created new module for user statistics database operations
app/lib/db/peer.ts Created new module for peer support post and reply database operations
app/mood/page.tsx Updated import path from database.ts to db/mood.ts
app/context/ChatContext.tsx Updated import path from database.ts to db/chat.ts
app/community/page.tsx Updated import path from database.ts to db/peer.ts
app/affirmations/page.tsx Updated import paths from database.ts to db/quotes.ts and db/user.ts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codewithaman07 codewithaman07 merged commit c611c2e into main Feb 26, 2026
3 of 5 checks passed
@codewithaman07 codewithaman07 deleted the refactor-database-split-domain-17851207981027042725 branch March 9, 2026 20:57
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.

2 participants