Flask portfolio app (dark mode) with SQLAlchemy + Flask-WTF + Flask-Login, a Stripe Checkout store, a scikit-learn "mental health" predictor, and python-dotenv config. Windows / PowerShell; Python lives in the repo-local venv/.
Run from the repo root (the ML route loads classificador.pkl with a CWD-relative path).
# Install deps
.\venv\Scripts\pip install -r requirements.txt
# Env + DB (both required before first boot)
Copy-Item .env.example .env # then set STRIPE keys
.\venv\Scripts\python seed.py # tables + admin user + sample data
# Dev server (debug=True, http://127.0.0.1:5000)
.\venv\Scripts\python app.py
# Tests (in-memory DB via tests/conftest.py; does NOT touch instance/portfolio.db)
.\venv\Scripts\python -m pytest tests -q
# Focused
.\venv\Scripts\python -m pytest tests/test_loja.py -v
.\venv\Scripts\python -m pytest "tests/test_blog_flow.py::test_usuario_exclui_proprio_post" -vNo lint, formatter, typecheck, or CI is configured. Current suite: 33 tests.
User-facing setup docs are in README.md; point users there instead of restating setup.
app.py— entrypoint.load_dotenv(), then config from.envwith fallbacks:SECRET_KEY,SQLALCHEMY_DATABASE_URI,STRIPE_SECRET_KEY,STRIPE_PUBLISHABLE_KEY,BASE_URL. Setsstripe.api_key, initsdb+login_manager, definesuser_loader, registers blueprints.db.create_all()runs only insideif __name__ == "__main__"(so importing app does not create tables;seed.pycalls it itself).- Context processor
inject_yearmakescurrent_year,perfil, andcsrf_tokenavailable to every template.perfil(and the hardcodedhabilidades/contato_info) live inblueprints/main.py. blueprints/main.py—main_bp:/,/contato,/data(hub page),/data_science_mental(endpointmain.data_science_metal, a deliberate typo used bydata/data.html), and/student_depression.blueprints/auth.py—/registro,/login,/logout;login_manager.login_view = "auth.login".blueprints/blog.py—blog_bp(/blog): list/detail + own-post CRUD; ownership via_pode_gerenciar_post()(admins can manage all).blueprints/loja.py—loja_bp:/loja,POST /loja/checkout/<id>(Stripe Sessionmode="payment",currency="usd", 303 redirect),/loja/sucesso,/loja/cancelado. No webhook; orders are not persisted.blueprints/admin.py—admin_bp(/admin): dashboard + CRUD behind@admin_required; DRY helpersCAMPOS_ITEM,_processar_item(),_excluir_item().models.py— shareddb;User,Projeto,Experiencia,Educacao,Post,Mensagem,Produto.forms.py— WTForms classes (one per model + login/registro/contato) plus the lowercasedata_science_mentalform.seed.py—db.create_all()+ admin (admin/admin123) + sample data. Without it there is no admin user.templates/— all pages extendbase.html; admin forms reuseadmin/item_form.html. Always use blueprint-prefixed endpoints inurl_for.
forms.py::data_science_mental(~23 fields) andDepressionFormfeedclassificador.pkl/student_depression01.pkl. Field names and posted values must match the pickled model's expected columns.main.data_science_metalandmain.student_depressionload the pickles withjoblib.load(CWD-relative, committed at repo root), build a one-row DataFrame, then callpredict()andpredict_proba().- Results render directly on POST (no session/redirect, so F5 re-submits) into
templates/data/data_science_mental_result.htmlanddepression_result.html: status, confidence, class distribution, curated summary + all answers, and disclaimers._calcular_probabilidades()hides the probability UI if a model lackspredict_proba. - Shared result markup lives in
templates/data/_result_components.html(Jinja macros). - Covered by
tests/test_data_science.py, which monkeypatchesblueprints.main.joblib.loadwith fake models (no real pickle or Stripe calls).
- Two styling systems coexist:
static/css/style.cssuses CSS variables toggled by[data-theme], whiletemplates/index.htmlandtemplates/data*.htmluse Tailwind CDN utilities (dark:variants) plus.theme-pagefor the page background. base.htmlloads Tailwind withdarkMode: 'class'; the theme toggle storesthemeinlocalStorage(defaultdark) and sets bothdata-themeand the.darkclass.style.cssneedsbody .container { max-width: 1080px }because Tailwind's.containerloads later and otherwise changes the navbar width between pages. Keep it.- New Tailwind pages must supply both light and
dark:classes; new CSS-variable pages should use the existing vars.
- DB is SQLite at
instance/portfolio.db. Schema comes only fromdb.create_all()— there are no migrations. Changing a column requires deleting the DB and re-runningseed.py. - Admin fields must be listed in
CAMPOS_ITEMor they will not be persisted._processar_item()repopulates the form from the DB after an invalid POST, overwriting submitted values — be aware if you touch validation/editing. - Admin
*_excluirroutes are plain GET links with no CSRF; blog delete is POST-only with CSRF (a GET to/blog/<id>/excluirmust return 405). Post.author_idis non-nullable; admin-created posts setauthor_id = current_user.id(notauthor = current_user).Projeto.tecnologiasis a comma-separated string — use thetecnologias_listaproperty.Produto.preco_centavosis USD cents — use thepreco_usdproperty.- CSRF is enabled everywhere. Tests scrape tokens with
conftest._csrf/csrf_para(client, path)and log in withconftest.login. - Tests build their own app in
tests/conftest.py(hardcoded config, in-memory SQLite) and never importapp.py, so.envis irrelevant to tests. Stripe is monkeypatched viastripe.checkout.Session.create; never call the real API in tests. .gitignoreexcludesvenv/,instance/,.env;.env.exampleandclassificador.pklare committed.SECRET_KEYand Stripe keys come from.env; the app has insecure dev fallbacks, so don't ship them.