How saifurrahmanshochib/markdown-viewer works
1. Overall shape
- This is a self-hosted Next.js Markdown editor/viewer. The repository is dominated by a single interactive app rather than a multi-service backend.
- The core architecture is client-heavy: editing, previewing, tools, and export are handled in the browser, with Next.js mainly providing the app shell, bundling, and deployment.
2. Application shell
- app/layout.tsx, app/page.tsx, and app/globals.css define the root Next.js App Router shell.
- components/providers.tsx likely wires global client-side concerns such as theme, toast notifications, and other context providers.
- The app is styled with Tailwind CSS and uses a shared UI component system under components/ui/.
3. Primary user experience: the editor workspace
- The main functional boundary is components/editor/, which contains the full Markdown editing workspace.
- Key parts include the editor surface (markdown-editor.tsx, textarea-editor.tsx), preview panel (markdown-preview.tsx), and surrounding controls such as editor-toolbar.tsx, editor-status-bar.tsx, and editor-loader.tsx.
- This suggests a split-view / mode-switching editor where the document is edited on one side and rendered on the other.
4. Document flow: input → transform → preview
- User text enters the editor component, is processed through Markdown utilities in lib/markdown.ts, and then rendered in the preview component.
- Supporting transformations live in lib/html-to-markdown.ts and lib/emoji.ts, implying bidirectional content handling for pasted HTML and emoji normalization.
- The preview path likely includes enhanced Markdown features called out in the README: GFM, syntax highlighting, KaTeX math, and Mermaid rendering.
5. Draft persistence and local state
- Drafts are stored client-side through hooks/use-local-storage.ts, which aligns with the README’s localStorage-based draft behavior.
- components/editor/drafts-bar.tsx is the UI boundary for managing saved drafts, while hooks/use-debounce.ts likely reduces write frequency and expensive transforms while typing.
- This is an important architectural point: there is no central backend document store in the repo; persistence is local to the browser.
6. Editor tools and auxiliary analysis
- components/editor/tools-sidebar.tsx is the container for non-editing utilities such as outline, linting, stats, and tables.
- find-replace.tsx, editor-toolbar.tsx, and editor-status-bar.tsx provide editor operations and live document metadata.
- These tools consume the same document state as the editor and preview, but are visually and functionally separate subsystems.
7. Specialized content blocks
- components/editor/mermaid-block.tsx indicates explicit handling for Mermaid diagrams as a first-class Markdown extension.
- That implies the rendering pipeline has content-type-aware branches rather than treating the document as plain Markdown only.
- This is a notable diagram boundary: standard Markdown rendering versus embedded diagram blocks.
8. Export and output paths
- lib/export.ts provides the document output layer, supporting formats mentioned in the README such as Markdown, HTML, PDF, and print.
- Export likely depends on the current editor state and rendered HTML, making it a downstream consumer of the same document model used by the preview.
- This makes export a separate architectural branch from live editing, even though both originate from the same document content.
9. Shared UI and interaction infrastructure
- components/ui/ contains reusable primitives like dialog, button, tabs, toast, tooltip, input, switch, and scroll area.
- These are the building blocks used across editor controls, confirmations, settings, and transient messages.
- hooks/use-toast.ts plus components/ui/toaster.tsx provide the global notification path for user feedback.
10. Platform/runtime and delivery
- The project targets Node.js 18.17+ and uses Docker as a first-class packaging/deployment path (Dockerfile, docker-compose.yml).
- next.config.mjs, middleware.ts, tailwind.config.ts, postcss.config.mjs, and tsconfig.json show a standard Next.js + TypeScript frontend stack with build-time optimization and request-level middleware.
- Dockerfile is described as a multi-stage image using Next.js standalone output, which means the deployable artifact is a self-contained server bundle rather than a separate web server plus app.
Main entry points: markdown-editor.tsx Editor · ui UI Primitives · markdown-preview.tsx Preview · markdown.ts Markdown Core
Components 27
App Shell
Next.js entry points and global styling
- Layout · Root document shell and app-wide structure
app/layout.tsx - Home · Main app entry that mounts the editor experience
app/page.tsx - Global CSS · Global Tailwind and base styling
app/globals.css - Providers · Global client-side context wiring
components/providers.tsx
Editor Workspace
Primary Markdown editing surface and tools
- Editor · Main Markdown editing container
components/editor/markdown-editor.tsx - Textarea · Raw text editing implementation
components/editor/textarea-editor.tsx - Preview · Rendered Markdown preview panel
components/editor/markdown-preview.tsx - Toolbar · Formatting and document actions
components/editor/editor-toolbar.tsx - Status Bar · Live document state and counts
components/editor/editor-status-bar.tsx - Drafts · Saved draft selection and management
components/editor/drafts-bar.tsx - Tools · Outline, stats, lint, and other helper tools
components/editor/tools-sidebar.tsx - Find/Replace · Search and replacement interactions
components/editor/find-replace.tsx
Content Pipeline
Markdown transformation, preview, and export
- Mermaid Block · Specialized Mermaid diagram handling inside Markdown
components/editor/mermaid-block.tsx - Markdown Core · Markdown parsing and rendering helpers
lib/markdown.ts - HTML Import · Converts pasted or imported HTML into Markdown
lib/html-to-markdown.ts - Emoji · Emoji normalization and replacement
lib/emoji.ts - Export · Markdown, HTML, PDF, and print export flow
lib/export.ts
State & UI
Shared hooks and reusable UI primitives
- Local Storage · Browser persistence for drafts and settings
hooks/use-local-storage.ts - Debounce · Throttles typing and expensive updates
hooks/use-debounce.ts - Toast · Global notification API
hooks/use-toast.ts - UI Primitives · Reusable dialogs, tabs, inputs, buttons, and overlays
components/ui - Toaster · Renders queued toast messages
components/ui/toaster.tsx - Defaults · Shared editor default settings and initial state
lib/editor-defaults.ts
Runtime & Delivery
Build, middleware, and containerized deployment
- Next Config · Next.js build and runtime configuration
next.config.mjs - Middleware · Request-time application middleware
middleware.ts - Dockerfile · Multi-stage production image build
Dockerfile - Compose · Local container orchestration
docker-compose.yml
Connections 29
- Home → Editor: mounts · The home page mounts the editor workspace
- Layout → Providers: wraps · App layout applies global providers
- Layout → Global CSS: loads · Root layout loads global styling
- Providers → Toast: provides · Global notification infrastructure
- Providers → Toaster: renders · Provider tree includes the toast host
- Editor → Textarea: uses · Editor surface contains the text input mode
- Editor → Preview: pairs with · Editor surface drives rendered preview
- Editor → Toolbar: controls · Toolbar actions operate on the current document
- Editor → Status Bar: shows · Status bar reflects editor state
- Editor → Drafts: manages · Draft sidebar connects to editor state
- Editor → Tools: augments · Tools panel shares the active document
- Editor → Find/Replace: supports · Search and replace acts on editor content
- Editor → Defaults: initializes · Default editor configuration seeds the workspace
- Textarea → Debounce: debounces · Typing updates and derived work are throttled
- Drafts → Local Storage: persists · Draft storage is browser-local
- Preview → Markdown Core: renders via · Preview uses the Markdown rendering pipeline
- Preview → Mermaid Block: embeds · Preview handles Mermaid as a special block
- Markdown Core → HTML Import: ingests · Markdown pipeline accepts HTML conversion input
- Markdown Core → Emoji: normalizes · Markdown content passes through emoji handling
- Toolbar → UI Primitives: uses · Toolbar relies on shared UI components
- Tools → UI Primitives: uses · Sidebar utilities use the shared component kit
- Find/Replace → UI Primitives: uses · Search UI is built from shared primitives
- Status Bar → UI Primitives: uses · Status UI uses shared primitives
- Export → Markdown Core: exports from · Export flow consumes the document model and rendered content
- Export → Preview: derives from · Some export paths depend on rendered preview output
- UI Primitives → Toaster: supports · Shared UI underpins transient messaging and dialogs
- Next Config → Dockerfile: packages · Build configuration feeds the standalone deployment artifact
- Middleware → Home: intercepts · Request middleware sits in front of the app shell
- Compose → Dockerfile: orchestrates · Compose uses the container image for local deployment