title: How to structure a Flask app like in Django?
body: <p>I have switched from Django to Flask for a project and am a bit lost how to setup a similar structure like in Django.</p>
  
  <p>In my flask example everything works fine in a single file but the moment I even try to pull the models into its own class, I run into a cross-reference issue and can't solve it.</p>
  
  <p><strong>F11.py</strong></p>
  
  <pre><code>app = Flask(__name__)
  db = SQLAlchemy(app)
  
  ...
  
  if __name__ == "__main__":
      app.run()
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class User(db.Model, UserMixin):
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(80), unique=True)
      password = db.Column(db.String)
  </code></pre>
  
  <p>The problem already starts here with <code>db.Model</code>. <code>db</code> is instantiated in the main <code>F11.py</code>, so how do I access it? If I just import it I would get a cross-reference error.</p>