Development Tools

Development tools and utilities for ShipKit

Development Tools

ShipKit provides a comprehensive set of development tools to help developers build, test, and debug applications efficiently.

Core Development Tools

AI Development Tools

AI Loader

The AI Loader provides context and information about the project to AI assistants:

// src/lib/ai/ai-loader.ts
export class AILoader {
    private context: AIContext;

    constructor() {
        this.context = {
            projectName: "ShipKit",
            description: "Production-ready SaaS starter kit built with Next.js",
            technologies: {
                framework: "Next.js (App Router)",
                language: "TypeScript",
                styling: ["Tailwind CSS", "CSS Modules"],
                ui: ["Shadcn/UI", "Radix UI", "Lucide Icons"],
                // ... more technology stack details
            },
            // ... project structure and conventions
        };
    }

    public getContext(): AIContext {
        return this.context;
    }

    public getTechnology(key: keyof TechnologyStack): string | string[] {
        return this.context.technologies[key];
    }
}

AI Analyzer

The AI Analyzer helps analyze and understand different aspects of the codebase:

// src/lib/ai/ai-analyzer.ts
export class AIAnalyzer {
    public getPitfalls(): string[] {
        return [
            "Nesting server components inside client components",
            "Using client-side data fetching when server-side is better",
            "Not handling loading and error states",
            // ... more pitfalls
        ];
    }

    public getRecommendedTools(task: string): string[] {
        const tools: Record<string, string[]> = {
            forms: [
                "react-hook-form for form handling",
                "zod for validation",
                "Shadcn/UI form components",
            ],
            // ... more tool recommendations
        };
        return tools[task] || [];
    }
}

Logging System

A comprehensive logging system for development and debugging:

// src/lib/logger.ts
export const logger = console;

export const prefixes = {
    wait: white(bold("○")),
    error: red(bold("⨯")),
    warn: yellow(bold("⚠")),
    ready: "▲",
    info: white(bold(" ")),
    event: green(bold("✓")),
    trace: magenta(bold("»")),
};

export function info(...message: any[]) {
    prefixedLog("info", ...message);
}

export function error(...message: any[]) {
    prefixedLog("error", ...message);
}

export function warn(...message: any[]) {
    prefixedLog("warn", ...message);
}

Documentation Tools

Tools for managing and generating documentation:

// src/lib/docs.ts
export function processDirectory(dir: string): NavSection[] {
    const sections: NavSection[] = [];
    const rootPath = path.join(process.cwd(), "docs");

    // Process directories and files
    const entries = fs.readdirSync(path.join(rootPath, dir), {
        withFileTypes: true,
    });

    // ... documentation processing logic

    return sections;
}

export const getDocsNavigation = cache((): NavSection[] => {
    return processDirectory("");
});

Testing Utilities

Download Testing

The download testing utility helps verify file download functionality:

// src/app/(app)/(dev)/test/page.tsx
export default async function TestPage() {
    const session = await auth();

    return (
        <div className="container mx-auto py-8">
            <h1 className="mb-6 text-2xl font-bold">Download Page</h1>
            {session ? <DownloadButton userId={session.user.id} /> : <LoginButton />}
        </div>
    );
}

Download Button Component

interface DownloadButtonProps {
    userId: string;
}

export const DownloadButton = ({ userId }: DownloadButtonProps) => {
    const [downloadUrl, setDownloadUrl] = useState<string | null>(null);

    const handleDownload = async () => {
        const temporaryLinkId = await generateTemporaryLink({ userId });
        const url = `/download/${temporaryLinkId}`;
        setDownloadUrl(url);
        window.open(url, "_blank");
    };

    return (
        <div className="space-y-4">
            <Button onClick={() => void handleDownload()}>
                Generate Download Link
            </Button>
            {/* Download link display */}
        </div>
    );
};

Development Features

Platform Detection

// src/lib/utils/is.ts
export const is = {
    mac: navigator?.platform?.includes("Mac"),
    windows: navigator?.platform?.includes("Win"),
};

Color Utilities

Terminal color formatting utilities:

// src/lib/utils/pico-colors.ts
export const reset = enabled ? (s: string) => `\x1b[0m${s}\x1b[0m` : String;
export const bold = formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m");
export const red = formatter("\x1b[31m", "\x1b[39m");
export const green = formatter("\x1b[32m", "\x1b[39m");
export const yellow = formatter("\x1b[33m", "\x1b[39m");
// ... more color formatters

Builder.io Integration

Tools for managing Builder.io components:

// src/lib/builder-io.ts
const BUILDER_COMPONENTS = {
    LAUNCH_HERO: "LaunchHero",
    QUICK_START: "QuickStart",
    CODE_PREVIEW: "CodePreview",
    PRICING_SECTION: "PricingSection",
    FAQ_SECTION: "FAQSection",
    CTA_SECTION: "CTASection",
} as const;

export function registerComponents() {
    Object.values(BUILDER_COMPONENTS).forEach((component) => {
        Builder.registerComponent(
            dynamic(() => import("@/components/builder/launch-components")
                .then((mod) => mod[component])),
            {
                name: component,
                inputs: [],
            }
        );
    });
}

Best Practices

  1. Type Safety

    • Use TypeScript interfaces
    • Prop validation
    • Error boundaries
  2. Performance

    • Client hydration
    • Dynamic imports
    • State management
  3. Code Organization

    • Component structure
    • File naming
    • Directory layout

Error Handling

  1. Authentication Errors

    try {
        const session = await auth();
        if (!session) {
            // Handle unauthenticated state
        }
    } catch (error) {
        // Handle authentication error
    }
    
  2. Download Errors

    try {
        const temporaryLinkId = await generateTemporaryLink({ userId });
        // Handle successful link generation
    } catch (error) {
        // Handle link generation error
    }
    

Testing

  1. Component Tests

    describe('DevelopmentTools', () => {
        it('should handle authentication', () => {
            // Test implementation
        });
    
        it('should generate download links', () => {
            // Test implementation
        });
    });
    
  2. Integration Tests

    describe('DevToolsIntegration', () => {
        it('should integrate with authentication', () => {
            // Test implementation
        });
    
        it('should handle file downloads', () => {
            // Test implementation
        });
    });
    

Customization

  1. Adding New Tools

    export const NewDevTool = () => {
        return (
            <div className="container mx-auto py-8">
                <h1 className="mb-6 text-2xl font-bold">New Tool</h1>
                {/* Tool implementation */}
            </div>
        );
    };
    
  2. Styling

    <div className="rounded-lg border bg-card p-4 text-card-foreground shadow-sm">
        {/* Component content */}
    </div>
    
  3. Layout

    <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
        {/* Grid items */}
    </div>