# Developer & AI Handoff Guide — BCT Website

Read this first if you are a developer or an AI assistant (ChatGPT, Claude, etc.) asked to change this site.
Pair it with `CHANGELOG.md` (what changed and why) and `INSTALL.md` (how it is deployed).

- **Site:** https://bandjouncommunitytexas.org — Bandjoun Community of Texas (BCT), a 501(c)(3) Cameroonian
  diaspora nonprofit in Houston, Texas. Built and maintained by The Yong Technologies.
- **Version:** see `VERSION` (1.5.3 at time of writing). Bump it and add a `CHANGELOG.md` entry with every change.
- **Stack:** Python 3.9+ (production: 3.11 on AlmaLinux 8), Flask 3, Flask-SQLAlchemy (SQLite), Flask-Login,
  Flask-WTF (CSRF), Pillow, nh3 (HTML sanitising), pyotp + segno (2-step login), gunicorn (optional).
  No JavaScript build step: plain HTML templates, one CSS file and one JS file per side (public/admin).

---

## 1. Rules for anyone changing this site

1. **Bilingual everything.** Every visible string exists in English and French.
   - Interface labels (menus, buttons) → `i18n.py` `STRINGS` as `("English", "Français")`.
   - Page text → a `ContentBlock` (editable in Admin › Page Content) with `en`/`fr`.
   - Database records → paired `*_en` / `*_fr` columns, read with `tr(obj, 'field')` (French falls back to English).
2. **Never hard-code content the client may want to edit.** Put it in a content block or a setting.
3. **Keep the database upgradeable.** New columns → add them in `models.py` *and* an `ALTER TABLE` in
   `app._migrate()` (SQLite `create_all` never alters existing tables). New content blocks → add to
   `content_seed.BLOCKS`; `_migrate()` inserts missing keys on live sites without touching existing ones.
4. **Never break existing URLs** (they are in Google and shared links). Rename labels, not routes.
5. **Escape names inside JavaScript** with `|tojson` inside a single-quoted attribute
   (`onsubmit='return confirm({{ ("Delete " ~ name ~ "?")|tojson }})'`). An apostrophe once broke a
   delete confirmation so the browser deleted without asking (fixed 1.2.0).
6. **Admin forms post with CSRF** (`<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">`);
   `fetch()` calls send the `X-CSRFToken` header (see `static/js/admin.js` `post()`).
7. **Rich text is sanitised** with `utils.clean_html()` before saving (allowed tags in `utils.ALLOWED_TAGS`).
8. **Log admin actions** with `log("…")` in `admin.py` (shows in Activity Log).
9. **Super-Admin-only** pages use `@super_required` (Settings, Users, Activity, Backup).
10. **Test before shipping** (section 9) and give the client an update zip plus exact commands.
    The client runs the site himself with `python app.py` on a cPanel account (section 8).

---

## 2. File map

```
app.py            App factory: settings, DB, _migrate(), language selection, template helpers
                  (c(), tr(), t(), media_url(), random_banner(), setting()), security headers, /media route.
public.py         Public pages (blueprint "public"), contact form, sitemap.xml, robots.txt.
admin.py          Admin section (blueprint "admin", prefix /admin): auth/2FA, all management pages.
models.py         SQLAlchemy models + get_setting()/set_setting().
cli.py            Flask CLI: import-content, import-album, add-past-board, create-admin, reset-password.
content_seed.py   Initial bilingual content: BLOCKS, SETTINGS, BOARD, PAST_BOARD, ALBUMS, ALBUM_COVERS,
                  EVENTS, ADMINS (password hashes only).
i18n.py           Interface strings EN/FR, month/weekday names, format_date().
media.py          Image pipeline: web (1920px) + thumb (640px) JPEGs, dHash duplicate detection,
                  video poster via ffmpeg (optional), safe delete.
mailer.py         SMTP sending (settings.ini [smtp]); async send for contact form.
config.py         settings.ini loader/writer (secret key auto-generated on first run).
utils.py          clean_html, slugify, client_ip, text_to_html.
wsgi.py / gunicorn.conf.py   Production entry points (gunicorn optional).
start.sh stop.sh restart.sh status.sh _common.sh   Manual process management (cPanel, no systemd).
VERSION           Current version string (shown in admin sidebar).
templates/        base.html (layout, menu, footer, SEO), home, about, president, board (current+past),
                  events, gallery, album, contact, donate, 404, partials (_icons, _cta, _lightbox),
                  admin/*.html.
static/css/site.css   Public styles (CSS variables at top = brand palette).
static/css/admin.css  Admin styles.
static/js/site.js     Menu, slideshow, lightbox, copy buttons, reveal-on-scroll.
static/js/admin.js    Tabs, Quill editor init, SortableJS reorder, bulk uploader, captions, gallery picker.
static/vendor/        Quill 1.3.7 + SortableJS 1.15.2 (bundled, no CDN).
static/img/           BCT logo (circular cut-outs), favicon, social image, Yong Technologies logo.
content/              Original content used by import-content (photos, docs, albums, Past Executive Board).
deploy/               install.sh, update.sh, bct.service, nginx-bct.conf, cpanel-apache-proxy.conf,
                      cpanel-htaccess.txt.
instance/bct.db       SQLite database (created at runtime — NOT in the package).
uploads/              Processed photos/videos (created at runtime — NOT in the package).
settings.ini          Live settings incl. SMTP password (created at runtime — NOT in the package).
```

## 3. Data model (`models.py`)

| Model | Key fields | Notes |
|---|---|---|
| `User` | username, password_hash, role (`superadmin`/`editor`), totp_secret, totp_enabled, failed_attempts, locked_until | Admin accounts |
| `ContentBlock` | key, group, label, kind (`text`/`html`/`lines`), en, fr | Page text; `c('key')` in templates. `lines` → list |
| `ContentVersion` | block_key, en, fr, saved_at, saved_by | History for Restore |
| `Setting` | key, value | `get_setting()` / `set_setting()` |
| `BoardMember` | name, title_en, title_fr, photo, sort, visible, **board** (`current`/`past`) | First by `sort` = President, shown large |
| `Event` | title_en/fr, event_date, time_text, location_en/fr, description_en/fr (HTML), link_url, image, published | Past = `event_date < utils.today_local()` (Houston date, automatic) |
| `Album` | slug, title_en/fr, description_en/fr, cover_id, sort, visible | One menu item per visible album |
| `Photo` | album_id, kind (`image`/`video`), original, web, thumb, width, height, phash, caption_en/fr, sort, hidden | Paths relative to `uploads/` |
| `Slide` | image, thumb, caption_en/fr, sort, visible | Home slideshow |
| `Message` | name, email, phone, city, subject, body, ip, lang, is_read, email_status | Contact form inbox |
| `Activity` | username, action, ip, created_at | Activity Log |

**Content block keys:** home.welcome_title, home.hero_tagline, home.president_heading, home.president_excerpt,
about.title, about.intro, about.mission, about.vision, about.objectives_list, about.values_list,
about.values_closing, president.salutation, president.message, president.name, president.title, board.term,
board.past_term, board.past_intro, board.intro, events.intro, contact.intro, donate.intro, donate.tax_text.

**Setting keys:** identification_form_url, contact_email, zelle_email, zelle_name, ein, zelle_qr,
slideshow_interval, random_banner, president_photo, random_order_albums
(comma-separated album slugs whose photos are shown in random order).

## 4. Routes

**Public:** `/` · `/about` · `/about/president` · `/about/executive-board` (current board) ·
`/about/past-executive-boards` · `/events` · `/gallery` · `/gallery/<slug>` · `/join` (redirect to Google Form) ·
`/donate` · `/contact` (GET/POST) · `/robots.txt` · `/sitemap.xml` · `/media/<path>` (uploads).
Language: `?lang=en|fr` (remembered in the session; default from the browser).

**Admin (`/admin`):** login, 2fa, logout, dashboard, content (+ revert, president-photo), board (`?board=past`),
board/new, board/<id>, events, albums (+ settings, upload, bulk, picker, delete), photos/<id>/caption,
reorder/<kind> (JSON), slides (+ from-gallery), messages (+ export.csv), settings, users, account, activity, backup.

## 5. Common tasks — where to change things

| Task | Where |
|---|---|
| Add a menu item | `templates/base.html` (desktop/mobile menu and footer quick links) + label in `i18n.py` |
| Add a public page | route in `public.py`, template extending `base.html` (set `title`, `description`, `crumbs` block), add path to `sitemap()` |
| Add editable page text | add a tuple to `content_seed.BLOCKS` (auto-added on live sites at startup), use `{{ c('key') }}` |
| Add a site setting | `content_seed.SETTINGS` default + `SITE_KEYS` and form field in `admin.py`/`templates/admin/settings.html` |
| Add a DB column | `models.py` + `ALTER TABLE` in `app._migrate()` |
| Change colours/fonts | top of `static/css/site.css` (`:root` variables); bump `?v=` on the CSS link in `base.html` |
| Add a photo album to the live site | Admin › Photo Galleries, or `flask --app app import-album Album.zip` |
| Change the form/Zelle/EIN/email | Admin › Settings & Email (no code change) |

## 6. Design system
- Palette: terracotta `#B0643F` (primary), dark `#8E4B2D`, charcoal `#3A3839`, seal red `#C8102E`,
  bead navy `#1F2E6B`, soft background `#F8F5F3`. White site, as on natso.com.
- Fonts: Figtree (UI/headings), Lora italic (quotes/signature), from Google Fonts.
- Signature details: bead-strip divider under the header, kicker labels (uppercase, letter-spaced, terracotta),
  12–16px rounded cards, random gallery photo banner on inner pages.
- Breakpoints: 1180 (wordmark hides), 1040 (mobile menu), 860, 600.

## 7. Security model
Hashed passwords (werkzeug scrypt), lockout (5 failures → 15 min), per-IP throttle, optional TOTP, 2-hour sessions,
`secure_cookies=true` in production (login works over HTTPS only), CSRF everywhere, nh3 sanitising, security
headers, admin `noindex`, contact-form honeypot + 3 messages / 15 min per IP, uploads validated by Pillow.

## 8. Production environment (client's setup)
- AlmaLinux 8.10, **cPanel account** `bandjouncommunit`, site folder `~/bct-website`, venv `~/bct-website/venv`
  (Python 3.11). Live folder is `~/public_html/bct-website` (`~/www` is a symlink to it); there is no global
  `python` command — always use the venv. The client manages it with `start.sh` / `stop.sh` / `restart.sh` /
  `status.sh` (venv python, port from settings.ini, `logs/app.log`, `bct.pid`; shared code in `_common.sh`).
- App listens on `127.0.0.1:8035` (settings.ini). Apache forwards the domain via `~/public_html/.htaccess`
  (`deploy/cpanel-htaccess.txt`). HTTPS by cPanel AutoSSL.
- Cron: `@reboot` start + every-5-minutes restart-if-down (see INSTALL.md).
- Deliver changes as a small update zip whose paths start with `bct-website/`, applied with
  `cd ~ && unzip -o update.zip`, then restart. Never include `settings.ini`, `instance/` or `uploads/`.

## 9. Test checklist before delivering a change
1. `python -c "import app"` imports cleanly; run `flask --app app import-content content --force` on a scratch copy.
2. Every public route returns 200 in EN and FR; `/sitemap.xml` lists new pages.
3. Admin: log in, open every admin page, exercise the changed form; check CSRF is still required.
4. Upgrade path: copy new code over a copy of an *older* database and start — `_migrate()` must succeed and
   existing content must be unchanged.
5. Screenshots at 1440px and 390px (no sideways scroll on phones), EN and FR.
6. Bump `VERSION`, add a `CHANGELOG.md` entry, bump the CSS `?v=` if styles changed.
