Database Models
Understanding the database schema and models used in the Founderflow Boilerplate. Learn about the data structure, relationships, and how to work with the database.
Database Features
MongoDB
NoSQL document database for flexible data storage
Mongoose
ODM for MongoDB with schema validation
Indexing
Optimized queries with proper database indexing
Validation
Schema validation for data integrity
Relationships
Document references for data relationships
Type Safety
TypeScript definitions for all models
User Model
The main user model that stores user information and subscription details:
Authentication Fields
- • id - Unique user identifier
- • emailAddress - User's email addresses
- • firstName/lastName - User's name
- • picture - Profile picture URL
Subscription Fields
- • stripeCustomerId - Stripe customer ID
- • lemonsqueezyCustomerId - Lemon Squeezy ID
- • credits - Available user credits
- • plan - Current subscription plan
Payment History Model
Tracks all payment transactions and subscription changes:
Payment Tracking Fields:
Additional Models
Feedback Model
Collects and stores user feedback and suggestions:
Fields:
- • userId (optional)
- • message
- • rating
- • category
- • createdAt
Purpose:
- • User feedback collection
- • Product improvement insights
- • Customer satisfaction tracking
- • Support ticket integration
Leads Model
Tracks potential customers and marketing leads:
Fields:
- • name (optional)
- • source
- • status
- • createdAt
Purpose:
- • Lead generation tracking
- • Marketing campaign analysis
- • Conversion tracking
- • Email list building
Database Connection
The database connection is configured in lib/db.ts
:
Best Practices
Schema Validation
Always define proper schemas with validation rules to ensure data integrity.
Indexing
Create indexes for frequently queried fields to improve performance.
Error Handling
Implement proper error handling for database operations.
Next Steps
Now that you understand the database structure, explore these related areas: