About the design pattern, I recommend a DAO and Service approach, here's a good and short article about it: https://levelup.gitconnected.com/structuring-a-large-production-flask-application-7a0066a65447

About the models User/Activity relationship, I presume you have a mapped Activity model. If this is a One to One relationship, in the User model create a activityId field for the FK field and a activity relation where your ORM (I'll assume SQLAlchemy) will retrieve when user.activity is accessed.

class Activity(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    descrption = db.Column(db.String(255))

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    activity = db.relationship(Activity)
    activityId = db.Column(db.Integer, db.ForeignKey(Activity.id))

If you have a Many to Many relationship you'll have to create a third class called ActivityUser to map the relation

class ActivityUser(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    activity = db.relationship(Activity, lazy=True)
    user = db.relationship(User, lazy=True)
    activityId = db.Column(db.ForeignKey(Activity))
    userId = db.Column(db.ForeignKey(User))

and you can retrieve the user activities like this (again assuming you use SQLAlchemy):

ActivityUser.query.filter(ActivityUser.userId == user.id).all()
Answer from Ares on Stack Overflow
🌐
Medium
medium.com › reactorlabs › learn-flask-design-patterns-and-project-structure-e7b48185ab5e
Learn Flask Design Patterns And Project Structure | by jQN | ReactorLabs | Medium
February 2, 2021 - A single file that you typically come across when looking for Flask examples, often an app.py. This is good enough for quick projects where only a few routes are needed and you have less than a few hundred lines of code. app.py config.py requirements.txt static/ templates/ When you are working on projects that are more complex, for example, if you need to define models and forms. With this pattern, you can create separate components for your application.
Discussions

Best open source Flask repos for learning design patterns?
The example app from the Build a SAAS App with Flask course is partially available on GitHub at https://github.com/nickjj/build-a-saas-app-with-flask/ . It's not the complete app, but all of the design pattern related folders and structure is there. The complete app just adds way more blueprints, templates, cli commands and libraries. I've scaled this style of app to 10,000+ lines of Flask related code before. Apps with over a dozen blueprints and 50+ models, etc.. Out of every framework and design pattern I ever used, I like this one the best because I find it really easy to jump to specific bits of the code I'm interested in, thanks to blueprints doing a great job at organizing the main points of your code base. More on reddit.com
🌐 r/flask
20
37
June 20, 2018
Flask Application Factory Pattern example
Have you looked at this before? https://github.com/gothinkster/flask-realworld-example-app Edit: Or Miguel Grinberg's Microblog repos: https://github.com/miguelgrinberg/microblog More on reddit.com
🌐 r/flask
7
14
January 1, 2024
🌐
Flask
flask.palletsprojects.com › en › stable › patterns
Patterns for Flask — Flask Documentation (3.1.x)
These types of patterns may be a bit outside the scope of Flask itself, but Flask makes it easy to implement them.
🌐
Software Testing Help
softwaretestinghelp.com › home › python › flask design patterns and best practices for web applications
Flask Design Patterns And Best Practices For Web Applications
April 1, 2025 - Flask is so unopinionated and flexible that you might like to combine concepts from the existing patterns and create a new one. ... For example, You will find many examples from the MVC pattern to Single Page Applications to SAAS pattern. You name the design paradigm, and it is already there tried by someone in the community and is freely available for you to try your hands on.
🌐
Flask
flask.palletsprojects.com › en › stable › design
Design Decisions in Flask — Flask Documentation (3.1.x)
As your codebase grows, you are free to make the design decisions appropriate for your project. Flask will continue to provide a very simple glue layer to the best that Python has to offer. You can implement advanced patterns in SQLAlchemy or another database tool, introduce non-relational ...
🌐
GitHub
github.com › mzuvin › Flask-Design-Patterns
GitHub - mzuvin/Flask-Design-Patterns: Design Patterns(Singleton,Adapter,Mediator) with flask framework
Design Patterns(Singleton,Adapter,Mediator) with flask framework - mzuvin/Flask-Design-Patterns
Author   mzuvin
Find elsewhere
🌐
Ploneconf
2017.ploneconf.org › talks › how-to-design-a-great-api-using-flask.html
How to design a great API using Flask
Some specific topics I'll cover: Flask architecture, request lifecycles, security & auth packages, REST + CRUD API patterns, ORMs, separation of concerns, information hiding.
🌐
GitHub
github.com › topics › flask-design-pattern
flask-design-pattern · GitHub Topics · GitHub
To associate your repository with the flask-design-pattern topic, visit your repo's landing page and select "manage topics."
🌐
GitConnected
levelup.gitconnected.com › structuring-a-large-production-flask-application-7a0066a65447
Structuring a Large Production Flask Application | by Arash Soheili | Level Up Coding
April 8, 2020 - Blueprints are a great way to organize your routes and a must use for large applications. Services/DAO Singleton Design Pattern: A pattern I have found that works very well in a Flask app is the services/dao (database access object) singleton ...
🌐
MoldStud
moldstud.com › articles › developers faq › flask developers questions › flask and restful design patterns - a practical overview for developers
Flask and RESTful Design Patterns - A Practical Overview for Developers
April 12, 2025 - Flask-RESTful is a game changer when it comes to building RESTful APIs. It simplifies the process of creating endpoints and handling HTTP methods, making it a lot easier to focus on the logic of your application. ... I've been experimenting with different design patterns in Flask, and I've found that using decorators to define routes is a great way to keep my code organized and easy to read.
🌐
Medium
medium.com › @rudresh.narwal › mastering-flask-and-django-top-10-python-design-patterns-for-2024-830e0d958fcb
Mastering Flask and Django: Top 10 Python Design Patterns for 2024
December 28, 2024 - Here, we delve into the top 10 design patterns that are shaping the way we build web applications today. ... The Singleton pattern ensures a class has only one instance and provides a global point of access to it.
🌐
Flask
flask.palletsprojects.com › en › stable › patterns › appfactories
Application Factories — Flask Documentation (3.1.x)
def create_app(config_filename): app = Flask(__name__) app.config.from_pyfile(config_filename) from yourapplication.model import db db.init_app(app) Using this design pattern, no application-specific state is stored on the extension object, so one extension object can be used for multiple apps.
🌐
Auth0
auth0.com › home › blog › best practices for flask api development
Best Practices for Flask API Development
August 30, 2021 - I’d like to start this section by saying that there’s no one correct way to structure your application depending on application size, modules, requirements, or even personal preferences. This could vary. However, I’d like to introduce you to how my team structures Flask applications, and we used this setup for multiple production projects.
🌐
MoldStud
moldstud.com › articles › developers faq › flask developers questions › practical overview of flask and restful design patterns for developers
Practical Overview of Flask and RESTful Design Patterns for Developers
May 16, 2025 - Explore practical strategies for deploying Flask applications in serverless environments. Learn about architecture choices, integration patterns, and best practices for scalability and cost optimization.
🌐
Reddit
reddit.com › r/flask › flask application factory pattern example
r/flask on Reddit: Flask Application Factory Pattern example
January 1, 2024 -

I have been struggling with circular import errors and would like to rearrange my flask application so that it uses the 'Flask Application Factory'. Is there an example that is easy to understand for a beginner. Some examples are rather big to follow. I need a tutorial or example with a basic structure like;

🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-structure-a-large-flask-application-with-flask-blueprints-and-flask-sqlalchemy
How To Structure a Large Flask Application with Flask Blueprints and Flask-SQLAlchemy | DigitalOcean
November 19, 2022 - You create a test route using the app.route() decorator inside the factory function to demonstrate how to register routes inside application factories. In this case, the test_page() view function returns the heading Testing the Flask Application Factory Pattern.