This project is a social networking website developed using Flask, a micro web framework written in Python. The highlights of this project include various design patterns implemented to ensure a robust and maintainable application architecture.
-
Singleton Pattern:
- Implemented through
SingletonMeta
to ensure a single instance of theDatabaseConnection
class, managing a unique database connection efficiently.
- Implemented through
-
Model-View-Controller (MVC) Pattern:
- Model: The classes
User
,Post
, andRelationship
form the data model layer, managing users, posts, and relationships within the application. - The MVC pattern is implied here, focusing on the model aspect to separate data handling from presentation and control logic.
- Model: The classes
-
Object-Relational Mapping (ORM):
- Utilizes the
Peewee
ORM to map Python classes (User
,Post
,Relationship
) to database tables, abstracting database operations into object-oriented code for cleaner and more maintainable application logic.
- Utilizes the
-
Active Record Pattern:
- Each model class (
User
,Post
,Relationship
) extendsModel
, representing database rows with instances. This pattern provides methods for database operations like creation, reading, and querying directly on the model objects.
- Each model class (
-
Foreign Key Relationships:
- Establishes relationships between database tables using foreign keys. For example,
Post
links toUser
, andRelationship
links users to one another, enforcing referential integrity.
- Establishes relationships between database tables using foreign keys. For example,
-
Transaction Management:
- Handles database operations within transactions to maintain data integrity. This is especially evident in the
create_user
method, wheredatabase.transaction()
is used to ensure consistent database states.
- Handles database operations within transactions to maintain data integrity. This is especially evident in the
-
Query Filtering:
- Uses filtering and query chaining to retrieve specific subsets of data. Methods such as
get_posts
,following
, andfollowers
demonstrate efficient data retrieval based on user-specific queries.
- Uses filtering and query chaining to retrieve specific subsets of data. Methods such as
-
Indexing and Constraints:
- Uses unique constraints and indexes in the
Relationship
model to enforce data integrity and optimize query performance.
- Uses unique constraints and indexes in the
Before you begin, ensure you have the following requirements installed:
- Python version 2.7 or above
- Flask
- Peewee
- Flask-Login
- Flask-Bcrypt
- Flask-WTF
This is compatible with Mac OSX, Windows, and Linux operating systems.
Follow these steps to get your development environment running:
- Clone the repository (if you haven't already):
git clone https://github.com/aninda20/Community_Hub..git cd Community_Hub
Run in terminal to install required dependencies
pip install -r requirements.txt
Then run the following to start the server
python app.py
Open browser and go to
localhost:8000