# Prompt-as-Code Schema Architecture for GPT-Image2: A Complete Guide

> Unlock GPT-Image2 potential with Prompt-as-Code schema architecture. This guide explains how to transform text prompts into structured JSON for powerful image generation.

- Repository: [苍何/awesome-gpt-image-2](https://github.com/freestylefly/awesome-gpt-image-2)
- Tags: architecture
- Published: 2026-08-31

---

**The Prompt-as-Code architecture in the freestylefly/awesome-gpt-image-2 repository transforms free-form textual prompts into structured, machine-readable JSON specifications through atomic decomposition, reusable templates, and a centralized style library.**

The **Prompt-as-Code** paradigm reimagines image generation prompts as versionable, composable code objects rather than brittle prose. This article examines the complete architecture as implemented in the [freestylefly/awesome-gpt-image-2](https://github.com/freestylefly/awesome-gpt-image-2) repository, revealing how three interlocking components—atomic schemas, JSON templates, and a central style library—enable deterministic control over GPT-Image2 outputs.

## Core Components of the Prompt-as-Code Architecture

### Atomic Schema: Decomposing Prompts into Reusable Parts

The foundation of the system is the **atomic schema**, defined in [`README.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/README.md) under the "Atomic schema" section. This decomposes any visual prompt into five canonical categories:

- **Subjects** — the primary entities, characters, or objects
- **Lighting** — directional, ambient, and atmospheric light sources
- **Materials** — surface properties and texture descriptors
- **Layout** — spatial arrangement and compositional structure
- **Visual details** — secondary elements that complete the scene

By enforcing this decomposition, the architecture ensures that every prompt element becomes addressable, editable, and recombinable through code rather than manual rewriting.

### JSON-Based Templates: Agent-Ready Specifications

Located in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md), the template library provides concrete JSON schemas for common visual categories. Each template mirrors the atomic schema structure, exposing typed fields that automated systems can populate.

The templates cover diverse output types including **UI screenshots**, **infographics**, **character concepts**, and **architectural renders**. Every template defines required fields (`type`, `subject`, `layout`) alongside optional styling constraints.

### Central Style Library: Single Source of Truth for Visual Tokens

All reusable style definitions live in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json). This catalog includes:

- Named color palettes with hex codes and semantic tags
- Material presets (metallic, matte, translucent, etc.)
- Lighting configurations (golden hour, studio key-fill, neon ambient)
- Typography families and aesthetic descriptors

The style library is consumed by both the Agent skill layer and the web frontend, ensuring consistent token resolution across the pipeline.

## How the Prompt-as-Code Pipeline Executes

The architecture follows a five-stage transformation from human intent to API payload:

**1. Prompt Authoring**
Users begin with plain-text descriptions or community case studies from [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md).

**2. Atomic Decomposition**
The system parses free-form text into the canonical five-part schema according to rules specified in [`README.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/README.md).

**3. JSON Construction**
Decomposed elements populate a structured template. Because field names map directly to atomic categories, agents can programmatically edit, merge, or batch-process prompts without prose manipulation.

**4. Style Resolution**
When JSON fields reference style tokens (e.g., `"primary_color": "Neon Green"`), the system validates against [`style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/style-library.json) and retrieves auxiliary metadata.

**5. Execution**
The final JSON payload routes through Vercel functions in `api/_lib/` (including [`watcha.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/watcha.js) and [`supabase.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/supabase.js)), which enforce schema constraints before calling the GPT-Image2 generation API.

## Implementation Examples from the Source Code

### UI Screenshot Template

This example from [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) demonstrates how layout, content, and style are separated into addressable fields:

```json
{
  "type": "UI Screenshot",
  "platform": "iOS",
  "product": "Fitness App",
  "layout": "Card‑based feed with bottom tab bar",
  "style": {
    "theme": "Dark Mode",
    "primary_color": "Neon Green",
    "typography": "Clean sans‑serif"
  },
  "content": {
    "header": "Today's Activity",
    "cards": [
      {"title": "Running", "data": "5.2 km", "button": "Start"},
      {"title": "Calories", "data": "340 kcal"}
    ]
  },
  "constraints": "High fidelity, readable text, 9:16 aspect ratio"
}

```

### Infographic Template

Complex informational graphics use the same atomic structure with additional structural modules:

```json
{
  "type": "Infographic",
  "topic": "Urban Metabolism",
  "audience": "General Public",
  "structure": {
    "title_area": "城市生命系统图谱",
    "layout": "Isometric cutaway, 12 numbered panels",
    "modules": [
      {"title": "能源", "icon": "lightning", "text": "Power flows"},
      {"title": "水循环", "icon": "water_drop", "text": "Water flows"}
    ]
  },
  "style": {
    "aesthetic": "Scientific atlas",
    "colors": "Low saturation, color‑coded flows",
    "background": "Light paper texture"
  },
  "constraints": "No cyberpunk, no gibberish text, strict structural layout"
}

```

## Key Files in the Architecture

| File Path | Role |
|-----------|------|
| [`README.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/README.md) | Defines atomic schema concept and project vision |
| [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) | Complete library of plain-text and JSON templates |
| [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) | Central catalog of validated style tokens |
| [`agents/skills/gpt-image-2-style-library/SKILL.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/agents/skills/gpt-image-2-style-library/SKILL.md) | Agent skill definition for Claude Code and Codex integration |
| [`api/_lib/watcha.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/api/_lib/watcha.js) | Backend helper for API translation and constraint enforcement |
| [`api/_lib/supabase.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/api/_lib/supabase.js) | Data persistence layer for generated prompts |

## Agent Integration: Making Prompts Programmable

The [`SKILL.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/SKILL.md) file in `agents/skills/gpt-image-2-style-library/` exposes the architecture to AI coding agents. This enables:

- Automatic template selection based on user intent
- Style token validation without human lookup
- Batch prompt generation from structured data sources
- Version control integration for prompt histories

By treating prompts as code objects with defined schemas, the system allows agents to reason about, modify, and compose visual specifications using the same tools they apply to software development.

## Summary

- **Atomic schemas** in [`README.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/README.md) decompose prompts into five reusable categories: subjects, lighting, materials, layout, and visual details.
- **JSON templates** in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) provide machine-readable specifications for common output types, enabling agent-driven automation.
- **Style library** at [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) centralizes visual tokens for consistent, validated styling across the pipeline.
- **Five-stage pipeline** transforms human intent → atomic parts → structured JSON → resolved styles → API execution.
- **Agent integration** via [`SKILL.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/SKILL.md) makes prompts fully programmable and versionable as first-class code artifacts.

## Frequently Asked Questions

### What makes Prompt-as-Code different from traditional prompt engineering?

Traditional prompt engineering relies on prose refinement through trial and error. Prompt-as-Code treats prompts as structured data with typed fields, enabling programmatic manipulation, batch processing, and version control. The freestylefly/awesome-gpt-image-2 repository implements this through JSON schemas that separate content from presentation.

### Where is the style token validation logic located?

Token validation occurs against [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json), which serves as the single source of truth. This file is referenced by the Agent skill definition in [`agents/skills/gpt-image-2-style-library/SKILL.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/agents/skills/gpt-image-2-style-library/SKILL.md) and consumed by backend helpers in `api/_lib/` to ensure all style references resolve before API submission.

### Can I extend the architecture with custom templates?

Yes. The architecture in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) accepts new JSON templates provided they conform to the atomic schema structure. Custom templates must declare `type`, `subject`, and `layout` fields, with optional `style` and `constraints` objects. New style tokens require corresponding entries in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json).

### How does the backend enforce schema constraints?

The `api/_lib/` directory contains helper modules including [`watcha.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/watcha.js) and [`supabase.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/supabase.js) that validate incoming JSON payloads against the atomic schema before forwarding to the GPT-Image2 API. These modules reject malformed requests and resolve style tokens through lookups to the central style library.