Skip to content

DevBlogs : A blogging website made for developers by developers. This repository contains the backend for the project

License

Notifications You must be signed in to change notification settings

MLSAKIIT/devblogs-backend

Repository files navigation

DevBlogs Backend

Overview

This is the backend API for DevBlogs, a Full Stack Blogging site for Developers by Developers. It's part of the MLSA HACKTOBER 2024: WEBDEV project.

Tech Stack

  • Express.js as the web application framework
  • MongoDB for database management
  • Mongoose for MongoDB object modeling
  • JSON Web Tokens (JWT) for authentication
  • Swagger for API documentation

Features

  1. User authentication and authorization
  2. Blog post creation and retrieval
  3. Pagination for blog posts
  4. Request body validation
  5. Rate limiting
  6. CORS protection
  7. API documentation with Swagger

Prerequisites

  • Node.js
  • npm or yarn
  • MongoDB

Getting Started

  1. Clone the repository to your local machine.
  2. Navigate to the backend directory of the project.
  3. Install the required dependencies:
    npm install
    
    or
    yarn install
    
  4. Set up your environment variables:
    • Create a .env file in the backend directory.
    • Add necessary variables such as MONGODB_URI and JWT_SECRET.
  5. Start the server:
    npm run dev
    
    or
    yarn dev
    
  6. The backend should now be running, typically on http://localhost:3000.
  7. Access the Swagger documentation at http://localhost:3000/api-docs.

Installation with Docker

  1. Clone the repository:

    git clone https://github.com/MLSAKIIT/devblogs-backend.git
  2. Navigate to the project directory:

    cd devblogs-backend
  3. Configure your .env file:

    Before running Docker, ensure you have correctly set up your environment variables.

  4. Run the following command to start the application:

    docker compose up -d   

Folder Structure

.
└── src/
    ├── controllers/
    │   ├── auth.js
    │   └── blog.js
    ├── index.js
    ├── middlewares/
    │   ├── errorHandler.js
    │   └── verifyTokenMiddleware.js
    ├── models/
    │   ├── Blogs.js
    │   └── User.js
    ├── routes/
    │   ├── auth.js
    │   ├── blog.js
    │   └── verify.js
    ├── utils/
    │   ├── jwtHelper.js
    │   └── rateLimit.js
    └── validators/
        ├── login.js
        └── register.js

API Routes

  • /register: User registration
  • /login: User login
  • /verify: Verify JWT token
  • /change-password: Change user password
  • /get-blogs: Retrieve blog posts (with pagination)
  • /create-blog: Create a new blog post (protected route)
  • /get-featured-blog: Retrieve featured blog posts

For detailed API documentation, refer to the Swagger UI at /api-docs when the server is running.

Contributing

We welcome contributions to improve this project! Here's how you can contribute:

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

Issues & Features

  • User authentication with hashed passwords.
  • Input validation with joi.
  • Rate limiting and CORS protection.
  • Route protection using middleware.
  • Swagger for API documentation.
  • Error handling middleware.

Check the main project documentation for a list of current issues and tasks for the backend.

References