This Social Media App is a Flask-based application designed to provide users with an engaging platform for seamless communication, content sharing, and interaction. It features essential functionalities such as user account management, direct messaging (DMs), and post creation. Built using Python, Flask, and MySQL, this app serves as a demonstration of modular application design and API integration for modern social media platforms.
-
User Account Management
- Users can create accounts, update their profiles, and manage their information.
- Passwords are securely stored using encryption mechanisms.
-
Posts
- Users can create, read, update, and delete (CRUD) posts.
- The app supports multimedia content integration for posts.
-
Direct Messaging (DMs)
- Users can send and receive direct messages.
- Users can also delete and edit a message that has already been sent.
-
Database Integration
- ata is stored in a MySQL database with tables for users, posts, and messages.
- SQLAlchemy is used for ORM (Object-Relational Mapping), making database operations efficient and secure.
-
API-Driven Design
- The app's endpoints are structured for easy integration with client-side applications or third-party systems.
- Postman is recommended for API testing and debugging.
-
Scalable Architecture
- The application is divided into modules: user_app, post_app, and message_app, making it easy to maintain and extend.
- Shared resources and configurations are managed centrally in the shared folder.
-
Real-Time Communication
- Implements WebSocket or polling-based communication (future improvement).
- Backend Framework: Flask (Python)
- Database: MySQL
- Frontend/API Testing: Postman
- Additional Libraries:
- SQLAlchemy for database management.
- Flask-Migrate for handling database migrations.
- Cryptography for secure password handling.
-
Python (3.8 or higher)
- Click for - How to install Python on Windows and MacOS both
-
MySQL LTS version (8.3 or higher version)
- Click for - how to install MySQL LTS version on windows
- Click for - how to install MySQL LTS version on MacOS
- NOTE : use simple passwords that only has characters and numbers while setting up the password for the MySQL to avoid descrepencies (DO NOT USE SPECIAL CHARACTERS)
-
Postman API application
- Click for - How to install Postman applciation on windows
- Click for - How to install Postman application on MacOS
-
pip installation
- Click for - How to install pip on command prompt
- Click for - How to install pip on terminal
-
GitHub Desktop
- Click for - How to install github desktop on Windows
- Click for - How to install github desktop on MacOS
- Open terminal
- Run:
mysql -u root -p
- Enter your MySQL password.
- Create the database:
create database social_media_app;
-
Locate the MySQL
bin
directory :- Navigate to
C:\Program Files\MySQL\MySQL Server X.X\bin
. - Copy the path.
- Navigate to
-
Add MySQL to path :
- Open System Environment Variables:
- Press
Windows + S
and search for Environment Variables.
- Press
- Under System Variables, edit the
Path
variable and add the copied MySQLbin
path.
- Open System Environment Variables:
-
Verify Installation :
- Open a new Command Prompt window and run :
mysql --version
- If successful, create the database :
mysql -u root -p create database social_media_app;
- Open a new Command Prompt window and run :
- Ensure GitHub CLI is installed -
- Windows: Pre-installed.
- macOS: Install using -
-
brew install github/gh/gh
-
- Verify installation -
-
github --version
- if it doesn't work, use -
gh --version
-
- Clone the repository:
git clone https://github.com/shr3yajaisal/social_media_app
- Open terminal.
- Navigate to your project folder -
- For Windows -
cd path\to\your\project
- For MacOS
cd path/to/your/project
- For Windows -
- Create the virtual environment -
# For both MacOS and Windows python -m venv venv OR python3 -m venv venv # In case you are using python3
- Activate the virtual environment -
- For Windows
venv\Scripts\activate
- For MacOS
source venv/bin/activate
- For Windows
- Installing the packages of the requirements.txt file -
# For both MacOS and Windows pip install -r requirements.txt OR pip3 install -r requirements.txt # In case you are using pip3
- Installing the package "cryptography" -
# For both MacOS and Windows pip install cryptography OR pip3 install cryptography
-
Update the python path -
- Open
social_media_app/app_runner.py
. - Copy the
path
of thevenv/bin/python
. - replace
<version/of/Python/used/within/the/venv>
in line numbers 5, 9 and 13 with thepath
.
- Open
-
Update MySQL password -
- In
user_app/app.py
,shared/app.py
,post_app/app.py
andmessage_app/app.py
- - Go to the line number 11.
- replace
<enter-your-password>
with your actual MySQL password.
- In
- Set the Flask application -
- For Windows -
set FLASK_APP=shared/app.py
- For MacOS -
export FLASK_APP=shared/app.py
- For Windows -
- Initializing migrations -
# For both Windows and MacOS flask db init
- Generating a migration script -
# For both Windows and MacOS flask db migrate -m "Added new table for user profiles"
- Applying the migrations -
# For both Windows and MacOS flask db upgrade
- Start the application
# For both MacOS and Windows python app_runner.py OR python3 app_runner.py
- The servers will be available at -
- User App: http://127.0.0.1:5001
- Post App: http://127.0.0.1:5002
- Message App: http://127.0.0.1:5003
-
Now, for sending message or to create post, first of all you need to create a user.
-
When you go to
social_media_app/shared/post_model.py
, you can see, you have the structure of the user table. -
CREATING A COLLECTION ON POSTMAN APPLICATION -
- Open the Postman application
- open
collections
. - select the
+
sign i.e.,create new collection
. - select
blank collection
. - Give name to your collection.
-
CREATING A REQUEST ON POSTMAN APPLICATION -
- Now, select the option bar of your created collection.
- select the option
Add request
. - Give name to your request. For example, here you are going to create a users request, so name it
users
. - Place where,
enter URL or paste text
is written, enter the address of the server. Here, we are making the request for users, so we will be adding the address of the user_app. i.e.,http://127.0.0.1:5001
- Now go to the
social_media_app/user_app/routes/user_routes.py
. - There, you can see that the endpoint of
create_user()
function is/api/users
and the method isPOST
. - Now enter the URL as -
http://127.0.0.1:5001/api/users
and select the method asPOST
. - Now, go to the
Headers
column, enter the key asContent-Type
and enter the value asapplication/json
- Now, go to the
Body
column, selectraw
and then,json
. - In the blank space provided, enter the values of the users in the json format.
- Example -
{ "username" : "Shreya", "email" : "shreya@example.com", "password" : "shreya@123", "full_name" : "Shreya Jaisal", "bio" : "backend developer" }
- Now click the
send
button. - On success, you will see,
{ "message": "User created successfully", "user_id": 1 }
- And hence, a user is successfully created in your database.
-
Explore Additional Routes:
- check
routes
in -user_app/routes/user_routes.py
post_app/routes/post_routes.py
message_app/routes/message_routes.py
- check
-
And this is how you can run your social_media_app.
For further setup and usage instructions, refer to the "INSTRUCTIONS TO RUN SOCIAL MEDIA APP" section above. If you have suggestions or questions, feel free to email me at shreyajaisal90@gmail.com.