Skip to main content
This guide provides a comprehensive overview of CodeInk’s file structure and explains the purpose of each directory and key file.

Repository Root

codeink/
├── src/                    # Source code
├── public/                 # Static assets
├── astro.config.mjs        # Astro configuration
├── package.json            # Dependencies and scripts
├── tsconfig.json           # TypeScript configuration
├── wrangler.toml           # Cloudflare deployment config
├── bun.lock               # Dependency lock file
├── README.md              # Project documentation
└── LICENSE                # MIT License

Source Directory (src/)

The src/ directory contains all application code:
src/
├── components/            # Reusable Astro components
├── layouts/               # Page layouts
├── pages/                 # Route pages (file-based routing)
├── scripts/               # Client-side TypeScript
├── lib/                   # Utility libraries and helpers
├── styles/                # Global CSS and themes
└── assets/                # SVG icons and images

Components (src/components/)

Reusable UI components built with Astro:
The main editor component containing:
  • CodeMirror editor pane
  • Preview pane
  • Resize handle between panes
  • Loading overlay
  • View mode management (editor/split/preview)
Location: src/components/Editor.astroKey Features:
  • Responsive layout with mobile support
  • Sticky pane headers
  • Custom resize handle with hover effects
Top navigation bar with:
  • Logo and site title
  • View mode tabs (optional)
  • Theme toggle
  • Export button
Location: src/components/Header.astro
Bottom status bar displaying:
  • Save status (idle/saving/saved)
  • Markdown lint issues count
  • Auto-fix button
Location: src/components/StatusBar.astro
Toggle buttons for view modes:
  • Editor only
  • Split view (default)
  • Preview only
Location: src/components/ViewTabs.astro
Button to switch between light and dark themes.Location: src/components/ThemeToggle.astro
Syntax-highlighted code block component used in content pages.Location: src/components/CodeBlock.astro
Reusable UI primitives for marketing/content pages.Locations:
  • src/components/Card.astro
  • src/components/Button.astro

Layouts (src/layouts/)

Page layout templates:
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)
Usage:
---
import Layout from "@/layouts/Layout.astro"
---
<Layout title="Page Title" description="Page description">
  <!-- Page content -->
</Layout>

Pages (src/pages/)

File-based routing - each .astro file becomes a route:
FileRoutePurpose
index.astro/Landing page
editor.astro/editorMain editor interface
documents.astro/documentsDocument management page
about.astro/aboutAbout page
markdown-cheat-sheet.astro/markdown-cheat-sheetMarkdown syntax guide
katex-math-guide.astro/katex-math-guideKaTeX math reference
mermaid-diagrams-guide.astro/mermaid-diagrams-guideMermaid diagram examples
404.astro/404Error page
robots.txt.ts/robots.txtSEO robots file
llms.txt.ts/llms.txtAI/LLM documentation

Scripts (src/scripts/)

Client-side TypeScript modules:

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
Key Functions:
export function initEditor(): void

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>
Location: src/lib/db.ts

markdown.ts

Markdown processing pipelineExports:
  • renderMarkdown(content: string): Promise<string>
  • extractTitle(content: string): string
Features:
  • Marked parser with extensions
  • Shiki syntax highlighting
  • Custom code block renderer
  • Mermaid diagram support
Location: src/lib/markdown.ts

markdown-title.ts

Extract document title from markdownExtracts first heading (H1-H6) or falls back to “Untitled”Location: src/lib/markdown-title.ts

default-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.md

Shiki Highlighter (src/lib/shiki/)

Syntax highlighting engineLocation: src/lib/shiki/highlight.tsFeatures:
  • On-demand language loading
  • 60+ supported languages
  • Light and dark themes
  • Language aliases (js → javascript, etc.)
Main Export:
highlightCode(code: string, lang?: string): Promise<string>

Styles (src/styles/)

Global CSS organized by concern:

global.css

Main stylesheet importing all other CSS filesLocation: src/styles/global.css

tokens.css

CSS custom properties (design tokens):
  • Colors (background, foreground, primary, etc.)
  • Typography (font families, sizes)
  • Spacing and sizing
  • Border radius
Location: src/styles/tokens.css

base.css

Base element styles and resetsLocation: src/styles/base.css

prose.css

Typography styles for markdown previewApplied via .markdown-prose classLocation: src/styles/prose.css

code.css

Code block and syntax highlighting stylesLocation: src/styles/code.css

utilities.css

Custom utility classesLocation: src/styles/utilities.css

integrations.css

Styles for third-party integrations (Mermaid, KaTeX)Location: src/styles/integrations.css

Assets (src/assets/)

Static SVG icons and images:
src/assets/
├── logo.svg                    # CodeInk logo
├── icons/
│   ├── tech/                   # Technology logos
│   │   ├── astro.svg
│   │   ├── bun.svg
│   │   ├── mermaid.svg
│   │   ├── tailwind.svg
│   │   └── ts.svg
│   └── toggle-theme.svg        # Theme toggle icon

Public Directory (public/)

Static files served as-is:
public/
├── favicon.svg                 # Site favicon
├── favicon-192.png             # PWA icon (192x192)
├── favicon-512.png             # PWA icon (512x512)
├── apple-touch-icon.png        # iOS home screen icon
├── og-image.png                # Social media preview image
└── icons/
    └── lang/                   # Code language icons
        ├── default.svg
        ├── javascript.svg
        ├── python.svg
        ├── typescript.svg
        └── ... (60+ language icons)

Configuration Files

Astro framework configurationLocation: astro.config.mjsKey Settings:
{
  site: 'https://codeink.app',
  output: 'server',
  adapter: cloudflare(),
  integrations: [sitemap()],
  vite: {
    plugins: [tailwindcss()],
    build: {
      rollupOptions: {
        output: {
          manualChunks() { /* ... */ }
        }
      }
    }
  }
}

Import Aliases

CodeInk uses the @/ alias for cleaner imports:
// Instead of:
import { saveDoc } from "../../../lib/db"

// Use:
import { saveDoc } from "@/lib/db"
Alias mapping (tsconfig.json):
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

File Naming Conventions

Components

PascalCase with .astro extensionExamples: Editor.astro, StatusBar.astro

Scripts

kebab-case with .ts extensionExamples: editor.ts, markdown-linter.ts

Styles

kebab-case with .css extensionExamples: global.css, code.css

Pages

kebab-case with .astro extensionExamples: index.astro, markdown-cheat-sheet.astro

Key File Relationships

Understanding how files connect:

Finding Code

FeaturePrimary Files
Editorcomponents/Editor.astro, scripts/editor.ts, scripts/codemirror-setup.ts
Previewscripts/preview.ts, lib/markdown.ts
Storagelib/db.ts, scripts/editor.ts
Lintingscripts/markdown-linter.ts
Highlightinglib/shiki/highlight.ts
Themeslayouts/Layout.astro, styles/tokens.css

Next Steps

Setup

Set up your development environment

Architecture

Understand the technical architecture

Contributing

Start contributing to CodeInk

Build docs developers (and LLMs) love