Skip to content

File Structure

Temp edited this page Jan 9, 2026 · 5 revisions

File Structure

Project organization and key files in D1 Database Manager.

Overview

D1 Manager follows a modular structure separating frontend (React) and backend (Cloudflare Worker) code with clear organization.

Root Directory

d1-manager/
β”œβ”€β”€ src/                      # Frontend source code
β”œβ”€β”€ worker/                   # Backend source code
β”œβ”€β”€ public/                   # Static assets
β”œβ”€β”€ dist/                     # Build output (git-ignored)
β”œβ”€β”€ node_modules/             # Dependencies (git-ignored)
β”œβ”€β”€ .github/                  # GitHub Actions workflows
β”œβ”€β”€ package.json              # Project dependencies
β”œβ”€β”€ package-lock.json         # Locked dependencies
β”œβ”€β”€ tsconfig.json             # TypeScript root config
β”œβ”€β”€ tsconfig.app.json         # Frontend TS config
β”œβ”€β”€ tsconfig.node.json        # Node.js TS config
β”œβ”€β”€ vite.config.ts            # Vite configuration
β”œβ”€β”€ tailwind.config.js        # Tailwind CSS config
β”œβ”€β”€ postcss.config.js         # PostCSS configuration
β”œβ”€β”€ components.json           # shadcn/ui config
β”œβ”€β”€ wrangler.toml             # Worker production config
β”œβ”€β”€ wrangler.dev.toml         # Development config
β”œβ”€β”€ .env.example              # Environment template
β”œβ”€β”€ .gitignore                # Git ignore rules
β”œβ”€β”€ README.md                 # Project documentation
β”œβ”€β”€ LICENSE                   # MIT license
β”œβ”€β”€ SECURITY.md               # Security policy
β”œβ”€β”€ CONTRIBUTING.md           # Contribution guide
β”œβ”€β”€ CODE_OF_CONDUCT.md        # Community standards
β”œβ”€β”€ DOCKER_README.md          # Docker deployment guide
└── VERSION                   # Version number (1.1.1)

Frontend Structure (src/)

src/
β”œβ”€β”€ components/               # React components
β”‚   β”œβ”€β”€ ui/                  # shadcn/ui base components
β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”œβ”€β”€ card.tsx
β”‚   β”‚   β”œβ”€β”€ dialog.tsx
β”‚   β”‚   β”œβ”€β”€ input.tsx
β”‚   β”‚   β”œβ”€β”€ label.tsx
β”‚   β”‚   β”œβ”€β”€ select.tsx
β”‚   β”‚   β”œβ”€β”€ checkbox.tsx
β”‚   β”‚   β”œβ”€β”€ accordion.tsx
β”‚   β”‚   β”œβ”€β”€ progress.tsx
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ DatabaseView.tsx      # Database table list
β”‚   β”œβ”€β”€ TableView.tsx         # Table data browser
β”‚   β”œβ”€β”€ QueryConsole.tsx      # SQL query executor
β”‚   β”œβ”€β”€ SchemaDesigner.tsx    # Visual table creator
β”‚   β”œβ”€β”€ FilterBar.tsx         # Row-level filtering
β”‚   β”œβ”€β”€ ThemeToggle.tsx       # Theme switcher
β”‚   β”œβ”€β”€ Header.tsx            # App header
β”‚   β”œβ”€β”€ DatabaseComparison.tsx
β”‚   β”œβ”€β”€ CrossDatabaseSearch.tsx
β”‚   β”œβ”€β”€ MigrationWizard.tsx
β”‚   β”œβ”€β”€ CascadeImpactSimulator.tsx
β”‚   β”œβ”€β”€ TimeTravelInfo.tsx        # Time Travel tab
β”‚   └── ...
β”œβ”€β”€ contexts/                 # React contexts
β”‚   └── ThemeContext.tsx      # Theme state management
β”œβ”€β”€ hooks/                    # Custom hooks
β”‚   └── useTheme.ts           # Theme hook
β”œβ”€β”€ services/                 # External services
β”‚   β”œβ”€β”€ api.ts                # API client
β”‚   └── auth.ts               # Authentication helpers
β”œβ”€β”€ lib/                      # Shared libraries
β”‚   └── utils.ts              # Utility functions
β”œβ”€β”€ App.tsx                   # Main app component
β”œβ”€β”€ main.tsx                  # React entry point
└── index.css                 # Global styles + Tailwind

Key Frontend Files

App.tsx - Main application:

  • Routing logic
  • Database list view
  • State management
  • View switching

main.tsx - Entry point:

  • React initialization
  • DOM rendering
  • Theme provider

index.css - Global styles:

  • Tailwind imports
  • CSS variables for theming
  • Global styles

services/api.ts - API client:

  • Centralized API calls
  • Type-safe methods
  • Error handling

contexts/ThemeContext.tsx - Theme management:

  • Light/Dark/System modes
  • LocalStorage persistence
  • CSS class manipulation

Backend Structure (worker/)

worker/
β”œβ”€β”€ routes/                   # API route handlers
β”‚   β”œβ”€β”€ databases.ts          # Database operations
β”‚   β”œβ”€β”€ tables.ts             # Table operations
β”‚   β”œβ”€β”€ queries.ts            # Query execution
β”‚   β”œβ”€β”€ saved-queries.ts      # Saved queries
β”‚   β”œβ”€β”€ undo.ts               # Undo/rollback operations
β”‚   β”œβ”€β”€ jobs.ts               # Job history and events
β”‚   └── time-travel.ts        # Time Travel bookmarks
β”œβ”€β”€ utils/                    # Utility functions
β”‚   β”œβ”€β”€ auth.ts               # JWT validation
β”‚   β”œβ”€β”€ cors.ts               # CORS headers
β”‚   β”œβ”€β”€ helpers.ts            # Helper functions
β”‚   β”œβ”€β”€ database-tracking.ts  # DB access tracking
β”‚   β”œβ”€β”€ undo.ts               # Undo/rollback helpers
β”‚   └── time-travel.ts        # Time Travel helpers
β”œβ”€β”€ types/                    # TypeScript types
β”‚   └── index.ts              # Type definitions
β”œβ”€β”€ index.ts                  # Worker entry point
└── schema.sql                # Metadata DB schema

Key Backend Files

index.ts - Worker entry:

  • Request handling
  • Route dispatching
  • Error handling
  • Localhost detection

routes/databases.ts - Database CRUD:

  • List databases
  • Create database
  • Delete database
  • Rename database
  • Bulk operations

routes/tables.ts - Table operations:

  • List tables
  • Get schema/data
  • Create/rename/delete
  • Column management
  • Dependencies

routes/queries.ts - Query execution:

  • Execute SQL
  • Batch queries
  • Query history
  • Validation

utils/auth.ts - Authentication:

  • JWT validation
  • Cloudflare Access integration

utils/cors.ts - CORS management:

  • Allowed origins
  • CORS headers

schema.sql - Metadata database:

  • Query history table
  • Saved queries table
  • Database tracking

Configuration Files

package.json

Purpose: Project metadata and dependencies

Key sections:

  • name: "d1-manager"
  • version: "1.1.1"
  • scripts: Build and dev commands
  • dependencies: Runtime dependencies
  • devDependencies: Development tools

tsconfig.json

Purpose: TypeScript root configuration

Settings:

  • Strict mode enabled
  • ES2020 target
  • Module resolution: bundler
  • Path aliases: @/* β†’ src/*

tsconfig.app.json

Purpose: Frontend TypeScript config

Includes:

  • src/ directory
  • Vite types
  • React types

tsconfig.node.json

Purpose: Node.js tooling TypeScript config

Includes:

  • vite.config.ts
  • Build scripts

vite.config.ts

Purpose: Vite build configuration

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    port: 5173
  }
});

tailwind.config.js

Purpose: Tailwind CSS configuration

Settings:

  • Content paths
  • Theme customization
  • Dark mode: 'class'
  • Plugin: tailwindcss-animate

components.json

Purpose: shadcn/ui configuration

Settings:

  • Style: default
  • Base color: slate
  • CSS variables: true
  • TypeScript: true
  • Alias: @/components

wrangler.toml

Purpose: Worker production configuration

Sections:

  • Worker name
  • Main entry point
  • D1 bindings
  • Routes (optional)
  • Assets binding

wrangler.dev.toml

Purpose: Local development configuration

Settings:

  • Development worker name
  • Local mode enabled
  • Mock D1 binding
  • Port: 8787

.env.example

Purpose: Environment variable template

# Worker API URL (local development)
VITE_WORKER_API=http://localhost:8787

Build Output (dist/)

Git-ignored - Generated by npm run build

dist/
β”œβ”€β”€ assets/                   # Bundled JS/CSS
β”‚   β”œβ”€β”€ index-[hash].js
β”‚   β”œβ”€β”€ index-[hash].css
β”‚   └── ...
β”œβ”€β”€ index.html                # Entry HTML
└── ...

Documentation Files

README.md

Purpose: Main project documentation

Sections:

  • Features
  • Quick start
  • Installation
  • Configuration
  • Deployment
  • API reference

SECURITY.md

Purpose: Security policy

Sections:

  • Supported versions
  • Reporting vulnerabilities
  • Security best practices
  • Known considerations

CONTRIBUTING.md

Purpose: Contribution guidelines

Sections:

  • Development setup
  • Coding standards
  • Testing
  • Pull request process

LICENSE

Purpose: MIT License text

CODE_OF_CONDUCT.md

Purpose: Community guidelines

DOCKER_README.md

Purpose: Docker deployment instructions

VERSION

Purpose: Single source of truth for version number

Contents: 1.1.1

Git Files

.gitignore

Ignores:

# Dependencies
node_modules/

# Build output
dist/
.wrangler/

# Environment
.env
wrangler.toml

# IDE
.vscode/
.idea/

# OS
.DS_Store
Thumbs.db

.github/

GitHub-specific files:

  • Workflows (CI/CD)
  • Issue templates
  • Pull request templates
  • FUNDING.yml

Development Files

.eslintrc / eslint.config.js

Purpose: Linting configuration

Rules:

  • TypeScript rules
  • React rules
  • React Hooks rules

.prettierrc

Purpose: Code formatting (if used)

postcss.config.js

Purpose: PostCSS configuration

Plugins:

  • tailwindcss
  • autoprefixer

Public Assets

public/
β”œβ”€β”€ favicon.ico
β”œβ”€β”€ logo.svg
└── ...

Static assets served as-is.

File Naming Conventions

Components

Format: PascalCase

Examples:

  • DatabaseView.tsx
  • TableView.tsx
  • QueryConsole.tsx

Utilities

Format: camelCase

Examples:

  • api.ts
  • auth.ts
  • helpers.ts

Configuration

Format: kebab-case or specific conventions

Examples:

  • vite.config.ts
  • tailwind.config.js
  • .env.example

Import Paths

Alias Configuration

tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Usage:

// Instead of
import { Button } from '../../../components/ui/button';

// Use
import { Button } from '@/components/ui/button';

Next Steps


Need Help? See Troubleshooting or open an issue.

Clone this wiki locally