# mribrahem/publish_py architecture

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

- Interactive diagram: https://gitdiagram.com/mribrahem/publish_py
- Repository: https://github.com/mribrahem/publish_py

## Overview

This is a Flask application providing translation-support tools for mdwiki. Its principal workflow accepts a ContentTranslation publish request, validates and formats it, refines the wikitext, publishes it to Wikipedia, and can link the result to Wikidata while recording publish data. Other substantial capabilities include OAuth login and token management, CX token retrieval, reference repair, reporting APIs, and coordinator/admin tools. The graph reflects documented behavior and shown call relationships; less-sampled feature wiring is left unasserted.

Main entry points: [`src/main_app/public/routes/publish/worker.py`](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/worker.py) (Publish processing), [`src/main_app/services/auth/token_manager.py`](https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/auth/token_manager.py) (Token lifecycle), [`src/main_app/database/services/pages/pages_query_service.py`](https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/services/pages/pages_query_service.py) (Page queries), [`src/main_app/public/routes/publish/routes.py`](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/routes.py) (Publish endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entrypoints"]
  node_app["Flask application<br/>[__init__.py]"]
  node_td_results["Translation results"]
end

subgraph group_publishing["Translation publishing"]
  node_publish_routes["Publish endpoint<br/>[routes.py]"]
  node_publish_worker["Publish processing<br/>[worker.py]"]
  node_publish_db["Publish records<br/>[to_db.py]"]
  node_mw_oauth["MediaWiki API<br/>[oauth_client.py]"]
  node_refs["Reference repair<br/>[routes.py]"]
  node_text_api["Text API client<br/>[text_api.py]"]
  node_html_services["HTML processing"]
end

subgraph group_identity["Identity and tokens"]
  node_auth_routes["OAuth routes<br/>[routes.py]"]
  node_auth_flow["OAuth flow<br/>[flow.py]"]
  node_token_manager["Token lifecycle<br/>[token_manager.py]"]
  node_cx_routes["CX token endpoint<br/>[routes.py]"]
end

subgraph group_data["Data and reporting"]
  node_token_service["User token service"]
  node_database[("Application database<br/>[data_base.py]")]
  node_models["Domain records<br/>[pages.py]"]
  node_report_api["Reporting API<br/>[routes.py]"]
  node_top_stats["Top statistics"]
  node_pages_query["Page queries"]
end

subgraph group_operations["Operations tools"]
  node_coordinator["Coordinator tools"]
  node_admin["Admin tools"]
end

node_user(("Tool user"))
node_wikipedia(("Wikipedia"))
node_wikidata(("Wikidata"))

node_user -->|"submits content"| node_publish_routes
node_publish_routes -->|"processes edit"| node_publish_worker
node_publish_worker -->|"records result"| node_publish_db
node_publish_worker -->|"uses API client"| node_mw_oauth
node_mw_oauth -->|"publishes edits"| node_wikipedia
node_publish_worker -->|"links articles"| node_wikidata
node_user -.->|"requests repairs"| node_refs
node_refs -->|"uses client"| node_text_api
node_user -->|"starts login"| node_auth_routes
node_auth_routes -->|"delegates OAuth"| node_auth_flow
node_auth_flow -.->|"manages credentials"| node_token_manager
node_token_manager -->|"reads and writes"| node_token_service
node_token_manager -.->|"persists tokens"| node_database
node_user -->|"requests CX token"| node_cx_routes
node_cx_routes -->|"looks up credentials"| node_token_service
node_user -.->|"requests reports"| node_report_api
node_report_api -->|"routes statistics"| node_top_stats
node_top_stats -.->|"queries statistics"| node_pages_query
node_pages_query -->|"queries records"| node_models
node_pages_query -->|"reads data"| node_database
node_user -.->|"manages translations"| node_coordinator
node_user -.->|"administers tools"| node_admin
node_user -.->|"views results"| node_td_results
node_user -.->|"requests HTML"| node_html_services

click node_app "https://github.com/mribrahem/publish_py/blob/main/src/main_app/__init__.py"
click node_publish_routes "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/routes.py"
click node_publish_worker "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/worker.py"
click node_publish_db "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/to_db.py"
click node_mw_oauth "https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/clients/oauth_client.py"
click node_refs "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/refs/routes.py"
click node_text_api "https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/clients/text_api.py"
click node_auth_routes "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/auth/routes.py"
click node_auth_flow "https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/auth/flow.py"
click node_token_manager "https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/auth/token_manager.py"
click node_token_service "https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/services/users/user_token_service.py"
click node_cx_routes "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/cxtoken/routes.py"
click node_database "https://github.com/mribrahem/publish_py/blob/main/src/main_app/extensions/data_base.py"
click node_models "https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/models/pages.py"
click node_report_api "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/api/routes.py"
click node_top_stats "https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/api/top_stats_routes.py"
click node_pages_query "https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/services/pages/pages_query_service.py"
click node_coordinator "https://github.com/mribrahem/publish_py/tree/main/src/main_app/coordinators/routes"
click node_admin "https://github.com/mribrahem/publish_py/tree/main/src/main_app/admin"
click node_td_results "https://github.com/mribrahem/publish_py/tree/main/src/main_app/public/routes/td/results_2026"
click node_html_services "https://github.com/mribrahem/publish_py/tree/main/src/main_app/services/new_html_services"

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_app,node_td_results,node_user toneBlue
class node_publish_routes,node_publish_worker,node_publish_db,node_mw_oauth,node_refs,node_text_api,node_html_services toneAmber
class node_auth_routes,node_auth_flow,node_token_manager,node_cx_routes toneMint
class node_token_service,node_database,node_models,node_report_api,node_top_stats,node_pages_query toneRose
class node_coordinator,node_admin,node_wikipedia,node_wikidata toneIndigo
```

## Components

### Web entrypoints

- [Flask application](https://github.com/mribrahem/publish_py/blob/main/src/main_app/__init__.py): `src/main_app/__init__.py`
- [Translation results](https://github.com/mribrahem/publish_py/tree/main/src/main_app/public/routes/td/results_2026): `src/main_app/public/routes/td/results_2026`

### Translation publishing

- [Publish endpoint](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/routes.py): `src/main_app/public/routes/publish/routes.py`
- [Publish processing](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/worker.py): `src/main_app/public/routes/publish/worker.py`
- [Publish records](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/publish/to_db.py): `src/main_app/public/routes/publish/to_db.py`
- [MediaWiki API](https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/clients/oauth_client.py): `src/main_app/services/clients/oauth_client.py`
- [Reference repair](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/refs/routes.py): `src/main_app/public/routes/refs/routes.py`
- [Text API client](https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/clients/text_api.py): `src/main_app/services/clients/text_api.py`
- [HTML processing](https://github.com/mribrahem/publish_py/tree/main/src/main_app/services/new_html_services): `src/main_app/services/new_html_services`

### Identity and tokens

- [OAuth routes](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/auth/routes.py): `src/main_app/public/auth/routes.py`
- [OAuth flow](https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/auth/flow.py): `src/main_app/services/auth/flow.py`
- [Token lifecycle](https://github.com/mribrahem/publish_py/blob/main/src/main_app/services/auth/token_manager.py): `src/main_app/services/auth/token_manager.py`
- [CX token endpoint](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/cxtoken/routes.py): `src/main_app/public/routes/cxtoken/routes.py`

### Data and reporting

- [User token service](https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/services/users/user_token_service.py): `src/main_app/database/services/users/user_token_service.py`
- [Application database](https://github.com/mribrahem/publish_py/blob/main/src/main_app/extensions/data_base.py): `src/main_app/extensions/data_base.py`
- [Domain records](https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/models/pages.py): `src/main_app/database/models/pages.py`
- [Reporting API](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/api/routes.py): `src/main_app/public/routes/api/routes.py`
- [Top statistics](https://github.com/mribrahem/publish_py/blob/main/src/main_app/public/routes/api/top_stats_routes.py): `src/main_app/public/routes/api/top_stats_routes.py`
- [Page queries](https://github.com/mribrahem/publish_py/blob/main/src/main_app/database/services/pages/pages_query_service.py): `src/main_app/database/services/pages/pages_query_service.py`

### Operations tools

- [Coordinator tools](https://github.com/mribrahem/publish_py/tree/main/src/main_app/coordinators/routes): `src/main_app/coordinators/routes`
- [Admin tools](https://github.com/mribrahem/publish_py/tree/main/src/main_app/admin): `src/main_app/admin`

### Other components

- **Tool user**
- **Wikipedia**
- **Wikidata**

## Connections

- Tool user → Publish endpoint: submits content (evidence: `README.md`)
- Publish endpoint → Publish processing: processes edit (evidence: `src/main_app/public/routes/publish/routes.py`)
- Publish processing → Publish records: records result (evidence: `src/main_app/public/routes/publish/worker.py`)
- Publish processing → MediaWiki API: uses API client (evidence: `src/main_app/public/routes/publish/worker.py`)
- MediaWiki API → Wikipedia: publishes edits (evidence: `README.md`)
- Publish processing → Wikidata: links articles (evidence: `README.md`)
- Tool user → Reference repair: requests repairs
- Reference repair → Text API client: uses client (evidence: `src/main_app/public/routes/refs/routes.py`)
- Tool user → OAuth routes: starts login (evidence: `src/main_app/public/auth/routes.py`)
- OAuth routes → OAuth flow: delegates OAuth (evidence: `src/main_app/public/auth/routes.py`)
- OAuth flow → Token lifecycle: manages credentials
- Token lifecycle → User token service: reads and writes (evidence: `src/main_app/services/auth/token_manager.py`)
- Token lifecycle → Application database: persists tokens
- Tool user → CX token endpoint: requests CX token (evidence: `README.md`)
- CX token endpoint → User token service: looks up credentials (evidence: `src/main_app/public/routes/cxtoken/routes.py`)
- Tool user → Reporting API: requests reports
- Reporting API → Top statistics: routes statistics (evidence: `src/main_app/public/routes/api/routes.py`)
- Top statistics → Page queries: queries statistics
- Page queries → Domain records: queries records (evidence: `src/main_app/database/services/pages/pages_query_service.py`)
- Page queries → Application database: reads data (evidence: `src/main_app/database/services/pages/pages_query_service.py`)
- Tool user → Coordinator tools: manages translations
- Tool user → Admin tools: administers tools
- Tool user → Translation results: views results
- Tool user → HTML processing: requests HTML
