Technology stack
The application uses the following core technologies:- React 19: Latest version of React for building the user interface
- Vite: Next-generation frontend build tool for fast development and optimized builds
- react-markdown: Renders markdown content to React components
- remark-gfm: Adds support for GitHub Flavored Markdown (tables, strikethrough, task lists)
- Mermaid: Renders diagrams and flowcharts from markdown code blocks
- lucide-react: Beautiful, consistent icon library
- ESLint: Code quality and consistency checks
Project structure
The source code is organized as follows:Component breakdown
App.jsx: Main application component that orchestrates the entire UI, manages state, and handles file operationsSidebar.jsx: Displays the list of open files and provides file management controlsToolbar.jsx: Contains the sidebar toggle, file title, and font size controlsMarkdownRenderer.jsx: Renders markdown content using react-markdown with custom componentsMermaid.jsx: Handles Mermaid diagram rendering with proper initialization
State management
MD Viewer uses React’s built-in state management:useState: For component-level state (sidebar open/closed, active file, font size, etc.)useCallback: For memoized event handlers to optimize performanceuseEffect: For side effects like loading and persisting data
Local storage persistence
The application persists user data in the browser’s local storage:Styling approach
MD Viewer uses a custom CSS approach with modern techniques:CSS custom properties
The entire color scheme and design system is defined using CSS custom properties insrc/index.css, making it easy to customize:
- Theme colors (background, surface, accent)
- Typography scale
- Spacing system
- Border radius values
Glassmorphism design
The UI uses glassmorphism effects to create a modern, macOS-like appearance:- Semi-transparent backgrounds with backdrop blur
- Subtle borders and shadows
- Smooth transitions and animations
System fonts
The application uses system fonts for a native feel:-apple-systemfor macOS- Fallbacks for other platforms
- Separate font stacks for UI and markdown content
Component architecture
Unidirectional data flow
Data flows from theApp component down to child components via props:
Event handlers
User interactions are handled through callback props that modify state in the parent component, ensuring a single source of truth.File handling
MD Viewer supports multiple ways to open files:- File upload: Click the upload button in the sidebar
- Drag and drop: Drag markdown files anywhere in the window
- Create new: Generate a new untitled document
Performance optimizations
- React 19: Benefits from automatic optimizations in the latest React version
- Memoized callbacks: Uses
useCallbackfor event handlers to prevent unnecessary re-renders - Vite: Extremely fast HMR during development and optimized production builds
- Auto-hiding toolbar: Hides on scroll down for a distraction-free reading experience
Build configuration
The Vite configuration (vite.config.js) is minimal and uses the official React plugin: