<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ashley Alex Jacob on Medium]]></title>
        <description><![CDATA[Stories by Ashley Alex Jacob on Medium]]></description>
        <link>https://medium.com/@ashleyalexjacob?source=rss-7bb96d04a925------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZBglCyEfIbQpUtMTUQyqsA.jpeg</url>
            <title>Stories by Ashley Alex Jacob on Medium</title>
            <link>https://medium.com/@ashleyalexjacob?source=rss-7bb96d04a925------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:40:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashleyalexjacob/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flask API Folder Guide 2023]]></title>
            <link>https://ashleyalexjacob.medium.com/flask-api-folder-guide-2023-6fd56fe38c00?source=rss-7bb96d04a925------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fd56fe38c00</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Ashley Alex Jacob]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 20:09:27 GMT</pubDate>
            <atom:updated>2023-07-28T20:09:27.509Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_-gt1WwcudyAmsSRUiUCw.png" /></figure><blockquote>Having a consistent folder structure is key to success for various projects. After spending a year of experimentation in the industry while working on multiple projects and collaborating with multiple developers and machine learning engineers, this is the realisation I had. Merely because half of the time was spent in debugging or understanding the flow, which the parallel developer had implemented.</blockquote><p>When I joined another product team in March, most of my contributions had been to the proof of concept. However, after the proof of concept stage, we were progressing towards a full fledge API Service. I was assigned the task of setting up the entire workflow for the API service, which included folder structure, database schemas and implementations, and API Design. So I started looking into online resources, which covered the MVC pattern in Flask, REST APIs with Flask, Nested Routing, JWT authentication with Flask, and Database ORM and Migration.</p><p>However, getting all these materials in a single place is something I couldn’t find. But this medium article would give you an overview of all these steps and will boost your workflow.</p><p>A resource I normally recommend to those getting started with Flask is Corey Schafer’s Flask Playlist on Youtube Python Flask Tutorial: <a href="https://www.youtube.com/watch?v=MwZwr5Tvyxo&amp;list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&amp;ab_channel=CoreySchafer">https://www.youtube.com/watch?v=MwZwr5Tvyxo&amp;list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&amp;ab_channel=CoreySchafer</a></p><p>This guide would cover these topics:</p><ol><li>Setting up Python virtual environment and installation of packages.</li><li>Folder Structure for a Flask API Application</li><li>Setting up a SQL lite database, with Flask SQL Alchemy ORM and Flask Migration Tool.</li><li>Nested routing with Flask Blueprint.</li><li>Setting up a workflow for a JWT Based Authentication System</li></ol><p>This article assumes that you have a basic knowledge of <strong>GIT, Python, and Flask</strong> is a plus. Plus you have python and vs code installed along with Git.</p><h3>1. Setting up Python virtual environment and installation of packages</h3><p>First, we will start by creating an empty folder and creating a python virtual environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hOcaJiYO7kBQ0hCunC2baw.png" /></figure><p>Then type <strong>code .</strong> to open Visual Studio Code in the project directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8bAOeuMZHa2yKHEBqc49A.png" /></figure><p>Then we will setup up our virtual environment for our flask project. By using the following command</p><pre>python -m venv venv/</pre><p>This would result in a <strong>venv</strong> folder created in our project directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u68B5GymaftOQMkIkVlGVg.png" /></figure><p>Next step is to create a <strong>requirements.txt</strong> file.</p><pre>touch requirements.txt</pre><p>Lets populate our requirements.txt file by adding in the required packages for this project.</p><pre>flask<br>pathlib<br>python-dotenv<br>PyJWT<br>Flask-SQLAlchemy<br>Flask-Migrate<br>flask-bcrypt<br>mysqlclient</pre><p>Next steps involve activating our virtual environment and followed by installation of these packages, with this our first section of this guide will conclude.</p><pre># activate virtual environment<br># mac and linux os users<br>source venv/bin/activate<br># windows users<br>venv/Scripts/activate</pre><pre># install packages in virtual environment<br>pip install -r requirements.txt</pre><p>Our project directory is setup now and requirements are installed 🚀 Lets proceed towards our next step which is Folder Structure for a Flask API Application.</p><h3>2. Folder Structure for a API Application</h3><p>We will automate the files and folder creation stage however for now lets proceed by creating them manually.</p><p>Create following files in the project root directory:</p><ol><li>.env (for project secrets)</li><li>DockerFile</li><li>.gitignore</li><li><a href="http://app.py/">app.py</a> (Application starting point)</li><li><a href="http://readme.md/">README.md</a></li><li>init_setup.sh (Automation script for setting up environment)</li><li><a href="http://template.py/">template.py</a> (Automation script to create folders and files in it)</li></ol><pre>touch .env DockerFile .gitignore app.py README.md init_setup.sh template.<br>py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHtF8ynx-QA5Yea1mw8HSg.png" /></figure><p>We will use python packaged structure to organize our code.</p><p>Create <strong>src</strong> (You can give it the name of the package you want), inside it create a <strong>init</strong>.py constructor file.</p><p><em>Note: if you don’t have Linux or MacOs you can use touch command alternative in windows</em> echo &gt;&gt; .env</p><pre># create src directory<br>mkdir src<br><br># create constructor file in src directory<br>touch src/__init__.py</pre><p>Next step is to create config folder for our flask application in our src folder.</p><pre># create src/config<br>mkdir src/config<br><br># create files<br>touch src/config/__init__.py src/config/config.py src/config/dev_config.py src/config/production.py</pre><p>Controllers folder and files is next in our list.</p><pre># create src/controllers<br>mkdir src/controllers<br><br># create files<br>touch src/controllers/__init__.py src/controllers/auth_controller.py</pre><p>Middleware&#39;s and models and services folders and files is our next target.</p><pre># create middlewares, models and services folder<br>mkdir src/middlewares src/models src/services<br><br># create files within these folders<br>touch src/middlewares/__init__.py<br><br>touch src/models/__init__.py src/models/user_model.py<br><br>touch src/services/__init__.py src/services/jwt_service.py</pre><p>Lets create the remaining <a href="http://routes.py/">routes.py</a> and <a href="http://utils.py/">utils.py</a> file in our src directory.</p><pre>touch src/routes.py src/utils.py</pre><p>Now the wholes steps done above are tedious and repetitive, first thing first you can delete everything in the root directory or create a separate empty root directory. Start by creating a <a href="http://template.py/">template.py</a> file.Now our folder structure is ready lets just simplify it and using a simple python script to automate the tedious task of folder and files creation.</p><pre># create empty folder<br>mkdir &lt;Project-Name&gt;<br><br># change directory<br>cd &lt;Project-Name&gt;<br><br># Open VsCode<br>code .<br><br># create template.py file<br>touch template.py</pre><pre># template.py<br><br>import os<br>from pathlib import Path <br><br>PROJECT_NAME = &quot;src&quot; #add your project name here<br><br>LIST_FILES = [<br>    &quot;Dockerfile&quot;,<br>    &quot;.env&quot;,<br>    &quot;.gitignore&quot;,<br>    &quot;app.py&quot;,<br>    &quot;init_setup.py&quot;,<br>    &quot;README.md&quot;,<br>    &quot;requirements.txt&quot;,<br>    &quot;src/__init__.py&quot;,<br>    # config folder<br>    &quot;src/config/__init__.py&quot;,<br>    &quot;src/config/config.py&quot;,<br>    &quot;src/config/dev_config.py&quot;,<br>    &quot;src/config/production.py&quot;,<br>    # controllers<br>    &quot;src/controllers/__init__.py&quot;,<br>    &quot;src/controllers/auth_controller.py&quot;,<br>    # middlewares<br>    &quot;src/middlewares/__init__.py&quot;,<br>    # models<br>    &quot;src/models/__init__.py&quot;,<br>    &quot;src/models/user_model.py&quot;,<br>    # services<br>    &quot;src/services/__init__.py&quot;,<br>    &quot;src/services/jwt_service.py&quot;,<br>    # routes and utils<br>     &quot;src/routes.py&quot;,<br>     &quot;src/utils.py&quot;,<br>   ]<br><br>for file_path in LIST_FILES:<br>    file_path = Path(file_path)<br>    file_dir, file_name = os.path.split(file_path)<br><br>    # first make dir<br>    if file_dir!=&quot;&quot;:<br>        os.makedirs(file_dir, exist_ok= True)<br>        print(f&quot;Creating Directory: {file_dir} for file: {file_name}&quot;)<br>    <br>    if (not os.path.exists(file_path)) or (os.path.getsize(file_path)==0):<br>        with open(file_path, &quot;w&quot;) as f:<br>            pass<br>            print(f&quot;Creating an empty file: {file_path}&quot;)<br>    else:<br>        print(f&quot;File already exists {file_path}&quot;)</pre><p>Lets automate the entire project setup and folders and files creation using <a href="http://template.py/">template.py</a> script and automating using shell script</p><pre># create a init_setup.sh file<br>touch init_setup.sh</pre><p>Add following code to this init_setup.sh script</p><pre>echo &quot;[ `date` ]&quot;: &quot;START&quot;<br>echo &quot;[ `date` ]&quot;: &quot;Creating virtual env&quot; <br>python -m venv venv/<br>echo &quot;[ `date` ]&quot;: &quot;activate venv&quot;<br>source venv/bin/activate<br>echo &quot;[ `date` ]&quot;: &quot;installing the requirements&quot; <br>pip install -r requirements.txt<br>echo &quot;[ `date` ]&quot;: &quot;creating folders and files&quot; <br>python template.py<br>echo &quot;[ `date` ]&quot;: &quot;END&quot;</pre><p>Start the setup pipeline 🚀</p><pre>source init_setup.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTuE0MSO16eyftBf2fUFDg.png" /></figure><h3>3. Setting up a SQL lite database, with Flask SQL Alchemy ORM and Flask Migration Tool.</h3><p>Lets begin setting up a sql lite database within our existing project. We have already installed our project dependencies like Flask SqlAlchemy and Flask Migrate.</p><p>In our <strong>.env</strong> file add following keys and values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*efMW9llWZccWkR3z4RVXWQ.png" /></figure><p>First we will set the configurations for our dev and production environment. In the dev_config.py file add configuration properties for the flask server.</p><pre>class DevConfig:<br>    def __init__(self):<br>        self.ENV = &quot;development&quot;<br>        self.DEBUG = True<br>        self.PORT = 3000<br>        self.HOST = &#39;0.0.0.0&#39;</pre><p>Next add configurations for the production environment in the <a href="http://production.py/">production.py</a> file.</p><pre>class ProductionConfig:<br>    def __init__(self):<br>        self.ENV = &quot;production&quot;<br>        self.DEBUG = False<br>        self.PORT = 80<br>        self.HOST = &#39;0.0.0.0&#39;</pre><p>Finally in your <a href="http://config.py/">config.py</a> file import these dev and production config.</p><pre>from src.config.dev_config import DevConfig<br>from src.config.production_config import ProductionConfig<br><br>class Config:<br>    def __init__(self):<br>        self.dev_config = DevConfig()<br>        self.production_config = ProductionConfig()<br></pre><p>We will initiate our flask server for that to happen head over to __init__.py file which resides in src folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npk0nDxPTZ8GOwoOwXJ1QQ.png" /></figure><p>In the <strong>init</strong>.py file start by importing required modules and call load_dotenv function to load the environment variables and declare the flask application instance.</p><pre>from flask import Flask<br>import os<br>from src.config.config import Config<br>from dotenv import load_dotenv<br><br># loading environment variables<br>load_dotenv()<br><br># declaring flask application<br>app = Flask(__name__)<br><br># calling the dev configuration<br>config = Config().dev_config<br><br># making our application to use dev env<br>app.env = config.ENV</pre><p>Now we will edit our <a href="http://app.py/">app.py</a> file to start our server.</p><pre>from src import config, app<br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(host= config.HOST,<br>            port= config.PORT,<br>            debug= config.DEBUG)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJ2NHwmxwcs-FDx8c9aocw.png" /></figure><p>In order to setup the sql lite database add following configuration codes in the <strong>init</strong>.py file. Also initialise our Sql Alchemy instance and flask migrate instance (Migration tool to handle migrations).</p><pre>from flask import Flask<br>import os<br>from src.config.config import Config<br>from dotenv import load_dotenv<br>from flask_sqlalchemy import SQLAlchemy<br>from flask_migrate import Migrate<br><br># loading environment variables<br>load_dotenv()<br><br># declaring flask application<br>app = Flask(__name__)<br><br># calling the dev configuration<br>config = Config().dev_config<br><br># making our application to use dev env<br>app.env = config.ENV<br><br># Path for our local sql lite database<br>app.config[&#39;SQLALCHEMY_DATABASE_URI&#39;] = os.environ.get(&quot;SQLALCHEMY_DATABASE_URI_DEV&quot;)<br><br># To specify to track modifications of objects and emit signals<br>app.config[&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;] = os.environ.get(&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;)<br><br># sql alchemy instance<br>db = SQLAlchemy(app)<br><br># Flask Migrate instance to handle migrations<br>migrate = Migrate(app, db)<br><br># import models to let the migrate tool know<br>from src.models.user_model import User</pre><p>In your terminal type following commands to create your database file:</p><ol><li><strong><em>flask db init</em></strong> → Create instance and migrations folders</li><li><strong><em>flask db migrate -m “inital commit”</em></strong><em> →</em> Creates the database.db file in the instance folder</li><li><strong><em>flask db upgrade</em></strong> → Creates the user tables and other tables based on the schema specified in the models.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5-OwhLuQYKVz0r6N4cgAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ywe6l7B2zqXIJFheZzmhZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JExh8OY-Pxz_LxnQOtB6Wg.png" /></figure><h3>4. Nested routing with Flask Blueprint</h3><p>If i want to implement a API in flask and the route has hierarchy api/xyz/functionality1 and there is another route api/xyz/functionality2 i would have to do something like this in flask.</p><pre>@app.route(&quot;api/xyz/functionality1&quot;)<br>def handle_functionality1():<br>	pass<br><br>@app.route(&quot;api/xyz/functionality2&quot;)<br>def handle_functionality2():<br>	pass</pre><p>The functions above are two in number, lets say if you are developing a big product and you have more than <strong>20 routes</strong> under a single controller with similar functionalities and roles. Rewriting the entire url every time is cumbersome and tiring. Route nesting is the solution to our problem above, which we can achieve using Blueprint in flask.</p><p>According to the flask documentation “A <strong>Blueprint </strong>is a way to organize a group of related views and other code. Rather than registering views and other code directly with an application, they are registered with a blueprint. Then the blueprint is registered with the application when it is available in the factory function.”</p><p><a href="https://flask.palletsprojects.com/en/2.3.x/tutorial/views/">Blueprints and Views — Flask Documentation (2.3.x) (palletsprojects.com)</a></p><p>Now we have some idea about the use-case and flask blueprint, then lets implement it in our application.</p><pre>from flask import Blueprint<br>from src.controllers.user_controller import users<br><br># main blueprint to be registered with application<br>api = Blueprint(&#39;api&#39;, __name__)<br><br># register user with api blueprint<br>api.register_blueprint(users, url_prefix=&quot;/users&quot;)</pre><pre># src/__init__.py<br><br>from flask import Flask<br>import os<br>from src.config.config import Config<br>from dotenv import load_dotenv<br>from flask_sqlalchemy import SQLAlchemy<br>from flask_migrate import Migrate<br><br># loading environment variables<br>load_dotenv()<br><br># declaring flask application<br>app = Flask(__name__)<br><br># calling the dev configuration<br>config = Config().dev_config<br><br># making our application to use dev env<br>app.env = config.ENV<br><br># Path for our local sql lite database<br>app.config[&#39;SQLALCHEMY_DATABASE_URI&#39;] = os.environ.get(&quot;SQLALCHEMY_DATABASE_URI_DEV&quot;)<br><br># To specify to track modifications of objects and emit signals<br>app.config[&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;] = os.environ.get(&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;)<br><br># sql alchemy instance<br>db = SQLAlchemy(app)<br><br># Flask Migrate instance to handle migrations<br>migrate = Migrate(app, db)<br><br># import models to let the migrate tool know<br>from src.models.user_model import User<br><br># import api blueprint to register it with app<br>from src.routes import api<br>app.register_blueprint(api, url_prefix = &quot;/api&quot;)</pre><p>Lets populate our user_controller.py file with some dummy functions to test out the functionality of blueprint and our routes.</p><pre>from flask import request, Response, json, Blueprint<br><br># user controller blueprint to be registered with api blueprint<br>users = Blueprint(&quot;users&quot;, __name__)<br><br># route for login api/users/signin<br>@users.route(&#39;/signin&#39;, methods = [&quot;GET&quot;, &quot;POST&quot;])<br>def handle_login():<br>    return Response(<br>        response=json.dumps({&#39;status&#39;: &quot;success&quot;}),<br>        status=200,<br>        mimetype=&#39;application/json&#39;<br>    )<br><br># route for login api/users/signup<br>@users.route(&#39;/signup&#39;, methods = [&quot;GET&quot;, &quot;POST&quot;])<br>def handle_signup():<br>    return Response(<br>        response=json.dumps({&#39;status&#39;: &quot;success&quot;}),<br>        status=200,<br>        mimetype=&#39;application/json&#39;<br>    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cXW49PAnX57qJgrvcZcQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkX0eWAYih8XeCpS7bA6pQ.png" /></figure><p>So our routes our perfectly fine, we have tested them. Lets proceed to the other section of this guide and build a basic authentication flow.</p><h3>5. Setting up a workflow for a JWT Based Authentication System</h3><p><em>JSON web token</em> (JWT), pronounced “jot”, is an open standard (<a href="https://tools.ietf.org/html/rfc7519"><strong>RFC 7519</strong></a>) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. Again, JWT is a standard, meaning that all JWTs are tokens, but not all tokens are JWTs.</p><p><a href="https://auth0.com/docs/secure/tokens/json-web-tokens">JSON Web Tokens (auth0.com)</a></p><p>The diagram below gives an overview how the JWT (Json Web Token) Authentication System works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWVU3oSI8c8N3-hXwXXxcQ.png" /></figure><p><a href="https://documentation.softwareag.com/webmethods/compendiums/v10-5/C_API_Management/api-mgmt-comp/images/workflow_jwt.png">workflow_jwt.png (867×484) (softwareag.com)</a></p><p>Python has a <strong>jwt package </strong>that makes the interaction and operations like encoding, decoding and password compare easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vkaZqGSffHkhpCG5QyNBA.png" /></figure><p>We will also use another python package bcrypt for hashing passwords.</p><pre>from flask import Flask<br>import os<br>from src.config.config import Config<br>from dotenv import load_dotenv<br>from flask_sqlalchemy import SQLAlchemy<br>from flask_migrate import Migrate<br># for password hashing<br>from flask_bcrypt import Bcrypt<br><br># loading environment variables<br>load_dotenv()<br><br># declaring flask application<br>app = Flask(__name__)<br><br># calling the dev configuration<br>config = Config().dev_config<br><br># making our application to use dev env<br>app.env = config.ENV<br><br># load the secret key defined in the .env file<br>app.secret_key = os.environ.get(&quot;SECRET_KEY&quot;)<br>bcrypt = Bcrypt(app)<br><br># Path for our local sql lite database<br>app.config[&#39;SQLALCHEMY_DATABASE_URI&#39;] = os.environ.get(&quot;SQLALCHEMY_DATABASE_URI_DEV&quot;)<br><br># To specify to track modifications of objects and emit signals<br>app.config[&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;] = os.environ.get(&quot;SQLALCHEMY_TRACK_MODIFICATIONS&quot;)<br><br># sql alchemy instance<br>db = SQLAlchemy(app)<br><br># Flask Migrate instance to handle migrations<br>migrate = Migrate(app, db)<br><br># import api blueprint to register it with app<br>from src.routes import api<br>app.register_blueprint(api, url_prefix=&quot;/api&quot;)<br><br># import models to let the migrate tool know<br>from src.models.user_model import User</pre><p>We will start by completing our sign up route in the user controller, the flow would include validating request parameters, storing the user data in the db and generating jwt token and sending it in the response.</p><pre># src/controllers/user_controller.py<br><br># route for signup api/users/signup<br>@users.route(&#39;/signup&#39;, methods = [&quot;POST&quot;])<br>def handle_signup():<br>    try: <br>        # first validate required use parameters<br>        data = request.json<br>        if &quot;firstname&quot; in data and &quot;lastname&quot; and data and &quot;email&quot; and &quot;password&quot; in data:<br>            # validate if the user exist <br>            user = User.query.filter_by(email = data[&quot;email&quot;]).first()<br>            # usecase if the user doesn&#39;t exists<br>            if not user:<br>                # creating the user instance of User Model to be stored in DB<br>                user_obj = User(<br>                    firstname = data[&quot;firstname&quot;],<br>                    lastname = data[&quot;lastname&quot;],<br>                    email = data[&quot;email&quot;],<br>                    # hashing the password<br>                    password = bcrypt.generate_password_hash(data[&#39;password&#39;]).decode(&#39;utf-8&#39;)<br>                )<br>                db.session.add(user_obj)<br>                db.session.commit()<br><br>                # lets generate jwt token<br>                payload = {<br>                    &#39;iat&#39;: datetime.utcnow(),<br>                    &#39;user_id&#39;: str(user_obj.id).replace(&#39;-&#39;,&quot;&quot;),<br>                    &#39;firstname&#39;: user_obj.firstname,<br>                    &#39;lastname&#39;: user_obj.lastname,<br>                    &#39;email&#39;: user_obj.email,<br>                }<br>                token = jwt.encode(payload,os.getenv(&#39;SECRET_KEY&#39;),algorithm=&#39;HS256&#39;)<br>                return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;success&quot;,<br>                                    &quot;message&quot;: &quot;User Sign up Successful&quot;,<br>                                    &quot;token&quot;: token}),<br>                status=201,<br>                mimetype=&#39;application/json&#39;<br>            )<br>            else:<br>                print(user)<br>                # if user already exists<br>                return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;failed&quot;, &quot;message&quot;: &quot;User already exists kindly use sign in&quot;}),<br>                status=409,<br>                mimetype=&#39;application/json&#39;<br>            )<br>        else:<br>            # if request parameters are not correct <br>            return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;failed&quot;, &quot;message&quot;: &quot;User Parameters Firstname, Lastname, Email and Password are required&quot;}),<br>                status=400,<br>                mimetype=&#39;application/json&#39;<br>            )<br>        <br>    except Exception as e:<br>        return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;failed&quot;, <br>                                     &quot;message&quot;: &quot;Error Occured&quot;,<br>                                     &quot;error&quot;: str(e)}),<br>                status=500,<br>                mimetype=&#39;application/json&#39;<br>            )</pre><p>Then our sign in route would have following flow, we will start by checking user request parameters, check for user records, check for user password and then generate a jwt token and return it in the response.</p><pre># src/controllers/user_controller.py<br><br># route for login api/users/signin<br>@users.route(&#39;/signin&#39;, methods = [&quot;POST&quot;])<br>def handle_login():<br>    try: <br>        # first check user parameters<br>        data = request.json<br>        if &quot;email&quot; and &quot;password&quot; in data:<br>            # check db for user records<br>            user = User.query.filter_by(email = data[&quot;email&quot;]).first()<br><br>            # if user records exists we will check user password<br>            if user:<br>                # check user password<br>                if bcrypt.check_password_hash(user.password, data[&quot;password&quot;]):<br>                    # user password matched, we will generate token<br>                    payload = {<br>                        &#39;iat&#39;: datetime.utcnow(),<br>                        &#39;user_id&#39;: str(user.id).replace(&#39;-&#39;,&quot;&quot;),<br>                        &#39;firstname&#39;: user.firstname,<br>                        &#39;lastname&#39;: user.lastname,<br>                        &#39;email&#39;: user.email,<br>                        }<br>                    token = jwt.encode(payload,os.getenv(&#39;SECRET_KEY&#39;),algorithm=&#39;HS256&#39;)<br>                    return Response(<br>                            response=json.dumps({&#39;status&#39;: &quot;success&quot;,<br>                                                &quot;message&quot;: &quot;User Sign In Successful&quot;,<br>                                                &quot;token&quot;: token}),<br>                            status=200,<br>                            mimetype=&#39;application/json&#39;<br>                        )<br>                <br>                else:<br>                    return Response(<br>                        response=json.dumps({&#39;status&#39;: &quot;failed&quot;, &quot;message&quot;: &quot;User Password Mistmatched&quot;}),<br>                        status=401,<br>                        mimetype=&#39;application/json&#39;<br>                    ) <br>            # if there is no user record<br>            else:<br>                return Response(<br>                    response=json.dumps({&#39;status&#39;: &quot;failed&quot;, &quot;message&quot;: &quot;User Record doesn&#39;t exist, kindly register&quot;}),<br>                    status=404,<br>                    mimetype=&#39;application/json&#39;<br>                ) <br>        else:<br>            # if request parameters are not correct <br>            return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;failed&quot;, &quot;message&quot;: &quot;User Parameters Email and Password are required&quot;}),<br>                status=400,<br>                mimetype=&#39;application/json&#39;<br>            )<br>        <br>    except Exception as e:<br>        return Response(<br>                response=json.dumps({&#39;status&#39;: &quot;failed&quot;, <br>                                     &quot;message&quot;: &quot;Error Occured&quot;,<br>                                     &quot;error&quot;: str(e)}),<br>                status=500,<br>                mimetype=&#39;application/json&#39;<br>            )</pre><p>Lets test our endpoints and validate if they are working correctly or not. I will use postman you can use any api test client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hb2liSzrGrGHyRkTFJk8dQ.png" /></figure><p>You also need to pass content-type in the header</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KC2aGh5h5xB_jckW8lbOUw.png" /></figure><p>For now we have covered major of the stuff for this guide 🚀. After following this guide I’m sure you can setup a pretty good folder structure and workflow for your Flask API Projects and then extend it according to your business problem. So kickstart your development journey.</p><p>Note: This code can be refactored and plus we could have covered packaging application using dockers and its deployment, but in order to keep this guide short I have ignored it. Plus there can be numerous optimisations, which i will cover in my other guides. All the codes are available in the Github Repo, if you like it don’t forget to star ⭐️ and share it with others.</p><p>Github:</p><p><a href="https://github.com/AshleyAlexJacob/Flask-API-Folder-Guide-2023">AshleyAlexJacob/Flask-API-Folder-Guide-2023 (github.com)</a></p><p>Linkedin:</p><p><a href="https://www.linkedin.com/in/ashleyalexjacob2000/">https://www.linkedin.com/in/ashleyalexjacob2000/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fd56fe38c00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptocurrency, A Real Currency or Not?]]></title>
            <link>https://ashleyalexjacob.medium.com/cryptocurrency-a-real-currency-or-not-2defd007ae7e?source=rss-7bb96d04a925------2</link>
            <guid isPermaLink="false">https://medium.com/p/2defd007ae7e</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Ashley Alex Jacob]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 18:57:33 GMT</pubDate>
            <atom:updated>2021-06-02T19:10:51.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDMEF8K-701NGEbZUE5wSQ.jpeg" /><figcaption>:: An Abstraction of Cryptocurrencies</figcaption></figure><p>To buy goods, we need real money. We can also buy goods in exchange for a valuable gem like Gold, Diamond, etc. But Real Money has got real power. Real money has three powers It is Generally Accepted, you can use them to buy all sorts of products ranging from household to gaming consoles to mobile phones all. Real money is Durable, such that its value doesn’t change over the period. The real money is certain in its value, such that if some money has a value of 1000 so it will be 1000. Based on these traits in this era and past, Paper Currency has been the main source of exchange. But in past Gems like Gold, Diamond has remained a source of exchange.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x7J_QH4AG7F3jlxOgyZDTQ.jpeg" /><figcaption>:: Gold Stack</figcaption></figure><p>Gems like Gold, Diamond, etc. have powers but they don’t have all the powers like paper currency, Gold is not as generally accepted as paper currency, Gold is durable such that it retains its qualities, but is not certain in its value of exchange, it changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEclVgXdRDvrPHV8PL5wLg.jpeg" /></figure><p>A deep dive into history was necessary to get to the main topic. Back in the Early 90’s World-leading economists were thinking of a currency, which is more global, and more acceptable in all the countries plus the money transfer of it becomes blazing fast between countries. It was a concept of a unified global currency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*PzC3tOUuxorCoAQNgGvpmw.jpeg" /><figcaption>:: Unknown Personality Satoshi Nakamoto</figcaption></figure><p>To have a special currency, which is global and acceptable and is certain in its value was the target. At the beginning of the 21st Century, an Unknown Personality or Group of Persons named Satoshi Nakamoto proposed the Idea of Bitcoin, which formed the basis of the Digital Global and Paperless Currency “Cryptocurrency”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2k4PL0HyARZkbHInR0CAA.jpeg" /></figure><p>“Cryptocurrency” revolutionized the economic structure of the entire world. As the traditional Banking system is centralized such that a governing body monitors the paper currency. But in the case of Cryptocurrency, there is no Centralized body. Moreover, it is digital so it has no hard existence just like paper currency but has worth equal to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZSrfbVVEu_y4VHNTep1HGQ.jpeg" /></figure><p>One of the most famous cryptocurrencies is Bitcoin, there are others as well. So let’s discuss bitcoin, to get bitcoin a person who is known as Miner needs to solve a puzzle (Moreover like a complex jigsaw). For these computations, modern Machines are required. When the machine successfully solves the Mathematical Equation (aka Jigsaw) as a reward each miner gets 12 Bitcoins. But keep in mind after every 4 years the value of the reward of bitcoins is reduced by halving such that it becomes 6 coins after 4 years.</p><p>Another important concept in cryptocurrency is the verification of the stack of transactions i.e. Person A sends his coins to Person B, first we need to verify whether person A holds that much worth of coins or not. So, the stack is an important concept in the world of cryptocurrency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVSl-sXldy-EZ3s73gWl_Q.jpeg" /></figure><p>There are also myths that cryptocurrency is hackable, as every digital product is. But as the name suggests it is Encrypted and fully secure. Unlike other currencies, it holds the power of buying. In the future, all the transactions will be made using cryptocurrency and many companies are accepting it as a method of payment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2defd007ae7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Positive Impact on My Life]]></title>
            <link>https://ashleyalexjacob.medium.com/positive-impact-on-my-life-1cc6cbcce36e?source=rss-7bb96d04a925------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cc6cbcce36e</guid>
            <category><![CDATA[thinking]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[positivity]]></category>
            <dc:creator><![CDATA[Ashley Alex Jacob]]></dc:creator>
            <pubDate>Sun, 30 May 2021 09:41:38 GMT</pubDate>
            <atom:updated>2021-06-02T19:12:39.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eIDJB8g-j8GMpbhQ7_pV8Q.jpeg" /><figcaption>“With Positivity you can climb all heights”</figcaption></figure><p>The very person in my life that had a positive impact on my life is my father. Augustin Jacob is a personality who is renowned for his many traits. Which includes Consistency, Determination, and Care for everyone. Augustin Jacob is a part of Pakistan’s Largest Insurance Company EFU Life Assurance Ltd for 25 Years and is an enthusiast for more success and contributing his part in the ever-growing insurance sector. Moreover, the thing that matters to me and others, is his struggle for the rights of oppressed communities. He has raised the voice of the Minority Community of Pakistan for their rights.</p><p>While growing up I have witnessed my father on different battlegrounds and I have seen his struggles. While I analyze his life, there is new learning for me. He mentors me at every step of my life. I have been honest with my father and I ask for his advice. He advises me based on his experience.</p><p>The thing which I love is discussing various topics related to life matters, politics, and geopolitical and economical matters, and every time there is something new for me. These talks and analyses have positively impacted my life and I am getting better at managing different matters at ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFweQPVra0ppOvSNBA7X1Q.jpeg" /></figure><p>I remember I used to panic and get nervous when things didn’t go as I planned, but it was my father who helped me calm down, and help me through that period to get things right. He always says “We are humans and what we plan is not necessarily is going to happen. So it’s better to have Plan B, C plus become adaptive to any situation and circumstances”. He gives the example of a tree whose branches are flexible and whenever there are storms, as it is flexible so its branches don’t break they can easily go up and down according to the flow. As a compared to a tree with firm branches does get broken easily. So he recommends becoming flexible so that you don’t get broken.</p><p>I have adapted his teachings in my daily dealings and have benefitted from them a lot. Now I stay calm no matter what the situation is and I try my best to get past it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SfPMLMK131s440jV8Wx34A.jpeg" /></figure><p>This was about me and the impact a personality can have on your life. So stay positive and look for mentors, I mean they’ll truly guide you and you will observe the results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cc6cbcce36e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Which platform to choose for Mobile App Development?]]></title>
            <link>https://ashleyalexjacob.medium.com/which-platform-to-choose-for-mobile-app-development-736ced6507ac?source=rss-7bb96d04a925------2</link>
            <guid isPermaLink="false">https://medium.com/p/736ced6507ac</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Ashley Alex Jacob]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 20:37:22 GMT</pubDate>
            <atom:updated>2021-02-24T20:37:22.746Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Mobile Apps have changed the ecosystem of trade, now all the operations are performed with just a click of a button, with the added benefit that mobile fits in a pocket.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTDNPwA1irgh6UeGz-Kg7g.jpeg" /></figure><p>This article is about which platform to choose to publish your mobile app on the app stores.</p><p>As some of you might know, there are three main categories in the Mobile App Development arena:</p><p><strong>1. Native Applications</strong></p><p><strong>2. Cross-Platform Applications</strong></p><p><strong>3. Progressive Web Apps (PWA’s)</strong></p><p>I will be discussing only the Native Applications and Cross-Platform Applications. PWA’s are a talk for another day.</p><p><strong>Native Applications:</strong></p><p>Those mobile apps which are platform-specific fall under this category. For example Android Apps, Ios Apps, Windows Apps, etc.</p><p>Native Applications are considerably fast and robust as compared to Cross-Platform Apps. They perform better on their platforms.</p><p>IOS Mobile Apps can be developed using Swift or Objective C language.</p><p>While Android apps can be developed using Kotlin or Java.</p><p><strong>Cross-Platform Applications:</strong></p><p>Cross-Platform Mobile Applications give the benefit of maintaining a single codebase for multiple platforms. In other words, you write the code for the app in a single programming language and use it for different platforms. Whereas native applications are platform-specific, writing code of ios app in one programming language while for android app in another Programming language.</p><p>Popular Frameworks for Cross-Platform Development:</p><p><strong>React Native:</strong></p><p>It is one of the most famous and widely used frameworks for Cross-Platform App Development. Originally developed by Facebook back in 2013. It has one of the biggest communities. But one drawback is that it relies mostly on 3rd party plugins to add features.</p><p>React Native uses JavaScript as its Programming language, which is a very famous and rapidly fast-growing programming language, with bigger community support.</p><p><strong>Flutter:</strong></p><p>Flutter is the UI Development Toolkit, launched by Google back in 2017. It is the hottest topic in the mobile dev community these days. It is also fast growing. Flutter gives the edge in terms of performance, as it has its own UI Engine so it renders itself, instead of depending. Plus it has got a whole lot of UI components built-in. So it doesn’t rely on third-party plugins.</p><p>Flutter supports Dart Programming Language, which is also developed by Google. Dart is an object-oriented programming language.</p><p>Flutter also supports web development plus desktop development which is in beta version.</p><p><strong>Xamarin:</strong></p><p>Xamarin was developed by Microsoft itself back in 2011. It is an open source technology. The sole purpose was to develop cross-platform applications using a single language which is C#.</p><p>Xamarin apps have native apps like features and likewise the performance levels as well. One of the disadvantages of using xamarin is that the app sizes are much more and you might need to write some ui part platform specific, so for that you need to have the knowledge of Native Languages.</p><p>You can set up an environment for Xamarin in Microsoft Visual Studio or Xcode.</p><p>While summing up the discussion, if you want your application to be a platform specific application then go for Native Approach as it would be best in this scenario.</p><p>If you want to do Cross-Platform then compare, and select which suits you best, if you are coming from a Web Development background then go for React Native. If you have a background in .net technologies then go for Xamarin. And if you are a beginner like me who is just stepping into the multiverse of technologies and who knows the basics of OOPs and knows C++, then look for Flutter.</p><p>One more thing before stepping into the Mobile App Development Area, make sure you know the fundamentals of Programming and Algorithm Designing and Plus the Object Oriented Programming as it is a Must.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=736ced6507ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>