Skip to content

AppML Model — Defining Your Application Data Structure in XML

DodaTech Updated 2026-06-28 5 min read

In this tutorial, you will learn about AppML Model. We cover key concepts, practical examples, and best practices to help you master this topic.

The AppML model is the core of any AppML application. It is an XML file that describes your data structure, sources, and validation rules, and the AppML runtime uses it to generate the complete application.

What You'll Learn

You will write AppML model files from scratch, defining data sources, tables, fields with types, relationships, and validation constraints.

Why It Matters

The model is the single source of truth for your application. Every view, form, and data operation derives from the model. A well-designed model eliminates the need for separate database schemas, API documentation, and form validation code.

Real-World Use

The Durga Antivirus Pro team uses an AppML model to manage threat definitions. The model defines fields for threat name, signature hash, severity level, and affected systems, and the generated admin interface lets analysts add and update threats in real time.

flowchart LR
    A[Model XML] --> B[Table Definitions]
    A --> C[Field Definitions]
    A --> D[Relationships]
    A --> E[Validation Rules]
    B --> F[Database Schema]
    C --> G[Form Fields]
    D --> H[Join Queries]
    E --> I[Input Validation]
    style A fill:#1e293b,color:#fff

Model Structure

Every AppML model has a root <appml> element containing a <datasource> section that defines where the data lives and what tables to use.

<appml>
  <datasource type="sqlite">
    <table name="employees">
      <field name="id" type="integer" key="true" autoincrement="true"/>
      <field name="name" type="string" required="true"/>
      <field name="email" type="string" required="true" unique="true"/>
      <field name="salary" type="decimal"/>
      <field name="department" type="string"/>
      <field name="hired_date" type="date"/>
    </table>
  </datasource>
</appml>

Expected output: AppML generates a complete data entry screen for employees with text inputs, validation, and a unique email constraint.

Field Types

AppML supports a variety of field types that map to both database column types and HTML input types.

String fields render as text inputs. Integer and decimal fields render as number inputs with appropriate validation. Date fields render as date pickers. Boolean fields render as checkboxes.

<field name="is_active" type="boolean" default="true"/>
<field name="rating" type="integer" min="1" max="5"/>
<field name="description" type="text"/>
<field name="start_date" type="date"/>
<field name="price" type="decimal" precision="10" scale="2"/>

Expected output: Each field renders as the appropriate HTML input type with built-in browser validation for numbers, dates, and ranges.

Relationships Between Tables

AppML supports foreign key relationships that create dropdown selectors and join queries automatically.

<datasource type="sqlite">
  <table name="departments">
    <field name="id" type="integer" key="true"/>
    <field name="name" type="string"/>
  </table>
  <table name="employees">
    <field name="id" type="integer" key="true"/>
    <field name="name" type="string"/>
    <field name="department_id" type="integer">
      <relationship table="departments" field="id"/>
    </field>
  </table>
</datasource>

Expected output: The employees form shows a dropdown for department name instead of a text field for department ID. The list view displays the department name rather than the ID.

Validation Rules

Define validation constraints directly in the model so AppML enforces them on both the client and server.

<field name="age" type="integer" min="18" max="120"/>
<field name="email" type="string" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"/>
<field name="zip_code" type="string" minlength="5" maxlength="10"/>

Expected output: The form rejects invalid email formats, ages outside the 18-120 range, and zip codes that do not match the length requirements.

Common Mistakes

  1. Omitting the key field: Every table must have at least one field with key="true". Without it, AppML cannot identify records for update and delete operations.

  2. Using inconsistent field types across related tables: The foreign key field type must match the primary key field type. A string key paired with an integer foreign key causes type mismatch errors.

  3. Forgetting to set autoincrement for integer keys: Without autoincrement="true", you must provide ID values manually in every insert operation.

  4. Overusing text fields when specific types exist: Use boolean, date, decimal, and integer types instead of string for everything. Specific types enable proper validation and formatting.

  5. Not using unique constraints on natural identifiers: Fields like email, username, or SKU should be marked unique="true" to prevent duplicate entries.

Practice Questions

  1. What is the root element of every AppML model?

The <appml> element. All model definitions are children of this root.

  1. How do you define a foreign key relationship in AppML?

Use the <relationship> element inside the field definition, specifying the target table and field.

  1. What attribute makes a field a required input?

required="true". This generates a required attribute on the HTML input and server-side validation.

  1. Which field type would you use for a long-form text entry?

The text type renders as a textarea instead of a single-line input.

  1. What happens if you define a field with unique="true" and a duplicate value is entered?

AppML rejects the duplicate with a validation error message and prevents the insert or update.

Challenge

Design an AppML model for a library management system with three tables: books, authors, and members. Define proper relationships between them and include validation constraints for ISBN format and member email.

Frequently Asked Questions

Can I define multiple datasources in one model?

Yes. AppML supports multiple <datasource> elements, each pointing to different databases or file sources. Tables from different datasources can be used in the same application.

Does AppML support composite primary keys?

Yes. Define multiple fields with key="true" to create a Composite primary key. AppML uses the combination for record identification.

How does AppML handle default values?

Use the default attribute on a field definition. AppML uses this value when creating new records if the user does not provide a value.

Can I use calculated fields in AppML models?

AppML does not natively support calculated fields in the model. Computed values should be handled in the database as views or generated columns.

What happens if I change the model after data already exists?

AppML does not automatically migrate existing data. Add new fields with default values or null allowed. Renaming or removing fields requires manual database Migration.

Mini Project

Create an AppML model for a task management application with tables for projects, tasks, and users. Include field validation, a foreign key from tasks to projects, and a status field with allowed values.

What's Next

Continue to Data Controllers to learn how AppML manages data operations like create, read, update, and delete.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro