# doriandarko/gemini-writer architecture

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

- Interactive diagram: https://gitdiagram.com/doriandarko/gemini-writer
- Repository: https://github.com/doriandarko/gemini-writer

## Overview

Gemini Writing Agent turns a CLI prompt into a multi-file writing project: Gemini plans and generates content, tool calls create a project and write Markdown artifacts, and the agent streams progress while tracking tokens and iterations. Context compression and recovery preserve long-running work. The README documents streaming, thinking, and recovery behavior; the sampled excerpts omit parts of the main loop, so only clearly supported control and data transfers are shown.

Main entry points: [`writer.py`](https://github.com/doriandarko/gemini-writer/blob/main/writer.py) (CLI Agent), [`tools/compression.py`](https://github.com/doriandarko/gemini-writer/blob/main/tools/compression.py) (Context Compressor), [`tools/writer.py`](https://github.com/doriandarko/gemini-writer/blob/main/tools/writer.py) (Markdown Writer), [`tools/project.py`](https://github.com/doriandarko/gemini-writer/blob/main/tools/project.py) (Project Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent Runtime"]
  node_cli["CLI Agent<br/>[writer.py]"]
  node_runtime_utils["Agent Utilities<br/>[utils.py]"]
end

subgraph group_writing["Writing Tools"]
  node_file_tool["Markdown Writer<br/>[writer.py]"]
end

subgraph group_context["Context Management"]
  node_compression["Context Compressor<br/>[compression.py]"]
  node_context_summaries["Context Summaries"]
end

subgraph group_storage["Project Storage"]
  node_project_tool["Project Manager<br/>[project.py]"]
  node_active_project["Active Project<br/>[project.py]"]
  node_project_files["Project Files"]
end

node_user(("Writer"))
node_gemini["Gemini API"]

node_user -->|"provides prompt"| node_cli
node_user -.->|"provides recovery path"| node_cli
node_cli -->|"gets tools"| node_runtime_utils
node_runtime_utils -->|"returns tool map"| node_cli
node_cli -->|"sends prompt and tools"| node_gemini
node_gemini -->|"returns responses and calls"| node_cli
node_cli -->|"counts tokens"| node_gemini
node_cli -->|"dispatches project calls"| node_project_tool
node_cli -->|"dispatches writing calls"| node_file_tool
node_cli -->|"dispatches compression"| node_compression
node_project_tool -->|"sets active folder"| node_active_project
node_project_tool -->|"creates project folder"| node_project_files
node_file_tool -->|"reads active folder"| node_active_project
node_file_tool -->|"writes Markdown"| node_project_files
node_compression -->|"gets active folder"| node_active_project
node_compression -->|"requests summary"| node_gemini
node_compression -->|"saves summary"| node_context_summaries
node_cli -.->|"loads recovery context"| node_context_summaries

click node_cli "https://github.com/doriandarko/gemini-writer/blob/main/writer.py"
click node_runtime_utils "https://github.com/doriandarko/gemini-writer/blob/main/utils.py"
click node_project_tool "https://github.com/doriandarko/gemini-writer/blob/main/tools/project.py"
click node_file_tool "https://github.com/doriandarko/gemini-writer/blob/main/tools/writer.py"
click node_compression "https://github.com/doriandarko/gemini-writer/blob/main/tools/compression.py"
click node_active_project "https://github.com/doriandarko/gemini-writer/blob/main/tools/project.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_cli,node_runtime_utils toneBlue
class node_file_tool toneAmber
class node_compression,node_context_summaries,node_gemini toneMint
class node_project_tool,node_active_project,node_project_files toneRose
class node_user toneIndigo
```

## Components

### Agent Runtime

- [CLI Agent](https://github.com/doriandarko/gemini-writer/blob/main/writer.py): `writer.py`
- [Agent Utilities](https://github.com/doriandarko/gemini-writer/blob/main/utils.py): `utils.py`

### Writing Tools

- [Markdown Writer](https://github.com/doriandarko/gemini-writer/blob/main/tools/writer.py): `tools/writer.py`

### Context Management

- [Context Compressor](https://github.com/doriandarko/gemini-writer/blob/main/tools/compression.py): `tools/compression.py`
- **Context Summaries**

### Project Storage

- [Project Manager](https://github.com/doriandarko/gemini-writer/blob/main/tools/project.py): `tools/project.py`
- [Active Project](https://github.com/doriandarko/gemini-writer/blob/main/tools/project.py): `tools/project.py`
- **Project Files**

### Other components

- **Writer**
- **Gemini API**

## Connections

- Writer → CLI Agent: provides prompt
- Writer → CLI Agent: provides recovery path
- CLI Agent → Agent Utilities: gets tools
- Agent Utilities → CLI Agent: returns tool map
- CLI Agent → Gemini API: sends prompt and tools
- Gemini API → CLI Agent: returns responses and calls
- CLI Agent → Gemini API: counts tokens
- CLI Agent → Project Manager: dispatches project calls
- CLI Agent → Markdown Writer: dispatches writing calls
- CLI Agent → Context Compressor: dispatches compression
- Project Manager → Active Project: sets active folder
- Project Manager → Project Files: creates project folder
- Markdown Writer → Active Project: reads active folder
- Markdown Writer → Project Files: writes Markdown
- Context Compressor → Active Project: gets active folder
- Context Compressor → Gemini API: requests summary
- Context Compressor → Context Summaries: saves summary
- CLI Agent → Context Summaries: loads recovery context
