# dasdron15/cobalt architecture

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

- Interactive diagram: https://gitdiagram.com/dasdron15/cobalt
- Repository: https://github.com/dasdron15/cobalt

## Overview

##### Project Type and Purpose
- Type: Native, terminal-based code editor
- Purpose: Provide minimal text-editing features with an ncurses-powered UI

##### File Structure
src/
- config.h        – configuration constants & defaults
- main.c          – application entry point
- editor.c/.h     – core text‐buffer, cursor movement, editing operations
ui/
- status_bar.c/.h – rendering of status line (filename, mode)
utils/
- common.c/.h    – shared helper routines (string ops, error handling)
- fileio.c/.h    – file open/save, buffer serialization

##### Extract Insights from the README
- Depends on ncurses for terminal UI
- Built via Makefile – single binary (`cobalt`)
- No external services – purely local

##### Main Components
A. Entry Point
– main.c: initializes components in sequence
B. Configuration Manager
– config.h: holds default key-bindings, display settings
C. File I/O Module
– utils/fileio.c: open, read, write files into/from the in-memory buffer
D. Core Editor Module
– editor.c: data structures for the text buffer, cursor, undo stack
E. UI Layer
– ui/status_bar.c: draws the status bar
– ncurses library: handles low-level terminal drawing & input
F. Utility Module
– utils/common.c: error reporting, helper functions

##### Relationships & Data Flows
1. main → Configuration Manager: load or set defaults
2. main → File I/O: load file into Editor buffer
3. main → UI Layer (via ncurses init)
4. UI Layer ↔ Core Editor:
- UI captures keystrokes → passes to Core Editor
- Core Editor updates buffer state → signals UI to re-render
5. Core Editor → File I/O: save buffer to disk on command
6. Utility Module is called by any other module for helpers, logging, error messages

##### Architectural Patterns & Principles
- Layered design:
– Top layer: main orchestrator
– Middle layer: Core Editor & UI
– Bottom layer: Utils & File I/O
- Separation of concerns: editing logic separated from rendering and from file system access
- Single binary, no networking

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Entry Layer"
        main["main.c"]:::core
        config["Configuration Manager\n(config.h)"]:::util
    end

    subgraph "Core & UI Layer"
        editor["Core Editor\n(editor.c)"]:::core
        ui["UI Layer\n(status_bar.c)"]:::core
        ncurses["ncurses\n(external)"]:::external
    end

    subgraph "Infrastructure Layer"
        fileIO["File I/O\n(fileio.c)"]:::util
        common["Utilities\n(common.c)"]:::util
    end

    fileSystem[(File System)]:::storage

    main -->|"load defaults"| config
    main -->|"load file"| fileIO
    main -->|"init UI"| ui

    ui -->|"init ncurses"| ncurses
    ui -->|"handle input"| editor
    editor -->|"render"| ui
    editor -->|"save file"| fileIO

    fileIO -->|"read/write"| fileSystem

    main -->|uses| common
    ui -->|uses| common
    editor -->|uses| common
    fileIO -->|uses| common

    click main "https://github.com/dasdron15/cobalt/blob/main/src/main.c"
    click config "https://github.com/dasdron15/cobalt/blob/main/src/config.h"
    click fileIO "https://github.com/dasdron15/cobalt/blob/main/src/utils/fileio.c"
    click editor "https://github.com/dasdron15/cobalt/blob/main/src/editor.c"
    click ui "https://github.com/dasdron15/cobalt/blob/main/src/ui/status_bar.c"
    click common "https://github.com/dasdron15/cobalt/blob/main/src/utils/common.c"

    classDef core fill:#add8e6,stroke:#333,stroke-width:1px
    classDef util fill:#90ee90,stroke:#333,stroke-width:1px
    classDef external fill:#ffa500,stroke:#333,stroke-width:1px
    classDef storage fill:#d3d3d3,stroke:#333,stroke-width:1px
```
