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
![Screen Shot - Community Hub](https://private-user-images.githubusercontent.com/53020383/288119976-3e65c5a2-dd6c-44d6-9c06-0a1dbac2a82a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5NjM4NDcsIm5iZiI6MTcyNTk2MzU0NywicGF0aCI6Ii81MzAyMDM4My8yODgxMTk5NzYtM2U2NWM1YTItZGQ2Yy00NGQ2LTljMDYtMGExZGJhYzJhODJhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDEwMTkwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwYTE1YmRlMDBjOWRkMjg1ZWQ5ZWMwNGRiZjEwMGZlOTQ1OGJkMzYxMWU2Y2U0NDRhMTUzOWIxNDRhZDM2MmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.JFSxi_S6L2R3ly4t0vKdY1IkK0yptCnxCk3Wm55ZO6U)