App Factory & Automated Code Gen
Relevant source files
The following files were used as context for generating this wiki page:
The App Factory & Automated Code Gen system is a comprehensive suite within Infinity OS designed to automate the entire application lifecycle, from initial scaffolding and AI-powered code generation to compilation, hosting, and deployment. It provides a modular environment where developers can generate full-stack applications based on high-level descriptions, manage them via an integrated IDE, and eventually "disconnect" them as standalone packages for external hosting.
The system is built on a multi-language foundation, supporting Python, JavaScript, TypeScript, and various frameworks like React, Next.js, and FastAPI. It leverages AI-driven engines to handle complex tasks such as phase-based development (Planning → Foundation → Core → Styling → Integration → Optimization), automated documentation generation, and GitHub repository integration.
Sources: workers/app-factory/src/app_factory.py:1-16, workers/app-factory/src/code_engine.py:1-15, workers/app-factory/src/doc_generator.py:1-6
Core Architecture & Components
The App Factory operates through several specialized modules that coordinate to manage application state and artifacts. The central orchestrator is the AppFactory class, which manages the AppRegistry, BuildSystem, InternalHosting, GitHubIntegration, and ModularDisconnect components.
Component Overview
| Component | Description | Key Responsibilities |
|---|---|---|
| AppRegistry | Central storage and tracking for application metadata. | PID generation, app state persistence, metadata management. |
| BuildSystem | Handles compilation and artifact generation for different runtimes. | Dependency installation, source compilation, artifact movement. |
| CodeGenerationEngine | AI-powered engine for generating source code from prompts. | Scaffolding, completion, refactoring, phase-based generation. |
| DocumentationGenerator | Generates technical documentation and API specs. | README, API.md, CHANGELOG, OpenAPI JSON, JSDoc/Docstrings. |
| InternalHosting | Provides a sandbox environment for live application previews. | Process management, port allocation, HTTP serving. |
| GitHubIntegration | Manages remote repository synchronization. | Repo creation, automated commits, pushing source code. |
Sources: workers/app-factory/src/app_factory.py:465-475, workers/app-factory/src/code_engine.py:317-323, workers/app-factory/src/doc_generator.py:53-58
System Workflow
The following diagram illustrates the lifecycle of an application from creation to deployment within the factory:
AI Code Generation Engine
The CodeGenerationEngine is the intelligence layer of the system. It uses a phase-based development approach to ensure complex applications are built logically. It supports multiple ProjectType templates, including REACT_APP, NEXTJS_APP, and FASTAPI_BACKEND.
Generation Phases
The engine follows a structured sequence defined by the GenerationPhase enum:
- PLANNING: Architectural design and feature mapping.
- FOUNDATION: Initial project scaffolding and configuration files.
- CORE: Implementation of primary business logic and components.
- STYLING: Application of UI frameworks (e.g., Tailwind CSS).
- INTEGRATION: Connecting front-end and back-end modules.
- OPTIMIZATION/TESTING/DOCUMENTATION: Final polishing and artifact generation.
Sources: workers/app-factory/src/code_engine.py:64-74, backend/code_engine.py:64-74
Template-Based Scaffolding
The system maintains pre-defined templates for rapid deployment. For instance, the REACT_APP template includes package.json, vite.config.ts, tailwind.config.js, and basic source files like App.tsx and main.tsx.
PROJECT_TEMPLATES = {
ProjectType.REACT_APP: {
"package.json": {
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"vite": "^5.0.0",
"tailwindcss": "^3.4.0"
}
},
"src/App.tsx": "import { useState } from 'react'..."
}
}
Sources: workers/app-factory/src/code_engine.py:129-220, backend/code_engine.py:129-220
Documentation Generation
The DocumentationGenerator ensures that every generated application is production-ready by automatically creating a full documentation suite. It extracts metadata from package.json or pyproject.toml to populate project details.
Generated Artifacts
- README.md: Includes installation, quick start, features, and dependency tables.
- API.md: Detailed endpoint documentation grouped by tags, including request/response examples.
- CHANGELOG.md: Version history following Keep a Changelog standards.
- openapi.json: A full OpenAPI 3.0.3 specification for backend services.
- Typescript Types: Interface definitions derived from project classes.
Sources: workers/app-factory/src/doc_generator.py:100-290
Automated Code Comments
The system can inject JSDoc comments into JavaScript/TypeScript or docstrings into Python code using pattern matching:
def generate_python_docstrings(self, code: str) -> str:
"""Add docstrings to Python code"""
# Pattern for function definitions
function_pattern = r'(def\s+(\w+)\s*\(([^)]*)\)\s*(?:->\s*[^:]+)?:)\s*\n(\s*)'
# ... logic to insert Args and Returns sections ...
Sources: workers/app-factory/src/doc_generator.py:349-368
Frontend IDE Interface
The App Factory includes a browser-native IDE (IDEPage) that provides a visual interface for managing projects and interacting with the AI generator.
Key Features of the IDE:
- File Explorer: A tree-view navigation for project structures.
- Monaco-style Editor: A multi-tab editor with syntax highlighting and line numbering.
- AI Assistant Panel: A chat-based interface for sending generation prompts to the backend.
- Live Preview: An iframe-based sandbox that renders React/Tailwind code in real-time.
- Integrated Terminal: A terminal emulator for running npm commands or git operations.
Application Disconnect & Standalone Export
A unique feature of the App Factory is the ModularDisconnect system. This allows an application developed within the Infinity OS ecosystem to be exported as a standalone package, complete with deployment scripts for various cloud providers.
Export Structure
When an app is disconnected, the ModularDisconnect.export_standalone method creates a ZIP containing:
- Source Code: The full application source.
- Build Artifacts: Compiled files (e.g.,
dist/orbuild/). - Manifest: A
manifest.jsoncontaining metadata, PID, and versioning. - Deployment Scripts: Bash scripts for Cloudflare Pages, Vercel, Netlify, and Docker.
Sources: workers/app-factory/src/app_factory.py:408-462
Deployment Script Example
The system generates platform-specific logic, such as the following for Cloudflare:
#!/bin/bash
# Deploy to Cloudflare Pages
cd source
npm install
npm run build
wrangler pages deploy dist --project-name={{app_name}}
Sources: workers/app-factory/src/app_factory.py:435-442
Data Models and State Management
The App Factory utilizes Pydantic and Dataclasses to ensure strict typing for application metadata and lifecycle events.
App Lifecycle States
| Status | Meaning |
|---|---|
CREATED | Source files written to disk; entry added to registry. |
BUILDING | BuildSystem is currently installing dependencies or compiling. |
READY | Build finished successfully; artifacts available in build_dir. |
HOSTING | App is currently running in the internal preview sandbox. |
DEPLOYED | Source has been pushed to a remote repository (GitHub). |
DISCONNECTED | App has been exported as a standalone package. |
Sources: workers/app-factory/src/app_factory.py:24-34
Core Data Structures
@dataclass
class App:
pid: str # Unique Product ID
name: str
app_type: AppType # Enum (NODEJS, REACT, etc.)
status: AppStatus # Enum (CREATED, READY, etc.)
source_dir: str # Path to source on disk
build_dir: str # Path to compiled artifacts
github_repo: Optional[GitHubRepo]
Sources: workers/app-factory/src/app_factory.py:68-85
Summary
The App Factory & Automated Code Gen system provides a highly automated, end-to-end development pipeline. By combining AI-driven generation phases with robust build and documentation tools, it enables the rapid creation of standardized, production-ready applications. The inclusion of an integrated IDE and a standalone export mechanism ensures that the platform supports both internal experimentation and external production deployments.
Sources: workers/app-factory/src/app_factory.py:603-625, workers/app-factory/src/code_engine.py:465-475