# cbcgb-com/sgbs-training architecture

> Architecture diagram of the GitHub repository cbcgb-com/sgbs-training, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cbcgb-com/sgbs-training
- Repository: https://github.com/cbcgb-com/sgbs-training

## Overview

1. **Repository purpose**
   - This repo supports a Chinese Bible-study training program (“小組查經帶領訓練”).
   - Architecturally it is not just a single app: it combines a training website, an authenticated application, content/docs, and a few tooling/scripts for generating or validating training materials.

2. **Two main user-facing surfaces**
   - **`apps/`** appears to be the runtime web application layer, with `app.py`, `api.py`, HTML templates, and static assets.
   - **`docs/`** is a separate documentation/knowledge site, likely built with MkDocs, containing class notes, resources, examples, and teaching prep material.

3. **Application runtime boundary**
   - `apps/app.py` is likely the main web server entrypoint.
   - `apps/api.py` suggests a lightweight internal API or route layer separate from page rendering.
   - `apps/templates/template.html` and `apps/static/` indicate server-rendered pages with static frontend assets rather than a full SPA.

4. **Core domain package**
   - The `sgbs_training/` package contains the reusable application logic:
     - `authentication.py` for access control / login checks
     - `api.py` for API-facing logic
     - `docs.py` for documentation/content retrieval or rendering
     - `email.py` for message generation/sending
     - `exercises.py` for training exercise logic
     - `scriptures.py` for Bible text/reference handling
   - This suggests a clean separation between web entrypoints and domain/services code.

5. **Content and learning workflow**
   - The repo centers on instructional content: lesson foundations, narrative/questioning/argumentation, study-note examples, and teaching resources.
   - `sgbs_training/exercises.py` and `sgbs_training/scriptures.py` likely power interactive study workflows by combining exercise prompts with scripture references and model answers/examples from `docs/examples/`.

6. **Authentication and user gating**
   - `sgbs_training/authentication.py` plus `apps/users.txt` imply a simple user list or access whitelist rather than a large identity provider.
   - This is an important boundary: some content or tools are probably restricted to trainees or instructors, while the MkDocs content may be public or semi-public.

7. **Email and generated artifacts**
   - `sgbs_training/email.py` and `deployments/email_generator.py` indicate an email-oriented distribution path, likely for sending class updates, study materials, or generated notifications.
   - This is separate from the web app path and represents a batch/offline output channel.

8. **Documentation site architecture**
   - `mkdocs.yml` plus `docs/` indicate a documentation site with:
     - class notes
     - examples
     - resources
     - templates and styles
     - custom JavaScript for UI behavior
   - The docs tree functions as the canonical curriculum/content repository, not just supplemental readme files.

9. **Custom docs behavior**
   - `docs/javascripts/chinese-toggle.js` and `expandable-cards.js` suggest interactive documentation features.
   - `docs/stylesheets/extra.css` and `transition.css` imply custom branding and presentation, likely for a polished teaching site rather than plain docs.

10. **Operational/deployment layer**
   - `.github/workflows/` contains separate pipelines for preview, app deployment, website deployment, and merge scheduling.
   - `Dockerfile` indicates containerized execution/deployment.
   - The repo therefore has at least two deployable targets: the application and the documentation website.

11. **Automation and validation tooling**
   - `notebooks/` contains exploratory/prototype work, including auth checks and Google Docs automation prototypes.
   - `pyproject.toml`, `pixi.lock`, `.pre-commit-config.yaml`, and `.markdownlint.json` show a Python-centric development workflow with formatting/linting and environment locking.
   - These are support systems around the main product, not core runtime components.

12. **Likely high-level data flow**
   - Training content is authored in `docs/` and perhaps transformed/consumed by `sgbs_training/docs.py`.
   - The web app (`apps/` + `sgbs_training/`) serves authenticated users, combining scripture/exercise logic with templates/static assets.
   - Email generation (`deployments/email_generator.py` / `sgbs_training/email.py`) produces outbound communications from the same content base.
   - CI/CD then publishes the app and docs as separate artifacts.

13. **Architecture diagram boundary suggestions**
   - Draw three major boxes:
     - **Documentation/Curriculum Site** (`docs/`, `mkdocs.yml`)
     - **Authenticated Training App** (`apps/`, `sgbs_training/`)
     - **Automation/Deployment** (`deployments/`, `.github/workflows/`, `Dockerfile`, notebooks)
   - Show shared content flowing from the docs/content layer into the app and email tooling.

Main entry points: [`mkdocs.yml`](https://github.com/cbcgb-com/sgbs-training/blob/master/mkdocs.yml) (MkDocs), [`apps/app.py`](https://github.com/cbcgb-com/sgbs-training/blob/master/apps/app.py) (App server), [`sgbs_training/docs.py`](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/docs.py) (Content), [`docs/index.md`](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/index.md) (Home)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_docs["Documentation site"]
  node_mkdocs["MkDocs<br/>site config<br/>[mkdocs.yml]"]
  node_docs_home["Home<br/>docs entry<br/>[index.md]"]
  node_lesson1["Foundations<br/>lesson note"]
  node_example_notes["Study notes<br/>example content"]
  node_resource_notes["Resources<br/>reference content"]
  node_docs_js["Doc scripts<br/>ui behavior<br/>[chinese-toggle.js]"]
  node_docs_css["Doc styles<br/>theme styles<br/>[extra.css]"]
  node_docs_theme["Dark theme<br/>template<br/>[dark.html]"]
end

subgraph group_app["Training app"]
  node_web_app["App server<br/>web entrypoint<br/>[app.py]"]
  node_web_api["App API<br/>route layer<br/>[api.py]"]
  node_web_template["Page template<br/>server template<br/>[template.html]"]
  node_web_static["Static assets<br/>frontend assets"]
  node_users_list["Users list<br/>access list<br/>[users.txt]"]
end

subgraph group_core["Domain package"]
  node_auth["Auth<br/>access control<br/>[authentication.py]"]
  node_core_api["Core API<br/>service layer<br/>[api.py]"]
  node_content["Content<br/>[docs.py]"]
  node_scriptures["Scriptures<br/>reference service<br/>[scriptures.py]"]
  node_exercises["Exercises<br/>training logic<br/>[exercises.py]"]
  node_mail["Email<br/>message service<br/>[email.py]"]
end

subgraph group_automation["Automation"]
  node_email_gen["Email gen<br/>batch generator<br/>[email_generator.py]"]
  node_deploy_app["Deploy app<br/>ci pipeline<br/>[deploy-app.yaml]"]
  node_deploy_site["Deploy site<br/>ci pipeline"]
  node_preview["Preview build<br/>ci pipeline<br/>[build-preview.yaml]"]
  node_schedule["Merge schedule<br/>ci automation"]
  node_docker["Docker<br/>container build"]
end

node_mkdocs -->|"publishes"| node_docs_home
node_mkdocs -->|"loads"| node_docs_js
node_mkdocs -->|"styles"| node_docs_css
node_mkdocs -->|"themes"| node_docs_theme
node_docs_home -->|"links"| node_lesson1
node_docs_home -->|"links"| node_example_notes
node_docs_home -->|"links"| node_resource_notes
node_web_app -->|"renders"| node_web_template
node_web_app -->|"serves"| node_web_static
node_web_app -->|"routes"| node_web_api
node_web_app -->|"checks"| node_auth
node_web_api -->|"uses"| node_core_api
node_web_api -->|"drives"| node_exercises
node_web_api -->|"reads"| node_scriptures
node_auth -->|"validates"| node_users_list
node_content -->|"reads"| node_lesson1
node_content -->|"reads"| node_example_notes
node_content -->|"reads"| node_resource_notes
node_exercises -->|"references"| node_scriptures
node_exercises -->|"uses"| node_content
node_mail -->|"composes"| node_content
node_email_gen -->|"produces"| node_mail
node_email_gen -->|"uses"| node_content
node_deploy_app -->|"builds"| node_docker
node_deploy_app -->|"deploys"| node_web_app
node_deploy_site -->|"builds"| node_mkdocs
node_deploy_site -->|"publishes"| node_docs_home
node_preview -->|"validates"| node_mkdocs
node_preview -->|"validates"| node_web_app
node_schedule -->|"coordinates"| node_deploy_app
node_schedule -->|"coordinates"| node_deploy_site

click node_mkdocs "https://github.com/cbcgb-com/sgbs-training/blob/master/mkdocs.yml"
click node_docs_home "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/index.md"
click node_lesson1 "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/class-notes/lesson-1-foundations.md"
click node_example_notes "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/examples/luke-study-notes.md"
click node_resource_notes "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/resources/bible-study-notes.md"
click node_docs_js "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/javascripts/chinese-toggle.js"
click node_docs_css "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/stylesheets/extra.css"
click node_docs_theme "https://github.com/cbcgb-com/sgbs-training/blob/master/docs/templates/dark.html"
click node_web_app "https://github.com/cbcgb-com/sgbs-training/blob/master/apps/app.py"
click node_web_api "https://github.com/cbcgb-com/sgbs-training/blob/master/apps/api.py"
click node_web_template "https://github.com/cbcgb-com/sgbs-training/blob/master/apps/templates/template.html"
click node_web_static "https://github.com/cbcgb-com/sgbs-training/tree/master/apps/static"
click node_users_list "https://github.com/cbcgb-com/sgbs-training/blob/master/apps/users.txt"
click node_auth "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/authentication.py"
click node_core_api "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/api.py"
click node_content "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/docs.py"
click node_scriptures "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/scriptures.py"
click node_exercises "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/exercises.py"
click node_mail "https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/email.py"
click node_email_gen "https://github.com/cbcgb-com/sgbs-training/blob/master/deployments/email_generator.py"
click node_deploy_app "https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/deploy-app.yaml"
click node_deploy_site "https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/deploy-website.yaml"
click node_preview "https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/build-preview.yaml"
click node_schedule "https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/merge-schedule.yaml"
click node_docker "https://github.com/cbcgb-com/sgbs-training/tree/master/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mkdocs,node_docs_home,node_lesson1,node_example_notes,node_resource_notes,node_docs_js,node_docs_css,node_docs_theme toneBlue
class node_web_app,node_web_api,node_web_template,node_web_static,node_users_list toneAmber
class node_auth,node_core_api,node_content,node_scriptures,node_exercises,node_mail toneMint
class node_email_gen,node_deploy_app,node_deploy_site,node_preview,node_schedule,node_docker toneRose
```

## Components

### Documentation site

Curriculum, examples, and MkDocs presentation layer.

- [MkDocs](https://github.com/cbcgb-com/sgbs-training/blob/master/mkdocs.yml): site config · MkDocs configuration for the documentation/teaching site. · `mkdocs.yml`
- [Home](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/index.md): docs entry · Main documentation landing page. · `docs/index.md`
- [Foundations](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/class-notes/lesson-1-foundations.md): lesson note · Representative class note for foundational training content. · `docs/class-notes/lesson-1-foundations.md`
- [Study notes](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/examples/luke-study-notes.md): example content · Representative worked example used as curriculum material. · `docs/examples/luke-study-notes.md`
- [Resources](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/resources/bible-study-notes.md): reference content · Representative resource page for training references and guidance. · `docs/resources/bible-study-notes.md`
- [Doc scripts](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/javascripts/chinese-toggle.js): ui behavior · Interactive documentation behaviors for Chinese toggles and expandable cards. · `docs/javascripts/chinese-toggle.js`
- [Doc styles](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/stylesheets/extra.css): theme styles · Custom documentation styling and transitions. · `docs/stylesheets/extra.css`
- [Dark theme](https://github.com/cbcgb-com/sgbs-training/blob/master/docs/templates/dark.html): template · Custom documentation theme override. · `docs/templates/dark.html`

### Training app

Authenticated web app and server-rendered interface.

- [App server](https://github.com/cbcgb-com/sgbs-training/blob/master/apps/app.py): web entrypoint · Main authenticated web application entrypoint. · `apps/app.py`
- [App API](https://github.com/cbcgb-com/sgbs-training/blob/master/apps/api.py): route layer · Lightweight application API/route layer. · `apps/api.py`
- [Page template](https://github.com/cbcgb-com/sgbs-training/blob/master/apps/templates/template.html): server template · Primary HTML template for rendered pages. · `apps/templates/template.html`
- [Static assets](https://github.com/cbcgb-com/sgbs-training/tree/master/apps/static): frontend assets · Static files served by the application. · `apps/static`
- [Users list](https://github.com/cbcgb-com/sgbs-training/blob/master/apps/users.txt): access list · Simple user whitelist used by authentication checks. · `apps/users.txt`

### Domain package

Reusable training logic shared by the app, docs helpers, and generators.

- [Auth](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/authentication.py): access control · Login and authorization checks. · `sgbs_training/authentication.py`
- [Core API](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/api.py): service layer · Shared API-facing logic used by the application. · `sgbs_training/api.py`
- [Content](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/docs.py): content service · Documentation/content retrieval and rendering helpers. · `sgbs_training/docs.py`
- [Scriptures](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/scriptures.py): reference service · Bible text and reference handling. · `sgbs_training/scriptures.py`
- [Exercises](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/exercises.py): training logic · Exercise generation and study workflow logic. · `sgbs_training/exercises.py`
- [Email](https://github.com/cbcgb-com/sgbs-training/blob/master/sgbs_training/email.py): message service · Email/message generation and sending support. · `sgbs_training/email.py`

### Automation

Deployment, containerization, and offline generation pipelines.

- [Email gen](https://github.com/cbcgb-com/sgbs-training/blob/master/deployments/email_generator.py): batch generator · Offline generator for email-oriented outputs. · `deployments/email_generator.py`
- [Deploy app](https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/deploy-app.yaml): ci pipeline · Workflow for building and deploying the training app. · `.github/workflows/deploy-app.yaml`
- [Deploy site](https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/deploy-website.yaml): ci pipeline · Workflow for building and deploying the documentation website. · `.github/workflows/deploy-website.yaml`
- [Preview build](https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/build-preview.yaml): ci pipeline · Workflow for preview/test builds. · `.github/workflows/build-preview.yaml`
- [Merge schedule](https://github.com/cbcgb-com/sgbs-training/blob/master/.github/workflows/merge-schedule.yaml): ci automation · Scheduled merge or maintenance workflow. · `.github/workflows/merge-schedule.yaml`
- [Docker](https://github.com/cbcgb-com/sgbs-training/tree/master/Dockerfile): container build · Container image definition for runtime/deployment. · `Dockerfile`

## Connections

- MkDocs → Home: publishes · MkDocs serves the documentation home and site structure.
- MkDocs → Doc scripts: loads · Docs site includes custom interactive JavaScript.
- MkDocs → Doc styles: styles · Docs site uses custom styling overrides.
- MkDocs → Dark theme: themes · Docs site uses a custom theme template.
- Home → Foundations: links · The docs site connects the home page to curriculum notes.
- Home → Study notes: links · The docs site connects the home page to worked examples.
- Home → Resources: links · The docs site connects the home page to study resources.
- App server → Page template: renders · Server entrypoint renders HTML pages via templates.
- App server → Static assets: serves · Application serves static assets alongside pages.
- App server → App API: routes · Main app delegates route/API handling to its API layer.
- App server → Auth: checks · Web app depends on authentication for gated access.
- App API → Core API: uses · Application API layer uses shared service logic.
- App API → Exercises: drives · API routes expose training exercise workflows.
- App API → Scriptures: reads · API routes use scripture/reference lookups.
- Auth → Users list: validates · Authentication checks against a simple user whitelist.
- Content → Foundations: reads · Content service consumes curriculum notes.
- Content → Study notes: reads · Content service consumes example study materials.
- Content → Resources: reads · Content service consumes supporting resources.
- Exercises → Scriptures: references · Exercise logic is grounded in Bible text and references.
- Exercises → Content: uses · Exercises draw from stored teaching content and examples.
- Email → Content: composes · Email generation uses shared curriculum/content material.
- Email gen → Email: produces · Offline generator produces email-ready output through the mail layer.
- Email gen → Content: uses · Batch email generation consumes the same training content base.
- Deploy app → Docker: builds · App deployment workflow uses container build artifacts.
- Deploy app → App server: deploys · Workflow deploys the authenticated application.
- Deploy site → MkDocs: builds · Website workflow builds the docs site.
- Deploy site → Home: publishes · Website workflow publishes the documentation content.
- Preview build → MkDocs: validates · Preview workflow validates docs builds.
- Preview build → App server: validates · Preview workflow also exercises the app build.
- Merge schedule → Deploy app: coordinates · Scheduled automation coordinates with deployment workflows.
- Merge schedule → Deploy site: coordinates · Scheduled automation coordinates with website publication.
