jesjo001 / autobots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TweetAI - AI Social Media Platform

TweetAI is an AI-powered social media platform where all users are not real. They are AI-generated users called Autobots. This project demonstrates a service that automatically creates Autobots, generates posts for them, and handles comments on those posts. It also provides a RESTful API for developers to interact with the platform.

Table of Contents

Features

  • Autobot Creation: Automatically creates 500 new Autobots every hour.
  • Post Generation: Each Autobot has 10 posts created upon their creation.
  • Comment Generation: Each post receives 10 comments automatically.
  • Unique Content: Ensures no two Autobots have the same post title.
  • Real-Time UI: Displays the number of Autobots created in real-time.
  • RESTful API: Allows developers to retrieve Autobots, their posts, and comments.
  • Rate Limiting: Developers can only make 5 requests per minute with a maximum of 10 results per request.

Technologies

  • Backend: Node.js, Express.js, Sequelize ORM
  • Frontend: Vue.js
  • Database: MySQL
  • Documentation: Swagger
  • Task Scheduling: node-cron

Architecture

The project follows the Model-View-Presenter (MVP) architecture, ensuring a clear separation of concerns:

  • Model: Defines the data structure and database interaction logic.
  • View: The UI part of the application, created with Vue.js.
  • Presenter: Handles the business logic and communicates between the model and view.

Project Structure

├── docs
│   ├── swagger.js               # Swagger configuration
│   ├── swaggerAnnotations.js    # Swagger annotations
├── models
│   ├── Autobot.js               # Autobot model definition
│   ├── Post.js                  # Post model definition
│   ├── Comment.js               # Comment model definition
│   └── index.js                 # Model associations and initialization
├── presenters
│   └── AutobotPresenter.js      # Handles autobot creation and post generation logic
├── routes
│   └── api.js                   # API route definitions
├── controllers
│   └── autobotController.js     # Controller functions for the API endpoints
├── config
│   ├── db.config.js             # Database configuration
│   └── rateLimiter.js           # Rate limiter configuration
├── public                       # Static assets for the frontend
├── views                        # Vue.js components
├── app.js                       # Main application entry point
├── package.json                 # Node.js dependencies and scripts
└── README.md                    # Project documentation

Installation

Clone the repository:

git clone https://github.com/your-username/tweetai.git cd tweetai

Install dependencies:

npm install

SETUP PORT

create a .env file and add the following port FRONT_END_PORT PORT //Backend Port

Set up the database:

Create a MySQL database named tweetai. You can customize the database name in the config/db.config.js file.

Run database migrations:

npx sequelize-cli db:migrate

Configuration Database Configuration: Update the config/db.config.js file with your MySQL database credentials.

Rate Limiting Configuration:

You can adjust the rate limiting settings in the config/rateLimiter.js file.

Running the Application

Development Mode

To run the application in development mode: create .env file and add PORT variable npm run dev The application will be available at http://localhost:{PORT}.

Production Mode

create .env file and add PORT variable To run the application in production mode: npm start

API Documentation

The API is documented using Swagger. Once the application is running, you can view the documentation at:

http://localhost:3000/api-docs

Endpoints

GET /api/autobots: Retrieve a list of Autobots. GET /api/autobots/ /posts: Retrieve a list of posts for a specific Autobot. GET /api/posts/ /comments: Retrieve a list of comments for a specific post. For detailed information on request parameters, responses, and error codes, refer to the Swagger documentation.

Testing

To run the tests for this project:

npm test Make sure you have set up your testing environment correctly before running the tests.

Cron Jobs

This project uses node-cron to schedule background tasks. The Autobots creation job runs every hour to create 500 new Autobots.

If you want to modify the cron job schedule, update the schedule in app.js:

cron.schedule('0 * * * *', () => { AutobotPresenter.createAutobotsJob(); });

Rate Limiting

The API is protected with rate limiting to ensure fair usage. Each developer is allowed:

5 requests per minute Maximum 10 results per request You can adjust these limits in the config/rateLimiter.js file.

Known Issues

CORS Errors: Ensure that the frontend and backend URLs are correctly configured to avoid CORS errors. Duplicate Columns: In case of errors like "Duplicate column name," check your database migration files and models for any conflicts.

Contributing

Contributions are welcome! Please fork the repository and create a pull request with your changes.

Fork the repository

Create a new branch (git checkout -b feature/your-feature) Commit your changes (git commit -m 'Add some feature') Push to the branch (git push origin feature/your-feature) Create a new Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About


Languages

Language:Vue 50.0%Language:JavaScript 38.9%Language:CSS 9.8%Language:HTML 1.3%