Skip to content

Latest commit

ย 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ SaaSNotes

License: MIT Node.js Version React Version MongoDB Express.js TypeScript Tailwind CSS

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.

๐Ÿ“‹ Table of Contents

๐ŸŒŸ Features

๐Ÿ” Authentication & Security

  • 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

๐Ÿข Multi-Tenancy

  • 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

๐Ÿ’ณ Subscription 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

๐Ÿ“ Notes Management

  • 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

๐ŸŽจ User Interface

  • Responsive design with Tailwind CSS
  • Modern UI components with Radix UI
  • Dark/Light theme support
  • Mobile-first approach
  • Accessibility compliant

๐Ÿ—๏ธ Architecture

Multi-Tenancy Strategy

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 tenantId field for data segregation
  • Security: Middleware ensures users can only access their tenant's data
  • Scalability: Efficient resource utilization while maintaining data isolation

Tech Stack

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

๐Ÿ“ Project Structure

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

๐Ÿ“‚ Key Directories Explained

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

๐Ÿš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (local or cloud instance)
  • npm or yarn package manager
  • Git for version control

Installation

  1. Clone the repository

    git clone https://github.com/Kush-Varshney/SaaSNotes.git
    cd SaaSNotes
  2. Install dependencies

    # Install root dependencies
    npm install
    
    # Install server dependencies
    cd server && npm install
    
    # Install client dependencies
    cd ../client && npm install
  3. Environment Setup

    Create .env file in the server directory:

    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 .env file in the client directory:

    REACT_APP_API_URL=http://localhost:5000/api
  4. Database Setup

    cd server
    node utils/seedData.js
  5. 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

๐ŸŒ Access Points

๐Ÿ‘ฅ Test Accounts

All test accounts use the password: password

Email 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

๐Ÿ“š API Documentation

Authentication Endpoints

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 -

Notes Management

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 -

Subscription Management

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 -

Tenant Management

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 -

๐Ÿš€ Deployment

Vercel Deployment

  1. Backend Deployment

    cd server
    npm install -g vercel
    vercel --prod
  2. Frontend Deployment

    cd client
    vercel --prod
  3. Environment Variables (Set in Vercel Dashboard)

    • NODE_ENV=production
    • MONGODB_URI=<your-mongodb-connection-string>
    • JWT_SECRET=<your-production-jwt-secret>
    • CLIENT_URL=<your-frontend-url>

Database Setup (Production)

  • Use MongoDB Atlas or another cloud MongoDB service
  • Update MONGODB_URI in your Vercel environment variables
  • Run the seed script against production database (optional)

๐Ÿ”’ Security Features

Implemented Security Measures

  • โœ… 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

Production Security Checklist

  • 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

๐Ÿ“Š Subscription Plans

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

๐Ÿงช Testing

Manual Testing Scenarios

  1. Multi-tenancy Testing

    • Login as different tenant users
    • Verify data isolation between tenants
    • Test cross-tenant access prevention
  2. Subscription Testing

    • Test Free plan limits (3 notes max)
    • Test Pro plan upgrade/downgrade
    • Verify admin-only subscription management
  3. Role-based Access

    • Test admin vs member permissions
    • Verify user invitation functionality
    • Test subscription management restrictions
  4. Notes Functionality

    • CRUD operations
    • Search and filtering
    • Archive/unarchive
    • Tag management

๐Ÿ› Troubleshooting

Common Issues

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 .env file
  • 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_URL in server .env file
  • 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

๐Ÿ›ฃ๏ธ Roadmap

Phase 1 - Core Features โœ…

  • Multi-tenant architecture
  • User authentication and authorization
  • Basic notes CRUD operations
  • Subscription management
  • Role-based access control

Phase 2 - Enhanced Features ๐Ÿšง

  • Email notifications for subscription changes
  • Advanced analytics dashboard
  • Export functionality for notes
  • Real-time collaboration features
  • Mobile application (React Native)

Phase 3 - Advanced Features ๐Ÿ“‹

  • Advanced search with full-text indexing
  • Audit logging for compliance
  • Multi-language support
  • API rate limiting per user
  • Advanced reporting and insights

Phase 4 - Enterprise Features ๐Ÿ”ฎ

  • SSO integration (SAML, OAuth)
  • Advanced security features
  • Custom branding per tenant
  • White-label solutions
  • Enterprise support

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository

    git clone https://github.com/Kush-Varshney/SaaSNotes.git
    cd SaaSNotes
  2. Create a feature branch

    git checkout -b feature/amazing-feature
  3. Make your changes

    • Follow the existing code style
    • Add tests for new features
    • Update documentation as needed
  4. Commit your changes

    git commit -m 'Add some amazing feature'
  5. Push to the branch

    git push origin feature/amazing-feature
  6. Open a Pull Request

Development Guidelines

  • 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

๐Ÿ‘ค Author

Kush Varshney
B.Tech CSE | Full Stack Developer

Portfolio GitHub LinkedIn

About the Author

  • ๐ŸŽ“ 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

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ž Support

โญ Show Your Support

If you found this project helpful, please give it a โญ on GitHub!


Built with โค๏ธ using the MERN stack

Made with React Made with Node.js Made with MongoDB Made with Express Made with TypeScript

About

A multi-tenant SaaS notes application built with MERN stack featuring JWT authentication, subscription management, and complete data isolation between tenants.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages