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.
- Features
- Technologies
- Architecture
- Project Structure
- Installation
- Configuration
- Running the Application
- API Documentation
- Testing
- Cron Jobs
- Rate Limiting
- Known Issues
- Contributing
- License
- 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.
- Backend: Node.js, Express.js, Sequelize ORM
- Frontend: Vue.js
- Database: MySQL
- Documentation: Swagger
- Task Scheduling: node-cron
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.
├── 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
Clone the repository:
git clone https://github.com/your-username/tweetai.git cd tweetai
npm install
create a .env file and add the following port FRONT_END_PORT PORT //Backend Port
Create a MySQL database named tweetai. You can customize the database name in the config/db.config.js file.
Configuration Database Configuration: Update the config/db.config.js file with your MySQL database credentials.
You can adjust the rate limiting settings in the config/rateLimiter.js file.
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}.
create .env file and add PORT variable To run the application in production mode: npm start
The API is documented using Swagger. Once the application is running, you can view the documentation at:
http://localhost:3000/api-docs
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.
To run the tests for this project:
npm test Make sure you have set up your testing environment correctly before running the tests.
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(); });
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.
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.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
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
This project is licensed under the MIT License. See the LICENSE file for more details.