←back to Blog

Building AI-Powered Applications Using the Plan → Files → Code Workflow in TinyDev

«`html

Building AI-Powered Applications Using the Plan → Files → Code Workflow in TinyDev

In this tutorial, we introduce TinyDev class implementation, a minimal yet powerful AI code generation tool that utilizes the Gemini API to transform simple app ideas into comprehensive, structured applications. Designed to run effortlessly in Notebook, TinyDev follows a clean three-phase workflow—Plan → Files → Code—to ensure consistency, functionality, and modular design. Whether building a web interface, a Python backend, or a utility script, TinyDev allows users to describe their project in natural language and receive ready-to-run code files, automatically generated and saved in an organized directory. This makes it an ideal starting point for rapid prototyping or learning how AI can assist in development tasks.

Understanding the Target Audience

The primary audience for TinyDev includes software developers, project managers, and entrepreneurs interested in leveraging AI for application development. Their pain points often include:

  • Time constraints in coding and prototyping.
  • Difficulty in translating ideas into functional code.
  • Need for rapid iteration and testing of application concepts.

Their goals are to:

  • Accelerate the development process.
  • Reduce the complexity of coding tasks.
  • Enhance collaboration among team members.

Interests include:

  • AI and machine learning applications in software development.
  • Tools that streamline coding and project management.
  • Learning new technologies and methodologies.

Communication preferences lean towards clear, concise, and technical language, with a focus on practical applications and real-world examples.

TinyDev Class Implementation

The TinyDev class encapsulates the full logic of an AI-powered code generator using the Gemini API. It implements a structured three-phase workflow:

  1. Plan: Analyzes the user prompt to generate shared dependencies.
  2. Files: Identifies which files are needed for the application.
  3. Code: Generates functional code for each file individually.

The create_app method orchestrates the full app generation pipeline and saves the results, including code files and a detailed README, into a specified output directory, offering a complete, ready-to-use application scaffold from a single prompt.

Code Example


import google.generativeai as genai
import os
import json
import re
from pathlib import Path
from typing import List, Dict

class TinyDev:
    def __init__(self, api_key: str, model: str = "gemini-1.5-flash"):
        genai.configure(api_key=api_key)
        self.model = genai.GenerativeModel(model)
        self.generation_config = {
            'temperature': 0.1,
            'top_p': 0.8,
            'max_output_tokens': 8192,
        }
    
    def plan(self, prompt: str) -> str:
        planning_prompt = f"""As an AI developer, you’re building a tool that automatically generates code tailored to the user’s needs.
        the program you are writing is based on the following description:
        {prompt}
        the files we write will be generated by a python script. the goal is for us to all work together to write a program that will write the code for the user.
        since we are working together, we need to understand what our shared dependencies are. this includes:
        - import statements we all need to use
        - variable names that are shared between files
        - functions that are called from one file to another
        - any other shared state
        this is the most critical part of the process, if we don't get this right, the generated code will not work properly.
        please output a markdown file called shared_dependencies.md that lists all of the shared dependencies.
        the dependencies should be organized as:
        1. shared variables (globals, constants)
        2. shared functions (function signatures)
        3. shared classes (class names and key methods)
        4. shared imports (modules to import)
        5. shared DOM element ids (if web project)
        6. shared file paths/names
        be EXHAUSTIVE in your analysis. every file must be able to import or reference these shared items."""
        
        response = self.model.generate_content(
            planning_prompt,
            generation_config=self.generation_config
        )
        return response.text

Demo and Interactive Modes

The demo_tinydev function showcases TinyDev’s capabilities by running a predefined demo using one of several sample prompts, such as generating a Tic Tac Toe game or a Python news scraper. It initializes the TinyDev class with a Gemini API key, selects the first prompt from a list of project ideas, and guides the user through the full code generation pipeline, including planning shared dependencies, defining file structure, and generating code.

The interactive_tinydev function allows users to generate applications from their custom prompts in real time. After entering a valid Gemini API key, users can describe any app idea, and TinyDev will develop the complete project, code, structure, and supporting files automatically.

Conclusion

The TinyDev class demonstrates the potential of using AI to automate application scaffolding with remarkable accuracy and efficiency. By breaking down the code generation process into intuitive phases, it ensures that outputs are logically sound, well-structured, and aligned with the user’s intent. Whether you’re exploring new app ideas or seeking to accelerate development, TinyDev provides a lightweight and user-friendly solution powered by the Gemini models.

Check out the Notebook here. All credit for this research goes to the researchers of this project. Also, feel free to follow us on Twitter and don’t forget to join our 100k+ ML SubReddit and Subscribe to our Newsletter.

«`