Skip to content

Idea stash is an application designed to help you capture, organize, and connect your ideas, notes, and knowledge in a structured yet flexible way.

Notifications You must be signed in to change notification settings

rajankit3107/idea-stash-server

Repository files navigation

Brain Dump Backend

A Node.js/Express backend API for a brain dump application that allows users to store, manage, and share their content with others. Built with TypeScript, MongoDB, and JWT authentication.

πŸš€ Features

  • User Authentication: Sign up and sign in with JWT token-based authentication
  • Content Management: Create, retrieve, and delete content with titles and links
  • Sharing System: Generate shareable links to share your brain dump with others
  • Data Validation: Input validation using Zod schema validation
  • TypeScript: Full TypeScript support for better development experience
  • MongoDB: NoSQL database for flexible data storage

πŸ› οΈ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens)
  • Validation: Zod
  • Environment: dotenv
  • Development: Nodemon, ESLint, Prettier

πŸš€ Installation

  1. Clone the repository

    git clone <repository-url>
    cd brain-dump-backend
  2. Install dependencies

    npm install
  3. Environment Setup Create a .env file in the root directory:

    MONGODB_URI=your_mongodb_connection_string
    JWT_SECRET=your_jwt_secret_key
  4. Build and Run

    # Development mode
    npm run dev
    
    # Production mode
    npm run build
    npm start

The server will start on http://localhost:3000

πŸ“š API Documentation

Base URL

http://localhost:3000/api/v1

Authentication Endpoints

POST /signup

Create a new user account.

Request Body:

{
  "username": "string (3-13 characters)",
  "password": "string"
}

Response:

{
  "message": "user created successfully"
}

POST /signin

Authenticate user and get JWT token.

Request Body:

{
  "username": "string",
  "password": "string"
}

Response:

{
  "token": "jwt_token_here"
}

Content Management Endpoints

POST /content

Create new content (requires authentication).

Headers:

Authorization: Bearer <jwt_token>

Request Body:

{
  "title": "string",
  "link": "string"
}

Response:

{
  "message": "Content Added"
}

GET /content

Get all content for authenticated user.

Headers:

Authorization: Bearer <jwt_token>

Response:

{
  "content": [
    {
      "_id": "content_id",
      "title": "string",
      "link": "string",
      "tags": [],
      "userId": {
        "_id": "user_id",
        "username": "string"
      },
      "createdAt": "date",
      "updatedAt": "date"
    }
  ]
}

Sharing Endpoints

POST /share

Create or delete shareable link (requires authentication).

Headers:

Authorization: Bearer <jwt_token>

Request Body:

{
  "share": true // true to create, false to delete
}

Response:

{
  "createdlink": {
    "_id": "link_id",
    "hash": "random_hash_string",
    "userId": "user_id",
    "createdAt": "date",
    "updatedAt": "date"
  }
}

GET /share/:shareLink

Get shared content by hash link.

Parameters:

  • shareLink: The hash string from the share link

Response:

{
  "username": "string",
  "content": [
    {
      "_id": "content_id",
      "title": "string",
      "link": "string",
      "tags": [],
      "userId": "user_id",
      "createdAt": "date",
      "updatedAt": "date"
    }
  ]
}

πŸ—„οΈ Database Schema

User Model

{
  username: String (required, unique),
  password: String (required),
  createdAt: Date,
  updatedAt: Date
}

Content Model

{
  title: String (required),
  link: String (required),
  tags: [ObjectId] (references Tag model),
  userId: ObjectId (required, references User model),
  createdAt: Date,
  updatedAt: Date
}

Link Model

{
  hash: String,
  userId: ObjectId (required, references User model),
  createdAt: Date,
  updatedAt: Date
}

πŸ”§ Project Structure

brain-dump-backend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config.ts              # Database configuration
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   └── controllers.ts     # API route handlers
β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   └── middleware.ts      # JWT authentication middleware
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── model.ts          # MongoDB schemas
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── routes.ts         # API route definitions
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── random-string-generator.ts  # Utility functions
β”‚   β”œβ”€β”€ validators/
β”‚   β”‚   └── validators.ts     # Zod validation schemas
β”‚   └── index.ts              # Server entry point
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md

πŸš€ Available Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm start - Start the production server
  • npm run dev - Build and start in development mode with nodemon

πŸ” Security Features

  • JWT-based authentication
  • Input validation using Zod
  • Password hashing (implemented in user model)
  • Protected routes with middleware
  • Environment variable configuration

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some 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 ISC License.

About

Idea stash is an application designed to help you capture, organize, and connect your ideas, notes, and knowledge in a structured yet flexible way.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published