Although a beginner in web development, I currently have been working on a larger Flask application.
At the moment I'm working with the structure shown below but I'm wondering what is the best way to structure such an application especially regarding different database connections (SQLAlchemy).
Unlike what is shown in the usual (and very helpful) Flask tutorials, I envision an architecture of multiple, partially independent (sub)apps, each also relying on its own database connection. Also, I don't necessarily want to load all databases immediately when accessing the main website but only the one of the subapp that is needed.
For communication between server and client I plan to use REST API and I already use Blueprints to separate the subapps.
The app has a unified frontend, where the subapps are simply mapped to different URL endpoints (e.g. website.net/app1 and website.net/app2).
Any guidance on structuring such an app is greatly appreciated, thanks!
Current app structure:
project/
├─ run.py
├─ webapp/
│ ├─ __init__.py
│ ├─ static/
│ ├─ templates/
│ ├─ app1/
│ │ ├─ data/
│ │ │ ├─ app1_database.py
│ │ │ ├─ app1_db_session.py
│ │ │ ├─ app1_modelbase.py
│ │ ├─ database/
│ │ ├─ services/
│ │ │ ├─ app1_services.py
│ │ ├─ templates/
│ │ │ ├─ app1/
│ │ │ │ ├─ app1.html
│ │ ├─ __init__.py
│ │ ├─ app1_forms.py
│ │ ├─ app1_views.py
│ ├─ app2/
│ │ ├─ data/
│ │ │ ├─ app2_database.py
│ │ │ ├─ app2_db_session.py
│ │ │ ├─ app2_modelbase.py
│ │ ├─ database/
│ │ ├─ services/
│ │ │ ├─ app2_services.py
│ │ ├─ templates/
│ │ │ ├─ app2/
│ │ │ │ ├─ app2.html
│ │ ├─ __init__.py
│ │ ├─ app2_forms.py
│ │ ├─ app2_views.py
As we are talking about modules and directories structure the main goal is to compose the app in a way that will be easy to you to maintain, debug and improve. I think if you have several apps in one project you better place each on a different server. We usually use blueprints when we want to separate logic within a single app and especially when we are planning to reuse this logic in a different app. So we can just copy-paste the single blueprint to another project. For example authentication blueprint. It can be the same in several apps. You didn't show any business logic of the app. So it's hard to say. I usually slpit files into directories considering business logic.