# mashta-lilia/handwriter architecture

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

- Interactive diagram: https://gitdiagram.com/mashta-lilia/handwriter
- Repository: https://github.com/mashta-lilia/handwriter

## Overview

Handwritter is a web application for creating and downloading realistic handwritten documents, with Telegram OTP authentication. The main user journey is account registration and verification, then editing typed text and generating a canvas result for export. The README also documents login, password recovery, saved-document history, and generation progress over SSE. Authentication implementation is sampled; generation, history, and parts of the frontend API are not, so those links are documented or marked unverified rather than inferred from imports.

Main entry points: [`backend/api/auth/register.py`](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/register.py) (Auth endpoints), [`frontend/src/App.tsx`](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/App.tsx) (Page routing), [`backend/api/auth/recovery.py`](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/recovery.py) (Recovery endpoints), [`backend/services/auth/telegram.py`](https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/telegram.py) (Telegram delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Page routing<br/>[App.tsx]"]
  node_register_ui["Registration<br/>[RegisterPage.tsx]"]
  node_verify_ui["OTP verification"]
  node_login_ui["Login<br/>[LoginPage.tsx]"]
  node_recovery_ui["Password recovery"]
  node_auth_state["Auth state<br/>[authStore.ts]"]
  node_editor_ui["Handwriting editor<br/>[EditorPage.tsx]"]
  node_rich_editor["Rich text input<br/>[RichEditor.tsx]"]
  node_canvas["Canvas renderer"]
  node_editor_state["Editor state<br/>[editorStore.ts]"]
end

subgraph group_auth["Authentication"]
  node_auth_routes["Auth endpoints<br/>[register.py]"]
  node_recovery_routes["Recovery endpoints<br/>[recovery.py]"]
  node_auth_schema["Auth schemas<br/>[auth.py]"]
  node_token_service["Account and tokens<br/>[token_service.py]"]
  node_auth_crud["User queries<br/>[crud.py]"]
  node_security["Password and JWT<br/>[security.py]"]
  node_otp_service["OTP service<br/>[otp_service.py]"]
end

subgraph group_generation["Document generation"]
  node_generation_api["Generation API<br/>[generate.py]"]
  node_worker["Generation worker<br/>[tasks.py]"]
  node_history_api["Saved documents<br/>[history.py]"]
  node_document_result["Canvas result"]
end

subgraph group_platform["Persistence and integrations"]
  node_telegram_service["Telegram delivery<br/>[telegram.py]"]
  node_telegram_hook["Bot webhook<br/>[webhook.py]"]
  node_dependencies["Service dependencies<br/>[services.py]"]
  node_redis[("Redis OTP store<br/>[redis_client.py]")]
  node_user_model[("User records<br/>[user.py]")]
  node_database[("SQL database<br/>[database.py]")]
end

node_user(("User"))
node_telegram["Telegram Bot API"]
node_storage[("Image storage")]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_register_ui
node_app -->|"routes to"| node_verify_ui
node_app -->|"routes to"| node_login_ui
node_app -->|"routes to"| node_recovery_ui
node_app -->|"routes to"| node_editor_ui
node_register_ui -->|"starts registration"| node_auth_routes
node_verify_ui -->|"submits OTP"| node_auth_routes
node_login_ui -->|"authenticates"| node_auth_routes
node_recovery_ui -->|"requests reset"| node_recovery_routes
node_auth_routes -->|"validates with"| node_auth_schema
node_recovery_routes -->|"validates with"| node_auth_schema
node_auth_routes -->|"resolves services"| node_dependencies
node_recovery_routes -->|"resolves services"| node_dependencies
node_dependencies -->|"provides"| node_otp_service
node_dependencies -->|"provides"| node_telegram_service
node_dependencies -->|"provides"| node_token_service
node_auth_routes -->|"verifies OTP"| node_otp_service
node_auth_routes -->|"sends code"| node_telegram_service
node_auth_routes -->|"activates account"| node_token_service
node_recovery_routes -->|"verifies OTP"| node_otp_service
node_recovery_routes -->|"sends code"| node_telegram_service
node_recovery_routes -->|"updates password"| node_token_service
node_token_service -->|"queries users"| node_auth_crud
node_token_service -->|"hashes and signs"| node_security
node_auth_crud -->|"reads and writes"| node_user_model
node_user_model -->|"maps records"| node_database
node_otp_service -->|"stores OTP"| node_redis
node_telegram_service -->|"reads chat ID"| node_redis
node_telegram_hook -->|"records chat ID"| node_telegram_service
node_telegram_service -->|"sends messages"| node_telegram
node_editor_ui -->|"renders"| node_rich_editor
node_editor_ui -->|"renders"| node_canvas
node_editor_ui -.->|"uses state"| node_editor_state
node_user -->|"starts generation"| node_generation_api
node_generation_api -.->|"queues job"| node_worker
node_generation_api -->|"streams progress and result"| node_document_result
node_document_result -->|"renders words"| node_canvas
node_document_result -->|"references images"| node_storage
node_user -->|"lists documents"| node_history_api
node_history_api -->|"returns saved schema"| node_document_result

click node_app "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/App.tsx"
click node_register_ui "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/RegisterPage.tsx"
click node_verify_ui "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/VerifyRegistrationPage.tsx"
click node_login_ui "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/LoginPage.tsx"
click node_recovery_ui "https://github.com/mashta-lilia/handwriter/tree/main/frontend/src/pages"
click node_auth_state "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/store/authStore.ts"
click node_editor_ui "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/EditorPage.tsx"
click node_rich_editor "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/components/ui/RichEditor.tsx"
click node_canvas "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/components/canvas/HandwritingCanvas.tsx"
click node_editor_state "https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/store/editorStore.ts"
click node_auth_routes "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/register.py"
click node_recovery_routes "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/recovery.py"
click node_auth_schema "https://github.com/mashta-lilia/handwriter/blob/main/backend/schemas/auth.py"
click node_token_service "https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/token_service.py"
click node_auth_crud "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/crud.py"
click node_security "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/security.py"
click node_otp_service "https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/otp_service.py"
click node_telegram_service "https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/telegram.py"
click node_telegram_hook "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/telegram/webhook.py"
click node_dependencies "https://github.com/mashta-lilia/handwriter/blob/main/backend/dependencies/services.py"
click node_redis "https://github.com/mashta-lilia/handwriter/blob/main/backend/core/redis_client.py"
click node_user_model "https://github.com/mashta-lilia/handwriter/blob/main/backend/models/user.py"
click node_database "https://github.com/mashta-lilia/handwriter/blob/main/backend/core/database.py"
click node_generation_api "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/generate.py"
click node_worker "https://github.com/mashta-lilia/handwriter/blob/main/backend/worker/tasks.py"
click node_history_api "https://github.com/mashta-lilia/handwriter/blob/main/backend/api/history.py"

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_register_ui,node_verify_ui,node_login_ui,node_recovery_ui,node_auth_state,node_editor_ui,node_rich_editor,node_canvas,node_editor_state,node_user toneBlue
class node_auth_routes,node_recovery_routes,node_auth_schema,node_token_service,node_auth_crud,node_security,node_otp_service,node_storage toneAmber
class node_generation_api,node_worker,node_history_api,node_document_result,node_telegram toneMint
class node_telegram_service,node_telegram_hook,node_dependencies,node_redis,node_user_model,node_database toneRose
```

## Components

### Web application

- [Page routing](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Registration](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/RegisterPage.tsx): `frontend/src/pages/RegisterPage.tsx`
- [OTP verification](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/VerifyRegistrationPage.tsx): `frontend/src/pages/VerifyRegistrationPage.tsx`
- [Login](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/LoginPage.tsx): `frontend/src/pages/LoginPage.tsx`
- [Password recovery](https://github.com/mashta-lilia/handwriter/tree/main/frontend/src/pages): `frontend/src/pages`
- [Auth state](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/store/authStore.ts): `frontend/src/store/authStore.ts`
- [Handwriting editor](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/pages/EditorPage.tsx): `frontend/src/pages/EditorPage.tsx`
- [Rich text input](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/components/ui/RichEditor.tsx): `frontend/src/components/ui/RichEditor.tsx`
- [Canvas renderer](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/components/canvas/HandwritingCanvas.tsx): `frontend/src/components/canvas/HandwritingCanvas.tsx`
- [Editor state](https://github.com/mashta-lilia/handwriter/blob/main/frontend/src/store/editorStore.ts): `frontend/src/store/editorStore.ts`

### Authentication

- [Auth endpoints](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/register.py): `backend/api/auth/register.py`
- [Recovery endpoints](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/recovery.py): `backend/api/auth/recovery.py`
- [Auth schemas](https://github.com/mashta-lilia/handwriter/blob/main/backend/schemas/auth.py): `backend/schemas/auth.py`
- [Account and tokens](https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/token_service.py): `backend/services/auth/token_service.py`
- [User queries](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/crud.py): `backend/api/auth/crud.py`
- [Password and JWT](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/auth/security.py): `backend/api/auth/security.py`
- [OTP service](https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/otp_service.py): `backend/services/auth/otp_service.py`

### Document generation

- [Generation API](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/generate.py): `backend/api/generate.py`
- [Generation worker](https://github.com/mashta-lilia/handwriter/blob/main/backend/worker/tasks.py): `backend/worker/tasks.py`
- [Saved documents](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/history.py): `backend/api/history.py`
- **Canvas result**

### Persistence and integrations

- [Telegram delivery](https://github.com/mashta-lilia/handwriter/blob/main/backend/services/auth/telegram.py): `backend/services/auth/telegram.py`
- [Bot webhook](https://github.com/mashta-lilia/handwriter/blob/main/backend/api/telegram/webhook.py): `backend/api/telegram/webhook.py`
- [Service dependencies](https://github.com/mashta-lilia/handwriter/blob/main/backend/dependencies/services.py): `backend/dependencies/services.py`
- [Redis OTP store](https://github.com/mashta-lilia/handwriter/blob/main/backend/core/redis_client.py): `backend/core/redis_client.py`
- [User records](https://github.com/mashta-lilia/handwriter/blob/main/backend/models/user.py): `backend/models/user.py`
- [SQL database](https://github.com/mashta-lilia/handwriter/blob/main/backend/core/database.py): `backend/core/database.py`

### Other components

- **User**
- **Telegram Bot API**
- **Image storage**

## Connections

- User → Page routing: uses
- Page routing → Registration: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → OTP verification: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Login: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Password recovery: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Handwriting editor: routes to (evidence: `frontend/src/App.tsx`)
- Registration → Auth endpoints: starts registration
- OTP verification → Auth endpoints: submits OTP
- Login → Auth endpoints: authenticates
- Password recovery → Recovery endpoints: requests reset
- Auth endpoints → Auth schemas: validates with (evidence: `backend/api/auth/register.py`)
- Recovery endpoints → Auth schemas: validates with (evidence: `backend/api/auth/recovery.py`)
- Auth endpoints → Service dependencies: resolves services (evidence: `backend/api/auth/register.py`)
- Recovery endpoints → Service dependencies: resolves services (evidence: `backend/api/auth/recovery.py`)
- Service dependencies → OTP service: provides (evidence: `backend/dependencies/services.py`)
- Service dependencies → Telegram delivery: provides (evidence: `backend/dependencies/services.py`)
- Service dependencies → Account and tokens: provides (evidence: `backend/dependencies/services.py`)
- Auth endpoints → OTP service: verifies OTP (evidence: `backend/api/auth/register.py`)
- Auth endpoints → Telegram delivery: sends code (evidence: `backend/api/auth/register.py`)
- Auth endpoints → Account and tokens: activates account (evidence: `backend/api/auth/register.py`)
- Recovery endpoints → OTP service: verifies OTP (evidence: `backend/api/auth/recovery.py`)
- Recovery endpoints → Telegram delivery: sends code (evidence: `backend/api/auth/recovery.py`)
- Recovery endpoints → Account and tokens: updates password (evidence: `backend/api/auth/recovery.py`)
- Account and tokens → User queries: queries users (evidence: `backend/services/auth/token_service.py`)
- Account and tokens → Password and JWT: hashes and signs (evidence: `backend/services/auth/token_service.py`)
- User queries → User records: reads and writes (evidence: `backend/api/auth/crud.py`)
- User records → SQL database: maps records (evidence: `backend/models/user.py`)
- OTP service → Redis OTP store: stores OTP (evidence: `backend/services/auth/otp_service.py`)
- Telegram delivery → Redis OTP store: reads chat ID (evidence: `backend/services/auth/telegram.py`)
- Bot webhook → Telegram delivery: records chat ID (evidence: `backend/api/telegram/webhook.py`)
- Telegram delivery → Telegram Bot API: sends messages (evidence: `backend/services/auth/telegram.py`)
- Handwriting editor → Rich text input: renders (evidence: `frontend/src/pages/EditorPage.tsx`)
- Handwriting editor → Canvas renderer: renders (evidence: `frontend/src/pages/EditorPage.tsx`)
- Handwriting editor → Editor state: uses state
- User → Generation API: starts generation
- Generation API → Generation worker: queues job
- Generation API → Canvas result: streams progress and result
- Canvas result → Canvas renderer: renders words
- Canvas result → Image storage: references images
- User → Saved documents: lists documents
- Saved documents → Canvas result: returns saved schema
