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 […] The post Building AI-Powered Applications Using the Plan → Files → Code Workflow in TinyDev appeared first on MarkTechPost.

Jun 15, 2025 - 11:40
 0
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 & 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.

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

We begin by importing essential libraries required for the TinyDev code generator. google.generativeai is used to interact with the Gemini API, while standard libraries like os, json, and re support file handling and text processing. Path and type hints from typing ensure clean file operations and better code readability.

class TinyDev:
   """
   TinyDev: A lightweight AI code generator inspired by smol-dev
   Uses Gemini API to generate complete applications from simple prompts
   Follows the proven three-phase workflow: Plan → Files → Code
   """
  
   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:
       """
       Phase 1: Generate project plan and shared dependencies
       Creates the foundation for consistent code generation
       """
       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


   def specify_file_paths(self, prompt: str, shared_deps: str) -> List[str]:
       """
       Phase 2: Determine what files need to be created
       """
       files_prompt = f"""As an AI developer, you’re building a tool that automatically generates code tailored to the user’s needs.


the program:
{prompt}


the shared dependencies:
{shared_deps}


Based on the program description and shared dependencies, return a JSON array of the filenames that should be written.


Only return the JSON array, nothing else. The JSON should be an array of strings representing file paths.


For example, for a simple web app you might return:
["index.html", "styles.css", "script.js"]


For a Python project you might return:
["main.py", "utils.py", "config.py", "requirements.txt"]


JSON array:"""


       response = self.model.generate_content(
           files_prompt,
           generation_config=self.generation_config
       )
      
       try:
           json_match = re.search(r'\[.*?\]', response.text, re.DOTALL)
           if json_match:
               files = json.loads(json_match.group())
               return [f for f in files if isinstance(f, str)]
           else:
               lines = [line.strip() for line in response.text.split('\n') if line.strip()]
               files = []
               for line in lines:
                   if '.' in line and not line.startswith('#'):
                       file = re.sub(r'[^\w\-_./]', '', line)
                       if file:
                           files.append(file)
               return files[:10] 
       except Exception as e:
           print(f"Error parsing files: {e}")
           return ["main.py", "README.md"]


   def generate_code_sync(self, prompt: str, shared_deps: str, filename: str) -> str:
       """
       Phase 3: Generate code for individual files
       """
       code_prompt = f"""As an AI developer, you’re building a tool that automatically generates code tailored to the user’s needs..


the program:
{prompt}


the shared dependencies:
{shared_deps}


Please write the file {filename}.


Remember that your job is to write the code for {filename} ONLY. Do not write any other files.


the code should be fully functional. meaning:
- all imports should be correct
- all variable references should be correct 
- all function calls should be correct
- the code should be syntactically correct
- the code should be logically correct


Make sure to implement every part of the functionality described in the program description.


DO NOT include ``` code fences in your response. Return only the raw code.


Here is the code for {filename}:"""


       response = self.model.generate_content(
           code_prompt,
           generation_config=self.generation_config
       )
      
       code = response.text
       code = re.sub(r'^```[\w]*\n', '', code, flags=re.MULTILINE)
       code = re.sub(r'\n```$', '', code, flags=re.MULTILINE)
      
       return code.strip()


   def create_app(self, prompt: str, output_dir: str = "/content/generated_app") -> Dict:
       """
       Main workflow: Transform a simple prompt into a complete application
       """
       print(f"                        </div>
                                            <div class=
                            
                                Read More