# averageandyyy/journal architecture

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

- Interactive diagram: https://gitdiagram.com/averageandyyy/journal
- Repository: https://github.com/averageandyyy/journal

## Overview

##### Project type and purpose
- This is a command-line journal application written in C.
- It lets a user write new entries, read existing ones, and update entries via flags (-w, ‑r, ‑u).
- Entries are stored under a file-system tree of the form: entries/<year>/<month>/<filename>.

##### File structure
- Top-level Makefile: build script.
- Source files:
- journal.c         – main CLI entry point, flag dispatch
- getinput.c/.h     – one module for raw line-based input
- getnstr.c/.h      – module for bounded-string input (n characters)
- subfiles.c/.h     – utilities for directory traversal and file enumeration
- output.c/.h       – routines for printing file contents to the terminal
- entries/…         – default data directory (created on demand)
- Other sample directories (folder/, new_folder/) and raw text files illustrate file-tree usage.

##### README insights
- Flags and behavior are clearly documented.
- Default directory is entries/.
- File path pattern: year/month/file.txt.

##### Detail
- Error-handling path if the directory doesn’t exist (subfiles creates it).
- Flags and their code paths distinctly.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entities
    User["User (Terminal)"]:::external
    Journal["CLI Parser\njournal.c"]:::cli
    GetInput["Input Module\ngetinput"]:::util
    GetNstr["Input Module\ngetnstr"]:::util
    Subfiles["FS Utilities\nsubfiles"]:::util
    Output["I/O Module\noutput"]:::util
    DataStore["Data Store\nentries/"]:::datastore
    Makefile["Build Script\nMakefile"]:::infra
    Readme["Project Documentation\nREADME.md"]:::infra

    %% Main Flow
    User -->|"invoke ./journal"| Journal

    %% Write Path (-w)
    Journal -->|"flag -w: get entry text"| GetInput
    Journal -->|"flag -w: get filename"| GetNstr
    GetInput -->|"prepare dir path"| Subfiles
    GetNstr -->|"prepare dir path"| Subfiles
    Subfiles -->|"mkdir year/month"| DataStore
    Subfiles -->|"write file"| DataStore

    %% Read Path (-r)
    Journal -->|"flag -r: locate entry"| Subfiles
    Subfiles -->|"read file contents"| Output
    Output -->|"stdout"| User

    %% Update Path (-u)
    Journal -->|"flag -u: locate entry"| Subfiles
    Subfiles -->|"read file contents"| Output
    Output -->|"display for edit"| User
    User -->|"input new text"| GetInput
    GetInput -->|"append/overwrite"| Subfiles
    Subfiles -->|"write file"| DataStore

    %% Click Events
    click Journal "https://github.com/averageandyyy/journal/blob/main/journal/journal.c"
    click GetInput "https://github.com/averageandyyy/journal/blob/main/getinput/getinput.c"
    click GetNstr "https://github.com/averageandyyy/journal/blob/main/getnstr/getnstr.c"
    click Subfiles "https://github.com/averageandyyy/journal/blob/main/subfiles/subfiles.c"
    click Output "https://github.com/averageandyyy/journal/blob/main/output/output.c"
    click DataStore "https://github.com/averageandyyy/journal/tree/main/entries/"
    click Makefile "https://github.com/averageandyyy/journal/tree/main/Makefile"
    click Readme "https://github.com/averageandyyy/journal/blob/main/README.md"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef util fill:#90EE90,stroke:#000,stroke-width:1px
    classDef datastore fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
```
