Repository Root
Source Directory (src/)
The src/ directory contains all application code:
Components (src/components/)
Reusable UI components built with Astro:
Editor.astro
Editor.astro
The main editor component containing:
- CodeMirror editor pane
- Preview pane
- Resize handle between panes
- Loading overlay
- View mode management (editor/split/preview)
src/components/Editor.astroKey Features:- Responsive layout with mobile support
- Sticky pane headers
- Custom resize handle with hover effects
Header.astro
Header.astro
Top navigation bar with:
- Logo and site title
- View mode tabs (optional)
- Theme toggle
- Export button
src/components/Header.astroStatusBar.astro
StatusBar.astro
Bottom status bar displaying:
- Save status (idle/saving/saved)
- Markdown lint issues count
- Auto-fix button
src/components/StatusBar.astroViewTabs.astro
ViewTabs.astro
Toggle buttons for view modes:
- Editor only
- Split view (default)
- Preview only
src/components/ViewTabs.astroThemeToggle.astro
ThemeToggle.astro
Button to switch between light and dark themes.Location:
src/components/ThemeToggle.astroCodeBlock.astro
CodeBlock.astro
Syntax-highlighted code block component used in content pages.Location:
src/components/CodeBlock.astroCard.astro & Button.astro
Card.astro & Button.astro
Layouts (src/layouts/)
Page layout templates:
- Layout.astro
- ContentLayout.astro
Base layout for all pages.Location:
src/layouts/Layout.astroIncludes:- HTML document structure
- Meta tags (SEO, Open Graph, Twitter)
- Theme initialization script
- Global styles import
- Structured data (JSON-LD)
Pages (src/pages/)
File-based routing - each .astro file becomes a route:
| File | Route | Purpose |
|---|---|---|
index.astro | / | Landing page |
editor.astro | /editor | Main editor interface |
documents.astro | /documents | Document management page |
about.astro | /about | About page |
markdown-cheat-sheet.astro | /markdown-cheat-sheet | Markdown syntax guide |
katex-math-guide.astro | /katex-math-guide | KaTeX math reference |
mermaid-diagrams-guide.astro | /mermaid-diagrams-guide | Mermaid diagram examples |
404.astro | /404 | Error page |
robots.txt.ts | /robots.txt | SEO robots file |
llms.txt.ts | /llms.txt | AI/LLM documentation |
Scripts (src/scripts/)
Client-side TypeScript modules:
- Core Editor
- CodeMirror Setup
- Preview System
- Markdown Linting
- Other Scripts
editor.ts
Main editor initialization and orchestrationLocation:src/scripts/editor.tsResponsibilities:- Initialize CodeMirror editor
- Load/create documents from URL hash
- Set up auto-save (1 second debounce)
- Connect editor to preview
- Manage status bar state
- Handle theme changes
Libraries (src/lib/)
Shared utility code:
db.ts
IndexedDB wrapper for document storageExports:
getAllDocs(): Promise<Document[]>getDoc(id: string): Promise<Document | null>saveDoc(doc: Document): Promise<void>deleteDoc(id: string): Promise<void>
src/lib/db.tsmarkdown.ts
Markdown processing pipelineExports:
renderMarkdown(content: string): Promise<string>extractTitle(content: string): string
- Marked parser with extensions
- Shiki syntax highlighting
- Custom code block renderer
- Mermaid diagram support
src/lib/markdown.tsmarkdown-title.ts
Extract document title from markdownExtracts first heading (H1-H6) or falls back to “Untitled”Location:
src/lib/markdown-title.tsdefault-markdown.md
Default document content for new documentsImported as raw string:
import DEFAULT_MARKDOWN from "@/lib/default-markdown.md?raw"Location: src/lib/default-markdown.mdShiki Highlighter (src/lib/shiki/)
- highlight.ts
- transformers.ts
Syntax highlighting engineLocation:
src/lib/shiki/highlight.tsFeatures:- On-demand language loading
- 60+ supported languages
- Light and dark themes
- Language aliases (js → javascript, etc.)
Styles (src/styles/)
Global CSS organized by concern:
global.css
Main stylesheet importing all other CSS filesLocation:
src/styles/global.csstokens.css
CSS custom properties (design tokens):
- Colors (background, foreground, primary, etc.)
- Typography (font families, sizes)
- Spacing and sizing
- Border radius
src/styles/tokens.cssbase.css
Base element styles and resetsLocation:
src/styles/base.cssprose.css
Typography styles for markdown previewApplied via
.markdown-prose classLocation: src/styles/prose.csscode.css
Code block and syntax highlighting stylesLocation:
src/styles/code.cssutilities.css
Custom utility classesLocation:
src/styles/utilities.cssintegrations.css
Styles for third-party integrations (Mermaid, KaTeX)Location:
src/styles/integrations.cssAssets (src/assets/)
Static SVG icons and images:
Public Directory (public/)
Static files served as-is:
Configuration Files
- astro.config.mjs
- package.json
- tsconfig.json
- wrangler.toml
Astro framework configurationLocation:
astro.config.mjsKey Settings:Import Aliases
CodeInk uses the@/ alias for cleaner imports:
File Naming Conventions
Components
PascalCase with
.astro extensionExamples: Editor.astro, StatusBar.astroScripts
kebab-case with
.ts extensionExamples: editor.ts, markdown-linter.tsStyles
kebab-case with
.css extensionExamples: global.css, code.cssPages
kebab-case with
.astro extensionExamples: index.astro, markdown-cheat-sheet.astroKey File Relationships
Understanding how files connect:Finding Code
- By Feature
- By Type
- By Layer
| Feature | Primary Files |
|---|---|
| Editor | components/Editor.astro, scripts/editor.ts, scripts/codemirror-setup.ts |
| Preview | scripts/preview.ts, lib/markdown.ts |
| Storage | lib/db.ts, scripts/editor.ts |
| Linting | scripts/markdown-linter.ts |
| Highlighting | lib/shiki/highlight.ts |
| Themes | layouts/Layout.astro, styles/tokens.css |
Next Steps
Setup
Set up your development environment
Architecture
Understand the technical architecture
Contributing
Start contributing to CodeInk