# lumen-notes/lumen architecture

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

- Interactive diagram: https://gitdiagram.com/lumen-notes/lumen
- Repository: https://github.com/lumen-notes/lumen

## Overview

##### Main Components

a) Frontend Layer:
- React-based Single Page Application (evident from the src/components structure)
- Key UI Components:
- Editor (note-editor.tsx)
- Navigation (nav-bar.tsx, sidebar.tsx)
- Search Interface (search-input.tsx)
- Authentication (github-auth.tsx)

b) Core Services Layer:
- Management System (src/hooks/note.ts)
- Search Engine (src/hooks/search.ts)
- Tag Management (src/hooks/tag.ts)
- File System Operations (src/utils/fs.ts)

c) Integration Layer:
- GitHub Integration:
- Authentication (netlify/edge-functions/github-auth.ts)
- Git Operations (src/utils/git.ts)
- LFS Support (src/utils/git-lfs.ts)

d) Data Processing Layer:
- Markdown Processing:
- Remark Plugins (src/remark-plugins/)
- Frontmatter Parsing (src/utils/parse-frontmatter.ts)
- CodeMirror Extensions (src/codemirror-extensions/)

##### Architecture Patterns to Highlight

- JAMstack Architecture (using Netlify for deployment)
- Edge Computing (Netlify Edge Functions)
- Component-Based Architecture (React)
- State Management (evident from global-state.ts)

**┌─ Client Layer ─────────────────────┐**
- React SPA                          │
- UI Components                    │
- CodeMirror Editor               │
- State Management                │
- Core Services Layer ──────────────┤
- Note Management                  │
- Search Engine                    │
- Tag System                       │
- Processing Layer ────────────────┤
- Markdown Processing             │
- Syntax Highlighting             │
- Template Engine                 │
- Integration Layer ───────────────┤
- GitHub API                      │
- Git Operations                  │
- File System                     │
- ┘

##### Important Flows to Illustrate

- User Authentication Flow:
- Client → GitHub Auth → GitHub API → Token Storage
- Creation/Edit Flow:
- Editor → Markdown Processing → Git Operations → GitHub Storage
- Search Flow:
- Search Input → Search Engine → Note Index → Results Display

##### Technical Stack Indicators

- React
- TypeScript
- CodeMirror
- Remark
- Netlify
- GitHub API

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef frontend fill:#3498db,color:white
    classDef core fill:#2ecc71,color:white
    classDef processing fill:#9b59b6,color:white
    classDef integration fill:#e67e22,color:white
    classDef external fill:#95a5a6,color:white

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        UI["React SPA"]
        Editor["Note Editor"]
        NavBar["Navigation Bar"]
        Sidebar["Sidebar"]
        Search["Search Interface"]
        AuthUI["Auth UI"]
        Template["Template Engine"]
    end

    %% Core Services Layer
    subgraph CoreLayer["Core Services Layer"]
        NoteManager["Note Management"]
        SearchEngine["Search Engine"]
        TagSystem["Tag System"]
        StateManager["State Management"]
        AttachFile["File Attachment Handler"]
    end

    %% Processing Layer
    subgraph ProcessingLayer["Processing Layer"]
        MarkdownProc["Markdown Processing"]
        CodeMirrorExt["CodeMirror Extensions"]
        FrontMatter["Frontmatter Parser"]
    end

    %% Integration Layer
    subgraph IntegrationLayer["Integration Layer"]
        GitOps["Git Operations"]
        GitLFS["Git LFS Handler"]
        FileSystem["File System"]
        GithubAuth["GitHub Auth"]
    end

    %% External Services
    GitHub["GitHub API"]:::external

    %% Relationships
    UI --> Editor
    UI --> NavBar
    UI --> Sidebar
    UI --> Search
    UI --> AuthUI
    UI --> Template

    Editor --> NoteManager
    Editor --> CodeMirrorExt
    Search --> SearchEngine
    Sidebar --> TagSystem
    
    NoteManager --> StateManager
    NoteManager --> MarkdownProc
    NoteManager --> GitOps
    
    SearchEngine --> FileSystem
    TagSystem --> FileSystem
    
    MarkdownProc --> FrontMatter
    
    GitOps --> GitHub
    GitLFS --> GitHub
    GithubAuth --> GitHub
    
    AttachFile --> GitLFS
    AttachFile --> FileSystem

    %% Click events
    click Editor "https://github.com/lumen-notes/lumen/blob/main/src/components/note-editor.tsx"
    click NavBar "https://github.com/lumen-notes/lumen/blob/main/src/components/nav-bar.tsx"
    click Sidebar "https://github.com/lumen-notes/lumen/blob/main/src/components/sidebar.tsx"
    click Search "https://github.com/lumen-notes/lumen/blob/main/src/components/search-input.tsx"
    click AuthUI "https://github.com/lumen-notes/lumen/blob/main/src/components/github-auth.tsx"
    click Template "https://github.com/lumen-notes/lumen/blob/main/src/components/insert-template.tsx"
    click NoteManager "https://github.com/lumen-notes/lumen/blob/main/src/hooks/note.ts"
    click SearchEngine "https://github.com/lumen-notes/lumen/blob/main/src/hooks/search.ts"
    click TagSystem "https://github.com/lumen-notes/lumen/blob/main/src/hooks/tag.ts"
    click StateManager "https://github.com/lumen-notes/lumen/blob/main/src/global-state.ts"
    click AttachFile "https://github.com/lumen-notes/lumen/blob/main/src/hooks/attach-file.ts"
    click MarkdownProc "https://github.com/lumen-notes/lumen/tree/main/src/remark-plugins/"
    click CodeMirrorExt "https://github.com/lumen-notes/lumen/tree/main/src/codemirror-extensions/"
    click FrontMatter "https://github.com/lumen-notes/lumen/blob/main/src/utils/parse-frontmatter.ts"
    click GitOps "https://github.com/lumen-notes/lumen/blob/main/src/utils/git.ts"
    click GitLFS "https://github.com/lumen-notes/lumen/blob/main/src/utils/git-lfs.ts"
    click FileSystem "https://github.com/lumen-notes/lumen/blob/main/src/utils/fs.ts"
    click GithubAuth "https://github.com/lumen-notes/lumen/blob/main/netlify/edge-functions/github-auth.ts"

    %% Style applications
    class UI,Editor,NavBar,Sidebar,Search,AuthUI,Template frontend
    class NoteManager,SearchEngine,TagSystem,StateManager,AttachFile core
    class MarkdownProc,CodeMirrorExt,FrontMatter processing
    class GitOps,GitLFS,FileSystem,GithubAuth integration
```
