# bastienbyra/doccli architecture

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

- Interactive diagram: https://gitdiagram.com/bastienbyra/doccli
- Repository: https://github.com/bastienbyra/doccli

## Overview

##### Project type and purpose
- DocCLI is a Python-based command-line interface (CLI) tool for reading documents hosted locally (OS filesystem) or remotely (e.g., Git repositories).
- It supports three operating modes:
- client-server (both a CLI client and an HTTP server in one process)
- client (CLI issues HTTP requests to a remote DocCLI server)
- server (HTTP server that retrieves files locally or from Git)

##### File structure
- Top level:
- scripts/ – install scripts for Unix and Windows
- Makefile, CI workflows, linting, versioning, `.gitignore`, `LICENSE`
- doccli/ – the entire Python application
- Inside doccli/doccli/:
- entrypoints/ – CLI and server entrypoints
- commands/ – command implementations (e.g., `search`)
- services/ – core application logic (file_service, git_service)
- services/file_readers/ – adapters for each document type (`pdf`, `word`, `excel`, default text)
- configs/ – configuration abstractions per source (OS, Git, base)
- models/ – data models for directory contents, file contents, search results
- validators/ – input validation logic
- helpers/ and enums/ – utilities and enumerations
- Configuration: environment variables (`DOCCLI_MODE`, `DOCCLI_SOURCE`, etc.) control behavior
- Build/deps: `pyproject.toml`, mypy, lockfiles

##### Key insights from README
- Primary feature is the `search` command (view file or directory contents in a terminal UI)
- Pluggable “storage backends” (OS vs Git now, future S3/SharePoint/OneDrive)
- Three operating modes: CLI-only, server-only, and hybrid
- No database—files are read directly or via `git clone`

##### Detail
- Environment‐variable configuration branching

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        User["User"]:::external
        Main["main.py"]:::presentation
        ClientEP["client.py"]:::presentation
        ServerEP["server.py"]:::presentation
        HybridEP["clientserver.py"]:::presentation
        CLICommands["CLI Commands"]:::presentation
        SearchCmd["search.py"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Dispatcher["Command Dispatcher"]:::application
        ConfigManager["config.py"]:::application
        BaseConfig["base_config.py"]:::application
        GitConfig["git_config.py"]:::application
        OSConfig["os_config.py"]:::application
        BaseValidator["base_validator.py"]:::application
        SearchValidator["search_validator.py"]:::application
    end

    %% Domain/Service Layer
    subgraph "Domain/Service Layer"
        direction TB
        FileService["file_service.py"]:::domain
        GitService["git_service.py"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        DefaultReader["default_file_reader.py"]:::infrastructure
        PDFReader["pdf_file_reader.py"]:::infrastructure
        WordReader["word_file_reader.py"]:::infrastructure
        ExcelReader["excel_file_reader.py"]:::infrastructure
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        LocalFS["OS Filesystem"]:::external
        GitRemote["Git Remote Repo"]:::external
        HTTP["HTTP Transport"]:::external
    end

    %% Relationships
    User -->|"invoke CLI"| Main
    Main --> ClientEP
    Main --> ServerEP
    Main --> HybridEP

    ClientEP -->|"dispatch command"| Dispatcher
    ServerEP -->|"dispatch command"| Dispatcher
    HybridEP -->|"dispatch command / HTTP"| Dispatcher

    Dispatcher -->|"load config"| ConfigManager
    ConfigManager --> BaseConfig
    ConfigManager --> GitConfig
    ConfigManager --> OSConfig

    Dispatcher -->|"validate input"| BaseValidator
    BaseValidator --> SearchValidator

    Dispatcher -->|"execute search"| SearchCmd
    SearchCmd -->|"invoke service"| FileService
    SearchValidator --> FileService

    FileService -->|"choose Git adapter"| GitService
    GitService -->|"clone/checkout"| LocalFS
    FileService -->|"choose FS reader"| DefaultReader
    FileService --> PDFReader
    FileService --> WordReader
    FileService --> ExcelReader

    DefaultReader --> LocalFS
    PDFReader --> LocalFS
    WordReader --> LocalFS
    ExcelReader --> LocalFS

    %% Client-Server HTTP flow
    HybridEP -.->|HTTP request| HTTP
    HTTP -.-> ServerEP

    ServerEP --> Dispatcher

    %% Click Events
    click Main "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/main.py"
    click ClientEP "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/entrypoints/client.py"
    click ServerEP "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/entrypoints/server.py"
    click HybridEP "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/entrypoints/clientserver.py"
    click CLICommands "https://github.com/bastienbyra/doccli/tree/main/doccli/doccli/commands/CLI/"
    click SearchCmd "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/commands/CLI/search.py"
    click ConfigManager "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/config.py"
    click BaseConfig "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/configs/base_config.py"
    click GitConfig "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/configs/git_config.py"
    click OSConfig "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/configs/os_config.py"
    click BaseValidator "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/validators/base_validator.py"
    click SearchValidator "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/validators/search_validator.py"
    click FileService "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/file_service.py"
    click GitService "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/git_service.py"
    click DefaultReader "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/file_readers/default_file_reader.py"
    click PDFReader "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/file_readers/pdf_file_reader.py"
    click WordReader "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/file_readers/word_file_reader.py"
    click ExcelReader "https://github.com/bastienbyra/doccli/blob/main/doccli/doccli/services/file_readers/excel_file_reader.py"

    %% Styles
    classDef presentation fill:#D0E6FF,stroke:#0284C7,stroke-width:1px
    classDef application fill:#DFFFD0,stroke:#4CAF50,stroke-width:1px
    classDef domain fill:#FFE6B3,stroke:#FF9800,stroke-width:1px
    classDef infrastructure fill:#E0E0E0,stroke:#9E9E9E,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray: 2 2
```
