Giter Site home page Giter Site logo

communitybe's Introduction

Project Documentation: CommunityBE

Introduction

CommunityBE is a backend setup project that serves as the backend infrastructure for a community-based application. It provides API endpoints for managing users and posts within the community platform.

Setup

Prerequisites

Installation

  1. Clone the repository from GitHub.
  2. Navigate to the project directory in your terminal.
  3. Run npm install to install dependencies.

Configuration

Environment Variables

This project utilizes environment variables for configuration. Create a .env file in the root directory of the project and define the following variables:

You can copy and paste this Markdown directly into your documentation. It will render as follows:


Configuration

Environment Variables

This project utilizes environment variables for configuration. Create a .env file in the root directory of the project and define the following variables:

PORT=8000
MONGODB_URI=mongodb://localhost:27017/community_db

Usage

Starting the Server

To start the server, use one of the following npm scripts:

  • npm start: Starts the server using Node.js.
  • npm run server: Starts the server using Nodemon for automatic restarts during development.

API Endpoints

Users

  • GET /api/users: Get a list of all users.
  • GET /api/users/:id: Get details of a specific user by ID.

Posts

  • GET /api/posts: Get a list of all posts.

File Structure

The project follows the following directory structure:

Directory Structure

communitybe/

│
├── backend/
│ ├── config/
│ │ └── db.js
│ ├── middleware/
│ │ └── errorMiddleware.js
│ ├── routes/
│ │ ├── postRoutes.js
│ │ └── userRoutes.js
│ ├── controllers/
│ │ ├── postController.js
│ │ └── userController.js
│ └── server.js
│
├── models/
│ ├── Post.js
│ └── User.js
│
├── .env
├── package.json
└── README.md

Database Schema

User Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const userSchema = new Schema(
  {
    name: {
      type: String,
      required: true,
    },
    email: {
      type: String,
      required: true,
      unique: true,
    },
    password: {
      type: String,
      required: true,
    },
  },
  { timestamps: true }
);

const User = mongoose.model('User', userSchema);

module.exports = User;

Post Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const postSchema = new Schema(
  {
    title: {
      type: String,
      required: true,
    },
    content: {
      type: String,
      required: true,
    },
  },
  { timestamps: true }
);

const Post = mongoose.model('Post', postSchema);

module.exports = Post;

This Markdown representation will display the Post Schema code snippet with proper syntax highlighting and formatting:


Post Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const postSchema = new Schema(
  {
    title: {
      type: String,
      required: true,
    },
    content: {
      type: String,
      required: true,
    },
  },
  { timestamps: true }
);

const Post = mongoose.model('Post', postSchema);

module.exports = Post;

API Documentation

User Routes

  • GET /api/users

    • Description: Retrieves a list of all users.
    • Controller: userController.getUsers
  • GET /api/users/:id

    • Description: Retrieves details of a specific user by ID.
    • Controller: userController.getUserById

Post Routes

  • GET /api/posts
    • Description: Retrieves a list of all posts.
    • Controller: postController.getPosts

Dependencies

  • cors: ^2.8.5
  • dotenv: ^16.4.5
  • express: ^4.19.2
  • express-async-handler: ^1.2.0
  • mongodb: ^6.6.1
  • mongoose: ^8.3.4
  • nodemon: ^3.1.0

Author

  • Katiuska

License

This project is licensed under the MIT License.

communitybe's People

Contributors

chukalicious avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.