# styletranslator/style-translator architecture

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

- Interactive diagram: https://gitdiagram.com/styletranslator/style-translator
- Repository: https://github.com/styletranslator/style-translator

## Overview

Style Translator is a React/FastAPI service that translates user text into a selected language and tone. The main workflow loads available styles, accepts text and translation options, routes short or long requests, and displays the result. Short translations produce multiple candidates and may use a Redis cache; long translations are chunked and can use a glossary for consistency. The README also documents Gemini as the translation engine and optional Redis-backed caching and rate limiting. Connections reflect shown calls or README statements; unsampled implementation details are not inferred.

Main entry points: [`frontend/src/App.jsx`](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/App.jsx) (App state), [`backend/services/translate.py`](https://github.com/styletranslator/style-translator/blob/develop/backend/services/translate.py) (Translation service), [`backend/api/routes.py`](https://github.com/styletranslator/style-translator/blob/develop/backend/api/routes.py) (API routes), [`backend/clients/redis_client.py`](https://github.com/styletranslator/style-translator/blob/develop/backend/clients/redis_client.py) (Redis client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Translation interface"]
  node_app["App state<br/>[App.jsx]"]
  node_translate_hook["Translation hook<br/>[useTranslate.js]"]
  node_api_client["API client<br/>[client.js]"]
  node_style_carousel["Style carousel<br/>[StyleCarousel.jsx]"]
  node_input_panel["Text input<br/>[InputPanel.jsx]"]
  node_language_toggle["Language selector<br/>[LangToggle.jsx]"]
  node_result_panel["Result display<br/>[ResultPanel.jsx]"]
  node_candidate_row["Candidate row<br/>[CandidateRow.jsx]"]
  node_pill["Style pill<br/>[Pill.jsx]"]
  node_badge["Status badge<br/>[Badge.jsx]"]
end

subgraph group_api["HTTP API"]
  node_api_server["FastAPI app<br/>[main.py]"]
  node_routes["API routes<br/>[routes.py]"]
  node_request_schemas["Request schemas<br/>[schemas.py]"]
  node_error_handling["Error handling<br/>[error_handlers.py]"]
  node_domain_errors["Domain errors<br/>[exceptions.py]"]
end

subgraph group_translation["Translation workflow"]
  node_translate_service["Translation service<br/>[translate.py]"]
  node_style_prompts["Style prompts<br/>[styles.py]"]
  node_chunking["Text chunking<br/>[chunking.py]"]
end

subgraph group_infrastructure["Integrations and state"]
  node_gemini_client["Gemini client<br/>[gemini.py]"]
  node_gemini_api{{"Google Gemini"}}
  node_translation_cache["Translation cache<br/>[cache.py]"]
  node_rate_limiter["Rate limiter<br/>[rate_limiter.py]"]
  node_redis_client["Redis client<br/>[redis_client.py]"]
  node_redis_store[("Redis")]
  node_config["Runtime config<br/>[config.py]"]
end

node_user(("User"))

node_user -->|"enters text"| node_app
node_app -->|"renders"| node_style_carousel
node_app -->|"renders"| node_input_panel
node_app -->|"renders"| node_language_toggle
node_app -->|"renders"| node_result_panel
node_app -->|"renders"| node_pill
node_app -->|"uses"| node_translate_hook
node_app -->|"loads styles"| node_api_client
node_result_panel -->|"renders"| node_candidate_row
node_input_panel -->|"renders"| node_badge
node_result_panel -->|"renders"| node_pill
node_translate_hook -->|"requests translation"| node_api_client
node_api_client -->|"HTTP requests"| node_routes
node_api_server -->|"registers routes"| node_routes
node_api_server -->|"registers handlers"| node_error_handling
node_api_server -->|"closes on shutdown"| node_redis_client
node_routes -->|"validates and responds"| node_request_schemas
node_routes -->|"checks requests"| node_rate_limiter
node_routes -->|"dispatches translation"| node_translate_service
node_routes -->|"raises limit error"| node_domain_errors
node_error_handling -->|"converts errors"| node_domain_errors
node_translate_service -->|"reads and writes"| node_translation_cache
node_translate_service -->|"generates translations"| node_gemini_client
node_translate_service -->|"splits long text"| node_chunking
node_translate_service -->|"uses style definitions"| node_style_prompts
node_translate_service -->|"validates glossary"| node_request_schemas
node_gemini_client -->|"calls model"| node_gemini_api
node_translation_cache -->|"uses shared client"| node_redis_client
node_rate_limiter -->|"uses shared client"| node_redis_client
node_redis_client -.->|"connects"| node_redis_store
node_translation_cache -->|"reads settings"| node_config
node_redis_client -->|"reads settings"| node_config
node_rate_limiter -->|"reads settings"| node_config
node_gemini_client -->|"reads settings"| node_config
node_api_server -->|"configures CORS"| node_config

click node_app "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/App.jsx"
click node_translate_hook "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/hooks/useTranslate.js"
click node_api_client "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/api/client.js"
click node_style_carousel "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/StyleCarousel/StyleCarousel.jsx"
click node_input_panel "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/InputPanel/InputPanel.jsx"
click node_language_toggle "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/LangToggle/LangToggle.jsx"
click node_result_panel "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/ResultPanel/ResultPanel.jsx"
click node_candidate_row "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/CandidateRow/CandidateRow.jsx"
click node_pill "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/Pill/Pill.jsx"
click node_badge "https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/Badge/Badge.jsx"
click node_api_server "https://github.com/styletranslator/style-translator/blob/develop/backend/main.py"
click node_routes "https://github.com/styletranslator/style-translator/blob/develop/backend/api/routes.py"
click node_request_schemas "https://github.com/styletranslator/style-translator/blob/develop/backend/models/schemas.py"
click node_error_handling "https://github.com/styletranslator/style-translator/blob/develop/backend/core/error_handlers.py"
click node_translate_service "https://github.com/styletranslator/style-translator/blob/develop/backend/services/translate.py"
click node_style_prompts "https://github.com/styletranslator/style-translator/blob/develop/backend/styles.py"
click node_chunking "https://github.com/styletranslator/style-translator/blob/develop/backend/services/chunking.py"
click node_gemini_client "https://github.com/styletranslator/style-translator/blob/develop/backend/clients/gemini.py"
click node_translation_cache "https://github.com/styletranslator/style-translator/blob/develop/backend/clients/cache.py"
click node_rate_limiter "https://github.com/styletranslator/style-translator/blob/develop/backend/clients/rate_limiter.py"
click node_redis_client "https://github.com/styletranslator/style-translator/blob/develop/backend/clients/redis_client.py"
click node_config "https://github.com/styletranslator/style-translator/blob/develop/backend/core/config.py"
click node_domain_errors "https://github.com/styletranslator/style-translator/blob/develop/backend/core/exceptions.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_translate_hook,node_api_client,node_style_carousel,node_input_panel,node_language_toggle,node_result_panel,node_candidate_row,node_pill,node_badge,node_user toneBlue
class node_api_server,node_routes,node_request_schemas,node_error_handling,node_domain_errors toneAmber
class node_translate_service,node_style_prompts,node_chunking toneMint
class node_gemini_client,node_gemini_api,node_translation_cache,node_rate_limiter,node_redis_client,node_redis_store,node_config toneRose
```

## Components

### Translation interface

- [App state](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Translation hook](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/hooks/useTranslate.js): `frontend/src/hooks/useTranslate.js`
- [API client](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Style carousel](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/StyleCarousel/StyleCarousel.jsx): `frontend/src/components/StyleCarousel/StyleCarousel.jsx`
- [Text input](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/InputPanel/InputPanel.jsx): `frontend/src/components/InputPanel/InputPanel.jsx`
- [Language selector](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/LangToggle/LangToggle.jsx): `frontend/src/components/LangToggle/LangToggle.jsx`
- [Result display](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/ResultPanel/ResultPanel.jsx): `frontend/src/components/ResultPanel/ResultPanel.jsx`
- [Candidate row](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/CandidateRow/CandidateRow.jsx): `frontend/src/components/CandidateRow/CandidateRow.jsx`
- [Style pill](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/Pill/Pill.jsx): `frontend/src/components/Pill/Pill.jsx`
- [Status badge](https://github.com/styletranslator/style-translator/blob/develop/frontend/src/components/Badge/Badge.jsx): `frontend/src/components/Badge/Badge.jsx`

### HTTP API

- [FastAPI app](https://github.com/styletranslator/style-translator/blob/develop/backend/main.py): `backend/main.py`
- [API routes](https://github.com/styletranslator/style-translator/blob/develop/backend/api/routes.py): `backend/api/routes.py`
- [Request schemas](https://github.com/styletranslator/style-translator/blob/develop/backend/models/schemas.py): `backend/models/schemas.py`
- [Error handling](https://github.com/styletranslator/style-translator/blob/develop/backend/core/error_handlers.py): `backend/core/error_handlers.py`
- [Domain errors](https://github.com/styletranslator/style-translator/blob/develop/backend/core/exceptions.py): `backend/core/exceptions.py`

### Translation workflow

- [Translation service](https://github.com/styletranslator/style-translator/blob/develop/backend/services/translate.py): `backend/services/translate.py`
- [Style prompts](https://github.com/styletranslator/style-translator/blob/develop/backend/styles.py): `backend/styles.py`
- [Text chunking](https://github.com/styletranslator/style-translator/blob/develop/backend/services/chunking.py): `backend/services/chunking.py`

### Integrations and state

- [Gemini client](https://github.com/styletranslator/style-translator/blob/develop/backend/clients/gemini.py): `backend/clients/gemini.py`
- **Google Gemini**
- [Translation cache](https://github.com/styletranslator/style-translator/blob/develop/backend/clients/cache.py): `backend/clients/cache.py`
- [Rate limiter](https://github.com/styletranslator/style-translator/blob/develop/backend/clients/rate_limiter.py): `backend/clients/rate_limiter.py`
- [Redis client](https://github.com/styletranslator/style-translator/blob/develop/backend/clients/redis_client.py): `backend/clients/redis_client.py`
- **Redis**
- [Runtime config](https://github.com/styletranslator/style-translator/blob/develop/backend/core/config.py): `backend/core/config.py`

### Other components

- **User**

## Connections

- User → App state: enters text (evidence: `frontend/src/App.jsx`)
- App state → Style carousel: renders (evidence: `frontend/src/App.jsx`)
- App state → Text input: renders (evidence: `frontend/src/App.jsx`)
- App state → Language selector: renders (evidence: `frontend/src/App.jsx`)
- App state → Result display: renders (evidence: `frontend/src/App.jsx`)
- App state → Style pill: renders (evidence: `frontend/src/App.jsx`)
- App state → Translation hook: uses (evidence: `frontend/src/App.jsx`)
- App state → API client: loads styles (evidence: `frontend/src/App.jsx`)
- Result display → Candidate row: renders (evidence: `frontend/src/components/ResultPanel/ResultPanel.jsx`)
- Text input → Status badge: renders (evidence: `frontend/src/components/InputPanel/InputPanel.jsx`)
- Result display → Style pill: renders (evidence: `frontend/src/components/ResultPanel/ResultPanel.jsx`)
- Translation hook → API client: requests translation (evidence: `frontend/src/hooks/useTranslate.js`)
- API client → API routes: HTTP requests (evidence: `frontend/src/api/client.js`)
- FastAPI app → API routes: registers routes (evidence: `backend/main.py`)
- FastAPI app → Error handling: registers handlers (evidence: `backend/main.py`)
- FastAPI app → Redis client: closes on shutdown (evidence: `backend/main.py`)
- API routes → Request schemas: validates and responds (evidence: `backend/api/routes.py`)
- API routes → Rate limiter: checks requests (evidence: `backend/api/routes.py`)
- API routes → Translation service: dispatches translation (evidence: `backend/api/routes.py`)
- API routes → Domain errors: raises limit error (evidence: `backend/api/routes.py`)
- Error handling → Domain errors: converts errors (evidence: `backend/core/error_handlers.py`)
- Translation service → Translation cache: reads and writes (evidence: `backend/services/translate.py`)
- Translation service → Gemini client: generates translations (evidence: `backend/services/translate.py`)
- Translation service → Text chunking: splits long text (evidence: `backend/services/translate.py`)
- Translation service → Style prompts: uses style definitions (evidence: `backend/services/translate.py`)
- Translation service → Request schemas: validates glossary (evidence: `backend/services/translate.py`)
- Gemini client → Google Gemini: calls model (evidence: `README.md`)
- Translation cache → Redis client: uses shared client (evidence: `backend/clients/cache.py`)
- Rate limiter → Redis client: uses shared client (evidence: `backend/clients/rate_limiter.py`)
- Redis client → Redis: connects (evidence: `backend/clients/redis_client.py`)
- Translation cache → Runtime config: reads settings (evidence: `backend/clients/cache.py`)
- Redis client → Runtime config: reads settings (evidence: `backend/clients/redis_client.py`)
- Rate limiter → Runtime config: reads settings (evidence: `backend/clients/rate_limiter.py`)
- Gemini client → Runtime config: reads settings (evidence: `backend/clients/gemini.py`)
- FastAPI app → Runtime config: configures CORS (evidence: `backend/main.py`)
