Skip to content

shri-prakhar/second-brain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Second Brain - Personal Knowledge Management System 🧠

A sophisticated personal knowledge management system built with Node.js, Express, TypeScript, and MongoDB. This system allows users to store, organize, and interact with various types of content (articles, tweets, YouTube videos) using AI-powered features.

🌟 Features

Authentication & Authorization

  • Multiple Auth Methods:
    • JWT-based authentication
    • Google OAuth integration
    • Session-based authentication
    • Secure password hashing using bcrypt
  • Protected Routes: Middleware-based route protection
  • Cookie-based Sessions: Secure session management

Content Management

  • Multi-Content Support:
    • Articles with metadata extraction
    • Twitter posts
    • YouTube videos
    • Document links
  • AI-Powered Features:
    • Content summarization using LLaMA2
    • Smart content analysis
    • URL metadata extraction

Organization & Sharing

  • Tag Management System:
    • Create and manage custom tags
    • Tag-based content organization
    • Tag filtering and search
  • Content Sharing:
    • Share multiple items
    • Custom share messages
    • Time-based share expiry
    • Share count tracking

User Management

  • User Profiles:
    • Profile customization
    • Bio and profile picture
    • Saved items management
  • Learning Progress:
    • Track reading/watching progress
    • Interest management
    • AI-powered recommendations

πŸ› οΈ Technical Architecture

Backend Structure

src/
β”œβ”€β”€ config/           # Configuration setup
β”‚   β”œβ”€β”€ connection.ts     # Database connection
β”‚   β”œβ”€β”€ openai.config.ts  # AI configuration
β”‚   └── passport.ts       # Auth configuration
β”œβ”€β”€ controllers/      # Request handlers
β”‚   β”œβ”€β”€ ai.controller.ts
β”‚   β”œβ”€β”€ auth.controllers.ts
β”‚   β”œβ”€β”€ savedItems.controller.ts
β”‚   β”œβ”€β”€ shared.controller.ts
β”‚   └── tag.controller.ts
β”œβ”€β”€ middlewares/      # Custom middlewares
β”‚   └── auth.middlewares.ts
β”œβ”€β”€ models/          # Database schemas
β”‚   └── db.ts       # MongoDB models
β”œβ”€β”€ routes/          # API routes
β”‚   β”œβ”€β”€ ai.routes.ts
β”‚   β”œβ”€β”€ auth.routes.ts
β”‚   β”œβ”€β”€ savedItems.routes.ts
β”‚   β”œβ”€β”€ shared.routes.ts
β”‚   └── tag.routes.ts
β”œβ”€β”€ services/        # Business logic
β”œβ”€β”€ utils/           # Helper functions
β”œβ”€β”€ validations/     # Input validation
β”œβ”€β”€ app.ts          # Express app setup
└── server.ts       # Server entry point

Database Schema

User Model

interface User {
  name: string
  email: string
  password?: string
  authprovider: "email" | "googleId"
  profilePicture: string
  bio?: string
  savedItems: Types.ObjectId[]
  createdAt: Date
  updatedAt: Date
}

SavedItems Model

interface SavedItems {
  user: Types.ObjectId
  title: string
  url: string
  description: string
  tags: string[]
  folder?: string
  aiSummary?: string
  sharedCount: number
  createdAt: Date
  updateAt: Date
}

SharedItems Model

interface SharedItems {
  User: Types.ObjectId
  savedItems: Types.ObjectId[]
  shareId: string
  message?: string
  createdAt: Date
  expiresAt?: Date
}

πŸš€ API Endpoints

Authentication

  • POST /api/auth/signup - User registration
  • POST /api/auth/signin - User login
  • POST /api/auth/logout - User logout
  • GET /api/auth/google - Google OAuth login
  • GET /api/auth/google/callback - Google OAuth callback
  • GET /api/auth/me - Get current user

Saved Items

  • POST /items/addItem - Save new content
  • GET /items/getItem - Get saved items
  • PUT /items/updateItem/:id - Update saved item
  • DELETE /items/deleteItem/:id - Delete saved item

Tags

  • POST /tags/addTag - Create new tag
  • GET /tags/getTags - Get all tags
  • DELETE /tags/deleteTag/:name - Delete tag

AI Features

  • GET /ai/getSummary/:id - Get AI summary of content

Sharing

  • POST /share/shareItems - Share multiple items

πŸ”§ Installation & Setup

  1. Clone the repository
git clone <repository-url>
cd second-brain
  1. Install dependencies
npm install
  1. Environment Setup Create a .env file with:
PORT=5000
URL=<mongodb-connection-url>
JWT_SECRET=<your-jwt-secret>
GOOGLE_CLIENT_ID=<your-google-client-id>
GOOGLE_CLIENT_SECRET=<your-google-client-secret>
CLIENT_URL=http://localhost:3000
  1. Start Development Server
npm run dev
# or with auto-reload
npm run dev:watch
  1. Build for Production
npm run build
npm start

πŸ§ͺ Development Commands

npm run build          # Build TypeScript files
npm run start         # Start production server
npm run dev          # Start development server
npm run dev:watch    # Start development server with auto-reload
npm run lint         # Run ESLint
npm run lint:fix     # Fix ESLint issues
npm run format       # Format code with Prettier
npm run clean       # Clean build directory

πŸ” Security Features

  1. Authentication Security:

    • JWT token encryption
    • Secure password hashing
    • HTTP-only cookies
    • Session management
  2. Request Security:

    • CORS configuration
    • Input validation using Zod
    • MongoDB injection prevention
    • Request sanitization
  3. Data Protection:

    • Encrypted user data
    • Secure cookie handling
    • Protected routes middleware

πŸ› οΈ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • Database: MongoDB with Mongoose
  • Authentication: JWT, Passport.js
  • Validation: Zod
  • AI Integration: LLaMA2
  • Other Tools:
    • Bcrypt for password hashing
    • Cheerio for web scraping
    • Axios for HTTP requests
    • CORS for cross-origin requests
    • Helmet for security headers

πŸ“ Environment Variables

PORT=5000                    # Server port
URL=                        # MongoDB connection URL
JWT_SECRET=                 # JWT secret key
GEN_SALT=                   # Password hashing salt rounds
GOOGLE_CLIENT_ID=          # Google OAuth client ID
GOOGLE_CLIENT_SECRET=      # Google OAuth client secret
CLIENT_URL=                # Frontend application URL

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

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


Built with ❀️ using Node.js, Express, TypeScript, and MongoDB

About

Second Brain - Personal Knowledge Management System

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors