This project is a blog website built using Flask, featuring authentication and role-based access control (RBAC). The system supports three distinct roles: Admin, Author, and Reader, each with specific permissions.
- Full control over all blog posts (view, edit, delete).
- Manage users (promote users to Author or Admin roles).
- Access to user management features.
- Can create, view, edit, and delete their own blog posts.
- Has access to a customized interface to manage personal blog posts.
- Can view all published blog posts.
- Can like or dislike posts and see the number of likes/dislikes on each post.
- Users can register and login.
- Session-based or token-based authentication is used.
- Upon registration, users are automatically assigned the Reader role.
- Only Admins can promote users to Author or Admin roles.
- Admins can manage all posts (view, edit, delete any post).
- Authors can manage only their own posts.
- Readers can view all published posts and like/dislike them.
The project implements two database layers to demonstrate both SQL and NoSQL capabilities:
- SQL Database (e.g., SQLite, PostgreSQL, MySQL) for structured data such as blog posts and user roles.
- MongoDB (NoSQL) as an alternative layer to handle the same data.
- Flask: Web framework for building the application.
- Flask-Login: For user session management.
- Flask-SQLAlchemy: For interacting with the SQL database.
- MongoEngine: For interacting with MongoDB.
- Bootstrap: For responsive UI design.
Make sure you have the following installed:
- Python 3.x
- Virtualenv
- MongoDB
- SQLite Database
-
Clone the repository:
git clone https://github.com/nada-086/Blogger cd Blogger
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
-
Configure the database:
- For the SQL database, update the SQLALCHEMY_DATABASE_URI in the config.py file.
- For MongoDB, ensure that MongoDB is running and update the MONGO_URI in config.py.
-
Run the Application:
flask run
-
Access the website: Open your browser and go to
http://127.0.0.1:5000
- Add pagination for viewing blog posts.
- Implement search functionality for posts.
- Add comment section for readers to comment on blog posts.
.
├── app/ # Main application directory
│ ├── routes/ # Flask route handlers
│ │ └── user.py
│ │ └── blog.py
│ ├── models/ # Database models
│ │ ├── sql/ # SQL models (SQLAlchemy)
│ │ │ └── user.py # SQL model for users
│ │ │ └── blog.py
│ │ │ └── blog_action.py
│ │ └── mongo/ # MongoDB models (PyMongo)
│ │ └── blog.py # MongoDB model for blogs
│ │ └── user.py
│ │ └── blog_action.py
│ ├── services/ # Service layer for business logic
│ │ ├── blog/ # Blog-related services
│ │ │ └── factory.py
│ │ │ └── mongo.py
│ │ │ └── sql.py
│ │ └── user/ # User-related services
│ │ └── factory.py
│ │ └── mongo.py
│ │ └── sql.py
│ ├── templates/ # HTML templates for rendering views
│ │ ├── user/ # User-related templates
│ │ │ └── profile.html # User profile template
│ │ │ └── login.html
│ │ │ └── signup.html
│ │ │ └── user-management.hmtl
│ │ │ └── blog-management.html
│ │ ├── navbar/ # Navbar templates
│ │ │ └── admin.html
│ │ │ └── reader.html
│ │ └── blog/ # Blog-related templates
│ │ └── view.html # Single blog post view template
│ │ └── create.html
│ │ └── list.html
│ │ └── edit.html
│ ├── __init__.py # App initialization and configurations
├── .gitignore # Files to ignore in Git version control
├── README.md # Readme file with project information (this file)
├── main.py # Main entry point to run the Flask application
├── .env # Environment variables (e.g., API keys, DB URIs)
├── config.py # Configuration settings (database URIs, secret keys)
├── requirements.txt # List of Python dependencies