""" Shared SQLAlchemy instance. Kept in its own module (rather than inside models.py or app.py) so that every part of the application — auth, history, etc. — can import the same `db` object without circular imports. """ from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def init_db(app): """Bind SQLAlchemy to the Flask app and create tables if they don't exist.""" db.init_app(app) with app.app_context(): # Import models here so they're registered on db.metadata before create_all() from auth.models import User # noqa: F401 from history.models import ChatSession, ChatMessage # noqa: F401 db.create_all()