Skip to content

Latest commit

 

History

History
279 lines (140 loc) · 6.44 KB

README.md

File metadata and controls

279 lines (140 loc) · 6.44 KB

Design Document: Personal Blogging Platform API

1. Overview

This document outlines the design of a Personal Blogging Platform API that allows users to create, read, update, and delete blog posts. The API will support features like user authentication, categorization of posts, comments, and tags. The backend will be scalable, and secure, and support efficient data retrieval.

2. Goals

  • Provide a RESTful API for creating, managing, and interacting with blog posts.

  • Ensure secure user authentication and authorization.

  • Allow for rich content creation with support for tags, categories, and comments.

  • Enable efficient search and filtering of posts.

  • Provide scalable and modular design for future enhancements.

3. Non-goals

  • Frontend development (focus will be on API backend).

  • Real-time comment updates (to be handled in future iterations).

4. Technology Stack

  • Backend Framework: Node.js with Express.js

  • Database: MongoDB (NoSQL) or PostgreSQL (SQL)

  • Authentication: JSON Web Tokens (JWT)


5. API Requirements

5.1. User Management

  • Signup: Register new users with email, username, and password.

  • Login: Authenticate users and provide a JWT token.

  • Profile Management: Allow users to update their profile (e.g., avatar, bio).

5.2. Blog Post Management

  • Create Post: Authenticated users can create new blog posts (title, content, category, tags).

  • Edit Post: Authenticated users can edit their posts.

  • Delete Post: Authenticated users can delete their posts.

  • Get All Posts: Publicly accessible to get a list of all published posts (pagination).

  • Get Post by ID: Publicly accessible to retrieve a single post based on its unique ID.

5.3. Category and Tag Management

  • Create Category: Admin users can create categories.

  • Assign Tags: Users can assign multiple tags to posts.

  • Search Posts by Tag/Category: Users can filter posts based on tags or categories.

5.4. Comments

  • Add Comment: Authenticated users can comment on blog posts.

  • Delete Comment: Users can delete their comments.

  • Edit Comment: Users can edit their comments.

  • Get Comments for a Post: Retrieve all comments for a given blog post.


6. Database Schema Design

6.1. Users

{

  "_id": ObjectId,

  "username": String,

  "email": String,

  "passwordHash": String,

  "bio": String,

  "salt" : String,

  "role": String, // admin or user

  "createdAt": Date,

  "updatedAt": Date

}

6.2. Blog Posts

{

  "_id": ObjectId,

  "title": String,

  "content": String,

  "author": ObjectId (User),

  "category": ObjectId (Category),

  "tags": [ObjectId (Tag)],

  "createdAt": Date,

  "updatedAt": Date,

  "comments": [ObjectId (Comment)]

}

6.3. Comments

{

  "_id": ObjectId,

  "postId": ObjectId (Post),

  "author": ObjectId (User),

  "content": String,

  "createdAt": Date,

  "updatedAt": Date

}

6.4. Categories

{

  "_id": ObjectId,

  "name": String,

  "description": String,

  "createdAt": Date

}

6.5. Tags

{

  "_id": ObjectId,

  "name": String

}

7. Authentication & Authorization

  • JWT-based Authentication: Upon successful login, the user will receive a JWT token which they must provide in the Authorization header for future requests.

  • Role-based Access: Admins have higher privileges (e.g., managing categories). Users can manage their blog posts and comments.


8. API Endpoints

8.1. User Endpoints

  • POST /api/v1/user/signup: Register a new user.

  • POST /api/v1/user/login: Login and retrieve JWT token.

  • PUT /api/v1/user/profile: Update user profile (auth required).

  • DELETE /api/v1/user/delete: Delete user profile (either the admin or the user itelf)

8.2. Blog Post Endpoints

  • POST /api/v1/blogs: Create a new post (auth required).

  • GET /api/v1/blogs: Get a list of all blogs (public, with pagination).

  • GET /api/v1/blogs/:id: Get a specific post by ID (public).

  • PUT /api/v1/blogs/:id: Update a post (auth required, owner only).

  • DELETE /api/v1/blogs/:id: Delete a post (auth required, owner only).

  • GET /api/v1/blogs/author/:authorName: Get all blogs by a specific author.

  • GET /api/v1/blogs/tag/:tagName: Get all blogs by a specific tag.

  • GET /api/v1/blogs/category/:categoryName: Get all blogs by a specific category.

8.3. Category & Tag Endpoints

  • POST /api/v1/categories: Create a new category (admin only).

  • GET /api/v1/categories: Get all categories.

  • POST /api/v1/tags: Create a new tag (admin only).

  • GET /api/v1/tags: Get all tags.

8.4. Comment Endpoints

  • POST /api/v1/posts/:id/comments: Add a comment to a post (auth required).

  • PUT /api/v1/comments/:id: Edit a comment (auth required, owner only).

  • DELETE /api/v1/comments/:id: Delete a comment (auth required, owner only).


9. Security

  • Password Hashing: Store password hashes using bcrypt.

  • Authentication: Use JWT with a secure secret key.

  • Role-based Access Control: Only admins can perform certain actions (e.g., managing categories).


10. Deployment & Scaling

  • Containerization: Use Docker to containerize the application.

  • CI/CD: Setup automated CI/CD pipelines for deployment to AWS or similar cloud services.

  • Horizontal Scaling: API should be stateless, allowing multiple instances to handle large traffic.

  • Database Indexing: Use indexes on frequently queried fields (e.g., post titles, tags).


11. Future Enhancements

  • Real-time comments: Use WebSockets to provide live updates for comments.

  • Likes/Dislikes: Allow users to like/dislike blog posts.

12. Conclusion

This design provides a robust API for a personal blogging platform, enabling rich content management and user interactions while maintaining security and scalability. The modular approach allows for future feature additions without major architectural changes.