Building large apps
Tips for building large apps if you're hitting token limits
If you're working on large apps that are approaching your model’s token limits (e.g., 1 million for Gemini models), this guide will help you manage your app effectively.
Use a Long-Context Model
If you're not already using them, I recommend Google's Gemini models for large apps, as they support up to 1 million input tokens. While other models also offer large context windows, Gemini performs particularly well on long-context benchmarks.
Use Smart Context
Smart Context is a Dyad Pro feature that automatically selects the most relevant files from your codebase for the current conversation using a smaller model. This helps optimize your AI credit usage, as the flagship model doesn't need to process your entire codebase.
Smart Context also performs token compression by using a smaller model to pre-select files, allowing it to effectively handle well over 1 million tokens from your codebase.
However, keep in mind that Smart Context may struggle with broad queries (e.g., “make this app better”). In such cases, it falls back to using the flagship model on your entire codebase. If your codebase exceeds the model’s context window (e.g., >1 million tokens), this fallback will fail. In those cases, manual context management is your best option.
Manual Context Management
Starting with v0.8.0, Dyad includes advanced context management features that let you control exactly which parts of your codebase the model can access. This is especially useful for large projects but it requires some setup.
- For all users: Use glob-style paths (e.g.,
src/**
,dir/*.ts
) to specify which files to include in the chat context. - For Pro users with Smart Context: These paths guide Smart Context’s initial file selection and are used for the main model fallback scenario described above. You can also auto-include specific files (e.g., key modules or instructions) to ensure they're always included, regardless of what Smart Context selects.
Note: This may lead to unexpected behavior, such as Dyad writing new files or duplicating code, since the AI won’t have access to your entire codebase.
Splitting Your App
This approach requires the most effort and planning, but splitting your app into multiple smaller apps can help avoid hitting context limits and can also improve maintainability.
Suggestions for splitting your app:
- Are there features used only by specific user types (e.g., admins or employees) that could be isolated into a separate app?
- Do you have standalone pages like a marketing site or landing page? These can be split off and deployed as separate Vercel projects on subdomains (e.g.,
your-site.com
andapp.yoursite.com
).
Even if splitting your app isn't feasible, keeping your codebase modular—such as grouping related features into directories—makes your app easier to maintain and more suitable for manual context management.