A comprehensive multi-tenant SaaS notes application built with the MERN stack, featuring subscription management, role-based access control, and complete data isolation between tenants.
- ๐ Features
- ๐๏ธ Architecture
- ๐ Project Structure
- ๐ Quick Start
- ๐ฅ Test Accounts
- ๐ API Documentation
- ๐ Deployment
- ๐ Security Features
- ๐ Subscription Plans
- ๐งช Testing
- ๐ Troubleshooting
- ๐ฃ๏ธ Roadmap
- ๐ค Contributing
- ๐ค Author
- ๐ License
- JWT-based authentication with secure token management
- Role-based access control (Admin, Member)
- Secure password hashing using bcrypt
- Rate limiting and security headers
- Input validation and sanitization
- CORS protection and Helmet security headers
- Complete data isolation between tenants
- Tenant-aware API endpoints with automatic validation
- Scalable architecture supporting multiple organizations
- Shared schema approach for efficient resource utilization
- Tenant-specific user management
- Free Plan: 3 notes maximum
- Pro Plan: Unlimited notes ($9.99/month)
- Usage tracking and limit enforcement
- Admin-only subscription upgrades/downgrades
- Real-time subscription status updates
- Full CRUD operations for notes
- Advanced search and filtering capabilities
- Tagging system for organization
- Archive/unarchive functionality
- Pagination for large datasets
- Rich text editing support
- Responsive design with Tailwind CSS
- Modern UI components with Radix UI
- Dark/Light theme support
- Mobile-first approach
- Accessibility compliant
This application uses a shared schema with tenant isolation approach:
- Single Database: All tenants share the same MongoDB database
- Tenant Isolation: Every record includes a
tenantIdfield for data segregation - Security: Middleware ensures users can only access their tenant's data
- Scalability: Efficient resource utilization while maintaining data isolation
| Component | Technology | Version | Purpose |
|---|---|---|---|
| Frontend | React | 18.2.0 | User Interface |
| Backend | Node.js + Express | 4.18.2 | API Server |
| Database | MongoDB + Mongoose | 7.5.0 | Data Storage |
| Authentication | JWT | 9.0.2 | Token-based Auth |
| Styling | Tailwind CSS | 3.3.3 | CSS Framework |
| UI Components | Radix UI | Latest | Accessible Components |
| Deployment | Vercel | Latest | Cloud Platform |
| Type Safety | TypeScript | 5.0 | Type Checking |
SaaSNotes/
โโโ ๐ client/ # React Frontend Application
โ โโโ ๐ public/ # Static assets
โ โ โโโ index.html # HTML template
โ โโโ ๐ src/ # Source code
โ โ โโโ ๐ components/ # Reusable UI components
โ โ โ โโโ Layout.js # Main layout component
โ โ โ โโโ NoteCard.js # Note display component
โ โ โ โโโ NoteModal.js # Note creation/edit modal
โ โ โ โโโ ProtectedRoute.js # Route protection wrapper
โ โ โโโ ๐ contexts/ # React Context providers
โ โ โ โโโ AuthContext.js # Authentication state
โ โ โ โโโ NotesContext.js # Notes state management
โ โ โโโ ๐ pages/ # Page components
โ โ โ โโโ Dashboard.js # Main dashboard
โ โ โ โโโ Login.js # Login page
โ โ โ โโโ Notes.js # Notes management page
โ โ โ โโโ Settings.js # User settings page
โ โ โโโ App.js # Main App component
โ โ โโโ index.js # Application entry point
โ โ โโโ index.css # Global styles
โ โโโ package.json # Frontend dependencies
โ โโโ tailwind.config.js # Tailwind CSS configuration
โ โโโ vercel.json # Vercel deployment config
โ
โโโ ๐ server/ # Node.js Backend Application
โ โโโ ๐ middleware/ # Express middleware
โ โ โโโ auth.js # Authentication middleware
โ โโโ ๐ models/ # MongoDB models
โ โ โโโ Note.js # Note data model
โ โ โโโ Tenant.js # Tenant data model
โ โ โโโ User.js # User data model
โ โโโ ๐ routes/ # API route handlers
โ โ โโโ auth.js # Authentication routes
โ โ โโโ notes.js # Notes CRUD routes
โ โ โโโ subscription.js # Subscription management
โ โ โโโ tenants.js # Tenant management
โ โโโ ๐ services/ # Business logic services
โ โ โโโ subscriptionService.js # Subscription logic
โ โโโ ๐ utils/ # Utility functions
โ โ โโโ seedData.js # Database seeding
โ โโโ server.js # Express server setup
โ โโโ package.json # Backend dependencies
โ โโโ vercel.json # Vercel deployment config
โ
โโโ ๐ package.json # Root package configuration
โโโ ๐ README.md # Project documentation
โโโ ๐ LICENSE # MIT License
โโโ ๐ .gitignore # Git ignore rules
| Directory | Purpose | Key Files |
|---|---|---|
client/src/components/ |
Reusable UI components | Layout, NoteCard, NoteModal |
client/src/contexts/ |
State management | AuthContext, NotesContext |
client/src/pages/ |
Page-level components | Dashboard, Login, Notes, Settings |
server/models/ |
Database schemas | User, Note, Tenant models |
server/routes/ |
API endpoints | Authentication, CRUD operations |
server/middleware/ |
Express middleware | Authentication, validation |
server/services/ |
Business logic | Subscription management |
- Node.js (v16 or higher)
- MongoDB (local or cloud instance)
- npm or yarn package manager
- Git for version control
-
Clone the repository
git clone https://github.com/Kush-Varshney/SaaSNotes.git cd SaaSNotes -
Install dependencies
# Install root dependencies npm install # Install server dependencies cd server && npm install # Install client dependencies cd ../client && npm install
-
Environment Setup
Create
.envfile in theserverdirectory:NODE_ENV=development PORT=5000 MONGODB_URI=mongodb://localhost:27017/notes-saas JWT_SECRET=your-super-secret-jwt-key-change-this-in-production JWT_EXPIRE=7d CLIENT_URL=http://localhost:3000
Create
.envfile in theclientdirectory:REACT_APP_API_URL=http://localhost:5000/api
-
Database Setup
cd server node utils/seedData.js -
Start Development Servers
# From root directory - starts both frontend and backend npm run dev # Or start individually: npm run server # Backend only npm run client # Frontend only
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/health
All test accounts use the password: password
| Role | Tenant | Description | |
|---|---|---|---|
| admin@acme.test | Admin | Acme Corporation | Can invite users & manage subscriptions |
| user@acme.test | Member | Acme Corporation | Can only manage notes |
| admin@globex.test | Admin | Globex Corporation | Can invite users & manage subscriptions |
| user@globex.test | Member | Globex Corporation | Can only manage notes |
| Method | Endpoint | Description | Access | Request Body |
|---|---|---|---|---|
POST |
/api/auth/login |
User login | Public | {email, password} |
POST |
/api/auth/register |
Register new user | Admin only | {email, password, role} |
GET |
/api/auth/me |
Get current user profile | Authenticated | - |
PUT |
/api/auth/change-password |
Change password | Authenticated | {currentPassword, newPassword} |
POST |
/api/auth/refresh |
Refresh JWT token | Authenticated | - |
GET |
/api/auth/users |
Get all tenant users | Admin only | - |
| Method | Endpoint | Description | Access | Request Body |
|---|---|---|---|---|
POST |
/api/notes |
Create note | Authenticated | {title, content, tags} |
GET |
/api/notes |
List notes (paginated) | Authenticated | Query params |
GET |
/api/notes/:id |
Get single note | Authenticated | - |
PUT |
/api/notes/:id |
Update note | Authenticated | {title, content, tags} |
DELETE |
/api/notes/:id |
Delete note | Authenticated | - |
POST |
/api/notes/:id/archive |
Archive/unarchive note | Authenticated | - |
| Method | Endpoint | Description | Access | Request Body |
|---|---|---|---|---|
GET |
/api/subscription/usage |
Get usage statistics | Authenticated | - |
GET |
/api/subscription/plans |
Get available plans | Public | - |
POST |
/api/subscription/upgrade |
Upgrade subscription | Admin only | - |
POST |
/api/subscription/downgrade |
Downgrade subscription | Admin only | - |
| Method | Endpoint | Description | Access | Request Body |
|---|---|---|---|---|
GET |
/api/tenants/:slug |
Get tenant information | Authenticated | - |
POST |
/api/tenants/:slug/upgrade |
Upgrade to Pro | Admin only | - |
POST |
/api/tenants/:slug/downgrade |
Downgrade to Free | Admin only | - |
GET |
/api/tenants/:slug/stats |
Get tenant statistics | Admin only | - |
-
Backend Deployment
cd server npm install -g vercel vercel --prod -
Frontend Deployment
cd client vercel --prod -
Environment Variables (Set in Vercel Dashboard)
NODE_ENV=productionMONGODB_URI=<your-mongodb-connection-string>JWT_SECRET=<your-production-jwt-secret>CLIENT_URL=<your-frontend-url>
- Use MongoDB Atlas or another cloud MongoDB service
- Update
MONGODB_URIin your Vercel environment variables - Run the seed script against production database (optional)
- โ JWT token authentication with secure secrets
- โ Password hashing using bcrypt (12 rounds)
- โ Input validation and sanitization
- โ Rate limiting (100 requests per 15 minutes)
- โ CORS configuration
- โ Helmet security headers
- โ Tenant isolation middleware
- โ Role-based access control
- โ SQL injection prevention
- โ XSS protection
- Use strong, unique JWT secrets
- Enable MongoDB authentication
- Use HTTPS in production
- Implement proper logging and monitoring
- Regular security audits
- Keep dependencies updated
- Implement proper error handling
- Set up monitoring and alerting
| Plan | Price | Notes Limit | Features | Support |
|---|---|---|---|---|
| Free | $0/month | 3 notes | Basic note editing, search, archive | Community |
| Pro | $9.99/month | Unlimited | All Free features + Priority support + Advanced features | Email + Priority |
-
Multi-tenancy Testing
- Login as different tenant users
- Verify data isolation between tenants
- Test cross-tenant access prevention
-
Subscription Testing
- Test Free plan limits (3 notes max)
- Test Pro plan upgrade/downgrade
- Verify admin-only subscription management
-
Role-based Access
- Test admin vs member permissions
- Verify user invitation functionality
- Test subscription management restrictions
-
Notes Functionality
- CRUD operations
- Search and filtering
- Archive/unarchive
- Tag management
MongoDB Connection Error
Symptoms: Server fails to start, database connection errors Solutions:
- Ensure MongoDB is running locally or check cloud connection
- Verify connection string in
.envfile - Check network connectivity and firewall settings
- Verify MongoDB credentials and permissions
CORS Errors
Symptoms: Frontend can't connect to backend, CORS policy errors Solutions:
- Check
CLIENT_URLin server.envfile - Verify frontend URL matches CORS configuration
- Ensure both servers are running on correct ports
Authentication Issues
Symptoms: Login fails, token errors, unauthorized access Solutions:
- Check JWT secret configuration in
.env - Verify token expiration settings
- Clear browser localStorage and cookies
- Check if user exists in database
Deployment Issues
Symptoms: Build failures, runtime errors in production Solutions:
- Ensure all environment variables are set in Vercel
- Check build logs for specific errors
- Verify API endpoints are accessible
- Test database connectivity in production
- Multi-tenant architecture
- User authentication and authorization
- Basic notes CRUD operations
- Subscription management
- Role-based access control
- Email notifications for subscription changes
- Advanced analytics dashboard
- Export functionality for notes
- Real-time collaboration features
- Mobile application (React Native)
- Advanced search with full-text indexing
- Audit logging for compliance
- Multi-language support
- API rate limiting per user
- Advanced reporting and insights
- SSO integration (SAML, OAuth)
- Advanced security features
- Custom branding per tenant
- White-label solutions
- Enterprise support
We welcome contributions! Please follow these steps:
-
Fork the repository
git clone https://github.com/Kush-Varshney/SaaSNotes.git cd SaaSNotes -
Create a feature branch
git checkout -b feature/amazing-feature
-
Make your changes
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
-
Commit your changes
git commit -m 'Add some amazing feature' -
Push to the branch
git push origin feature/amazing-feature
-
Open a Pull Request
- Follow the existing code style and conventions
- Add comprehensive tests for new features
- Update documentation and README as needed
- Ensure all tests pass before submitting
- Write clear commit messages
- Keep pull requests focused and atomic
Kush Varshney
B.Tech CSE | Full Stack Developer
- ๐ Education: B.Tech in Computer Science and Engineering
- ๐ป Specialization: Full Stack Development
- ๐ Expertise: MERN Stack, Cloud Computing, DevOps
- ๐ Passion: Building scalable web applications and open-source projects
This project is licensed under the MIT License - see the LICENSE file for details.
- ๐ Bug Reports: Create an issue
- ๐ก Feature Requests: Start a discussion
- ๐ง Contact: GitHub Profile
- ๐ Portfolio: kushvarshney
If you found this project helpful, please give it a โญ on GitHub!