# Monorepo End State - Visual Summary

## BEFORE: Everything in kollabor/ (38,000 lines)

```
kollabor-cli/
├── kollabor/                          38,000 lines - ALL THE CODE
│   ├── llm/                          15,000 lines
│   │   ├── profile_manager.py        1149 lines
│   │   ├── agent_manager.py          1367 lines
│   │   ├── conversation_manager.py   1016 lines
│   │   ├── conversation_logger.py     972 lines
│   │   ├── llm_service.py            1070 lines
│   │   ├── api_communication_service  670 lines
│   │   ├── queue_processor.py         634 lines
│   │   ├── background_task_manager    498 lines
│   │   └── ... (20+ more files)
│   │
│   ├── io/                            8,000 lines
│   │   ├── terminal_renderer.py
│   │   ├── input_handler.py
│   │   ├── message_renderer.py
│   │   ├── message_coordinator.py
│   │   ├── layout.py
│   │   ├── buffer_manager.py
│   │   ├── input/                     (10+ files)
│   │   └── status/                    (15+ files)
│   │
│   ├── ui/                            5,000 lines
│   │   ├── modal_renderer.py
│   │   ├── modal_state_manager.py
│   │   ├── config_widgets.py
│   │   ├── widgets/                   (already in kollabor-tui)
│   │   └── ...
│   │
│   ├── commands/                      3,846 lines
│   │   ├── profile_command.py         984 lines
│   │   ├── mcp_command.py             947 lines
│   │   ├── menu_renderer.py           735 lines
│   │   └── ...
│   │
│   ├── fullscreen/                    2,000 lines
│   ├── config/                        1,500 lines
│   ├── plugins/                       1,000 lines
│   ├── effects/                         500 lines
│   ├── utils/                           500 lines
│   ├── models/                          100 lines
│   └── ...
│
└── packages/
    ├── kollabor-events/               1,000 lines
    ├── kollabor-agent/                3,000 lines
    ├── kollabor-ai/                   5,000 lines
    └── kollabor-tui/                  5,000 lines
```

## AFTER: Clean Package Separation

```
kollabor-cli/
├── kollabor/                          10,000 lines - ORCHESTRATION ONLY
│   ├── application.py                 Main app orchestrator
│   ├── cli.py                         Entry point
│   │
│   ├── llm/                           3,000 lines - THIN WRAPPERS
│   │   ├── llm_service.py             Orchestrates kollabor_ai
│   │   ├── api_communication_service  Delegates to kollabor_ai
│   │   ├── queue_processor.py         Delegates to kollabor_ai
│   │   └── ... (thin 5-50 line wrappers)
│   │
│   ├── commands/                      1,500 lines - THIN HANDLERS
│   │   ├── profile_command.py         100 lines (delegates to kollabor_ai)
│   │   ├── mcp_command.py             100 lines (delegates to kollabor_agent)
│   │   ├── registry.py                Command registration
│   │   └── ... (thin 50-100 line handlers)
│   │
│   ├── config/                        1,500 lines (optional package)
│   ├── plugins/                       1,000 lines (optional package)
│   ├── fullscreen/                    2,000 lines (optional package)
│   └── utils/                           500 lines (app-specific)
│
└── packages/
    ├── kollabor-events/               3,000 lines (was 1,000)
    │   ├── event_bus.py
    │   ├── hooks.py
    │   ├── data_models.py             ← resume models moved here
    │   ├── models.py
    │   └── utils/                     ← dict_utils, error_utils
    │
    ├── kollabor-agent/                8,000 lines (was 3,000)
    │   ├── mcp_manager.py             ← NEW: from mcp_command.py
    │   ├── agent_manager.py           ← NEW: from llm/
    │   ├── native_tools_handler.py    ← NEW: from llm/
    │   ├── tool_executor.py           (already there)
    │   ├── mcp_integration.py         (already there)
    │   └── shell_utils.py             ← NEW: from utils/
    │
    ├── kollabor-ai/                   12,000 lines (was 5,000)
    │   ├── profile_manager.py         ← NEW: from llm/ + commands/
    │   ├── conversation_manager.py    ← NEW: from llm/
    │   ├── conversation_logger.py     ← NEW: from llm/
    │   ├── context_service.py         ← NEW: from llm/
    │   ├── model_router.py            ← NEW: from llm/
    │   ├── response_processor.py      ← NEW: from llm/
    │   ├── system_prompt_builder.py   ← NEW: from llm/
    │   ├── prompt_renderer.py         ← NEW: from utils/
    │   ├── session_naming.py          ← NEW: from utils/
    │   ├── providers/                 (already there)
    │   ├── adapters/                  (already there)
    │   └── response_parser.py         (already there)
    │
    └── kollabor-tui/                  25,000 lines (was 5,000)
        ├── terminal_renderer.py       ← NEW: from io/
        ├── input_handler.py           ← NEW: from io/
        ├── message_renderer.py        ← NEW: from io/
        ├── message_coordinator.py     ← NEW: from io/
        ├── layout.py                  ← NEW: from io/
        ├── buffer_manager.py          ← NEW: from io/
        ├── render_loop.py             ← NEW: from io/
        ├── command_menu.py            ← NEW: from commands/
        ├── modal_renderer.py          ← NEW: from ui/
        ├── modal_state_manager.py     ← NEW: from ui/
        ├── config_merger.py           ← NEW: from ui/
        ├── config_widgets.py          ← NEW: from ui/
        ├── input/                     ← NEW: from io/input/
        ├── status/                    ← NEW: from io/status/
        ├── effects/                   ← NEW: from effects/
        ├── widgets/                   (already there)
        ├── design_system/             (already there)
        ├── key_parser.py              (already there)
        ├── terminal_state.py          (already there)
        └── visual_effects.py          (already there)
```

## Package Responsibilities

### kollabor-events (3,000 lines)
**Purpose:** Event system + data models
**Can be used by:** Any Python project needing event-driven architecture
**Dependencies:** None (foundational)

### kollabor-agent (8,000 lines)
**Purpose:** Tool execution + MCP integration + Agent management
**Can be used by:** Any Python project needing MCP/tools/agents
**Dependencies:** kollabor-events

### kollabor-ai (12,000 lines)
**Purpose:** LLM functionality + Profile management + Conversations
**Can be used by:** Any Python project needing LLM integration
**Dependencies:** kollabor-events, kollabor-ai (providers)

### kollabor-tui (25,000 lines)
**Purpose:** Terminal UI + Rendering + Input handling
**Can be used by:** Any Python project needing terminal interfaces
**Dependencies:** kollabor-events, kollabor-tui (design system)

### kollabor (10,000 lines)
**Purpose:** Application orchestration only
**Dependencies:** All packages above
**Contains:**
- Main application class
- Thin wrappers delegating to packages
- Command handlers (50-100 lines each)
- App-specific config/plugins

## Dependency Graph

```
                    ┌─────────────────┐
                    │  kollabor-cli   │
                    │   (kollabor/)   │
                    │   10k lines     │
                    └────────┬────────┘
                             │
            ┌────────────────┼────────────────┐
            │                │                │
            ▼                ▼                ▼
    ┌───────────────┐ ┌──────────────┐ ┌──────────────┐
    │ kollabor-ai   │ │kollabor-agent│ │ kollabor-tui │
    │  12k lines    │ │  8k lines    │ │  25k lines   │
    └───────┬───────┘ └──────┬───────┘ └──────┬───────┘
            │                │                │
            └────────────────┼────────────────┘
                             │
                             ▼
                    ┌─────────────────┐
                    │ kollabor-events │
                    │   3k lines      │
                    └─────────────────┘
```

## Code Movement Summary

### Phase 7A: kollabor-ai expansion (+7,000 lines)
```
MOVE: llm/profile_manager.py          → kollabor_ai.profile_manager
MOVE: llm/conversation_manager.py     → kollabor_ai.conversation_manager
MOVE: llm/conversation_logger.py      → kollabor_ai.conversation_logger
MOVE: llm/context_service.py          → kollabor_ai.context_service
MOVE: llm/model_router.py             → kollabor_ai.model_router
MOVE: llm/response_processor.py       → kollabor_ai.response_processor
MOVE: llm/system_prompt_builder.py    → kollabor_ai.system_prompt_builder
MOVE: utils/prompt_renderer.py        → kollabor_ai.prompt_renderer
MOVE: utils/session_naming.py         → kollabor_ai.session_naming
EXTRACT: commands/profile_command.py  → kollabor_ai.profile_manager (wizard logic)
```

### Phase 7B: kollabor-agent expansion (+5,000 lines)
```
MOVE: llm/agent_manager.py            → kollabor_agent.agent_manager
MOVE: llm/native_tools_handler.py     → kollabor_agent.native_tools_handler
MOVE: utils/shell_alias_detector.py   → kollabor_agent.shell_utils
EXTRACT: commands/mcp_command.py      → kollabor_agent.mcp_manager (MCP logic)
```

### Phase 7C: kollabor-tui expansion (+20,000 lines)
```
MOVE: io/terminal_renderer.py         → kollabor_tui.terminal_renderer
MOVE: io/input_handler.py             → kollabor_tui.input_handler
MOVE: io/message_renderer.py          → kollabor_tui.message_renderer
MOVE: io/message_coordinator.py       → kollabor_tui.message_coordinator
MOVE: io/layout.py                    → kollabor_tui.layout
MOVE: io/buffer_manager.py            → kollabor_tui.buffer_manager
MOVE: io/event_driven_render_loop.py  → kollabor_tui.render_loop
MOVE: io/input/*                      → kollabor_tui.input.*
MOVE: io/status/*                     → kollabor_tui.status.*
MOVE: commands/menu_renderer.py       → kollabor_tui.command_menu
MOVE: ui/modal_renderer.py            → kollabor_tui.modal_renderer
MOVE: ui/modal_state_manager.py       → kollabor_tui.modal_state_manager
MOVE: ui/config_merger.py             → kollabor_tui.config_merger
MOVE: ui/config_widgets.py            → kollabor_tui.config_widgets
MOVE: effects/*                       → kollabor_tui.effects.*
```

### Phase 7D: kollabor-events expansion (+2,000 lines)
```
MOVE: models/resume.py                → kollabor_events.data_models
MOVE: utils/dict_utils.py             → kollabor_events.utils
MOVE: utils/error_utils.py            → kollabor_events.utils
```

## Success Metrics

### Code Organization
- [ ] kollabor/ reduced from 38,000 → 10,000 lines (74% reduction)
- [ ] All packages increased appropriately
- [ ] No business logic in kollabor/ directory
- [ ] All thin wrappers are <50 lines

### Package Independence
- [ ] kollabor-events installable standalone
- [ ] kollabor-agent installable standalone
- [ ] kollabor-ai installable standalone
- [ ] kollabor-tui installable standalone

### Import Clarity
- [ ] Zero imports from kollabor.* to packages (only kollabor_*)
- [ ] Zero circular dependencies
- [ ] Clear dependency graph (no cycles)

### Developer Experience
- [ ] New developers can understand package structure in <5 minutes
- [ ] Each package has clear README
- [ ] Each package has example usage
- [ ] Clear contribution guidelines

## What's Left in kollabor/ (10,000 lines)

### Application Orchestrator (1,500 lines)
- `application.py` - Main app class, coordinates all packages

### LLM Thin Wrappers (3,000 lines)
- `llm_service.py` - Orchestrates kollabor_ai calls
- `api_communication_service.py` - Delegates to kollabor_ai
- `queue_processor.py` - Delegates to kollabor_ai
- `background_task_manager.py` - Generic utility
- `streaming_handler.py` - Delegates to kollabor_ai
- `message_handler.py` - Delegates to kollabor_ai
- `session_manager.py` - Delegates to kollabor_ai
- `status_service.py` - Delegates to kollabor_ai
- `hook_system.py` - App-level hook integration
- `plugin_sdk.py` - Plugin SDK
- `permissions/` - Permission system (stays)

### Command Handlers (1,500 lines)
- `registry.py` - Command registration
- `executor.py` - Command execution
- `parser.py` - Command parsing
- `ui_commands.py` - UI command handlers
- `profile_command.py` - Thin wrapper (100 lines)
- `mcp_command.py` - Thin wrapper (100 lines)
- `system_commands/` - System command handlers

### Optional Packages (5,000 lines)
- `config/` - Could become kollabor-config
- `plugins/` - Could become kollabor-plugin-system
- `fullscreen/` - Could become kollabor-fullscreen
- `logging/` - Logging setup
- `updates/` - Version checking
- `utils/` - App-specific utilities

## Next Steps

1. **Review spec** - Confirm end state vision
2. **Prioritize phases** - Which to tackle first
3. **Create GitHub issues** - Track each phase
4. **Execute Phase 7A** - Start with kollabor-ai (biggest impact)
5. **Parallel execution** - Use GLM agents for each phase

## Open Questions for Team

1. **Config package?** Yes/No/Later
2. **Plugin system package?** Yes/No/Later
3. **Fullscreen package?** Yes/No/Later
4. **Test location?** Packages vs central
5. **Backward compat?** Keep shims or clean break
6. **Phase priority?** 7A first or 7C (I/O) first
