Skip to content

Repository files navigation

AFrame

Auto-Generated, Data-Driven Frontend Framework

AFrame is a complete full-stack framework that generates production-ready React/MUI components and C# backend controllers directly from OpenAPI specifications. Build complete CRUD applications in minutes without writing UI code.

🎯 What is AFrame?

AFrame bridges the gap between your API specification and your application by:

  1. Parsing your OpenAPI 3.x spec
  2. Inferring component types and behaviors
  3. Generating React components, hooks, and configuration
  4. Enforcing backend API structure with C# controller interfaces

The result: A fully functional, themed, validated UI that stays in sync with your API.

✨ Features

  • πŸš€ Zero-Config Generation - Point at OpenAPI spec, get complete UI
  • 🎨 Zero CSS Required - Everything via MUI theme tokens
  • πŸ“Š Full CRUD Components - Cards, DataGrids, Forms, Search, Infinite Scroll
  • πŸ”— Smart Relations - Auto-detected from $ref, with modals and grids
  • βš™οΈ Highly Configurable - Override at global, entity, or component level
  • πŸͺ React Query Hooks - Built-in caching and state management
  • πŸ›‘οΈ Type Safe - Full TypeScript support throughout
  • πŸ”Œ Backend Enforcement - C# controller interfaces ensure API consistency
  • πŸ“š Complete Documentation - Astro-based docs site with examples

πŸ“¦ What's Included

Frontend Framework (/src)

  • OpenAPI parser
  • Code generator
  • Runtime components (Card, DataGrid, Search, etc.)
  • React Query hooks
  • Theming system
  • Configuration system

Backend Library (/backend)

  • Controller interface (IAFrameController)
  • Base controller implementation
  • Entity interface (IEntity)
  • Service interface (IEntityService)
  • Standard response formats
  • Example User and Role controllers

Demo Application (/demo)

  • Complete working example
  • User and Role management
  • Mock API with sample data
  • Multiple view types (Grid, Cards, Search)
  • Full CRUD operations

Documentation Site (/docs)

  • Getting started guide
  • Architecture overview
  • API inference rules
  • Configuration guide
  • Code examples
  • Deployment instructions

πŸš€ Quick Start

1. Install Dependencies

npm install

2. Run the Demo

npm run dev

Visit http://localhost:5173 to see the demo with User and Role management.

3. Generate Components from Your API

npm run generate -- -i your-api.yaml -o ./generated/aframe

4. Use in Your App

import { AFrameProvider } from 'aframe';
import { A } from './generated/aframe';

const config = {
  api: { baseUrl: 'https://api.example.com' },
  theme: { palette: { primary: { main: '#6366f1' } } },
};

function App() {
  return (
    <AFrameProvider config={config}>
      <A.User.DataGrid />
      <A.User.CreationCard />
    </AFrameProvider>
  );
}

πŸ“ Project Structure

aframe/
β”œβ”€β”€ src/                          # Frontend framework
β”‚   β”œβ”€β”€ cli/                      # Code generator CLI
β”‚   β”œβ”€β”€ parser/                   # OpenAPI parser
β”‚   β”œβ”€β”€ generator/                # Code generator
β”‚   β”œβ”€β”€ runtime/
β”‚   β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”œβ”€β”€ hooks/                # React Query hooks
β”‚   β”‚   └── context/              # Theme & config
β”‚   β”œβ”€β”€ types/                    # TypeScript types
β”‚   └── index.ts                  # Main exports
β”‚
β”œβ”€β”€ backend/                      # C# backend library
β”‚   β”œβ”€β”€ Core/
β”‚   β”‚   β”œβ”€β”€ IEntity.cs            # Base entity interface
β”‚   β”‚   β”œβ”€β”€ IEntityService.cs     # Service contract
β”‚   β”‚   └── ListResponse.cs       # Standard response
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”œβ”€β”€ IAFrameController.cs  # Controller interface
β”‚   β”‚   └── AFrameControllerBase.cs # Base implementation
β”‚   β”œβ”€β”€ Models/
β”‚   β”‚   β”œβ”€β”€ User.cs               # User entity & DTOs
β”‚   β”‚   └── Role.cs               # Role entity & DTOs
β”‚   β”œβ”€β”€ Examples/
β”‚   β”‚   β”œβ”€β”€ UserController.cs     # Example controller
β”‚   β”‚   └── RoleController.cs     # Example controller
β”‚   └── AFrame.Backend.csproj
β”‚
β”œβ”€β”€ demo/                         # React demo app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ generated/            # Generated components
β”‚   β”‚   β”œβ”€β”€ App.tsx               # Demo application
β”‚   β”‚   β”œβ”€β”€ main.tsx              # Entry point
β”‚   β”‚   └── mockApi.ts            # Mock API
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ docs/                         # Documentation site (Astro)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ layouts/Layout.astro  # Main layout
β”‚   β”‚   └── pages/
β”‚   β”‚       β”œβ”€β”€ index.astro       # Homepage
β”‚   β”‚       β”œβ”€β”€ examples.astro    # Code examples
β”‚   β”‚       └── docs/
β”‚   β”‚           β”œβ”€β”€ getting-started.astro
β”‚   β”‚           β”œβ”€β”€ how-it-works.astro
β”‚   β”‚           β”œβ”€β”€ frontend.astro
β”‚   β”‚           β”œβ”€β”€ backend.astro
β”‚   β”‚           β”œβ”€β”€ api-inference.astro
β”‚   β”‚           └── configuration.astro
β”‚   β”œβ”€β”€ astro.config.mjs
β”‚   └── package.json
β”‚
β”œβ”€β”€ package.json                  # Root dependencies
β”œβ”€β”€ tsconfig.json                 # TypeScript config
β”œβ”€β”€ vite.config.ts                # Vite config
β”œβ”€β”€ .gitignore
└── README.md                     # This file

πŸ”„ How It Works

The Three Layers

OpenAPI Spec
    ↓
[Parser] β†’ Extracts entities, fields, relations, operations
    ↓
[Generator] β†’ Emits React components and hooks
    ↓
React Components + Configuration

Inference Rules

AFrame intelligently infers how to render your data:

OpenAPI Component Example
string TextField firstName
string, format: email EmailField user@example.com
string, format: date DateField 2024-01-25
integer NumberField 42
boolean Switch true/false
string, enum Select active, pending
array of $ref RelationGrid List of roles

Operations

  • GET /resource β†’ DataGrid, InfiniteScroll, Search
  • GET /resource/{id} β†’ Card (view mode)
  • POST /resource β†’ CreationCard
  • PATCH /resource/{id} β†’ Card (edit mode)
  • DELETE /resource/{id} β†’ Delete button

πŸ’» Frontend Framework

Generated Components

Each entity gets these components:

<A.User.Card id="123" />              // View/edit single
<A.User.CreationCard />               // Create new
<A.User.DataGrid />                   // Paginated table
<A.User.Search />                     // Search & filter
<A.User.ListItem data={user} />       // List item
<A.User.InfiniteScroll />             // Infinite scroll
<A.User.Fields.Email />               // Individual field
<A.User.Relations.Roles.DataGrid />   // Relation grid

React Hooks

const { data, isLoading } = useEntity('User', '123');
const { data, isLoading } = useEntityList('User', { page: 1 });
const mutation = useCreateEntity('User');
const mutation = useUpdateEntity('User');
const mutation = useDeleteEntity('User');

Configuration

const config = {
  api: {
    baseUrl: 'https://api.example.com',
    headers: { 'Authorization': 'Bearer token' },
  },
  theme: {
    palette: {
      primary: { main: '#6366f1' },
      secondary: { main: '#ec4899' },
    },
  },
  Card: {
    // optional component-level settings
  },
  // optional entity specific settings
  entities: {
    User: {
      // optional settings to override globals
      props: {
        title: (e) => `${e.firstName} ${e.lastName}`,
        subtitle: 'email',
      },
      styles: {
        Card: { elevation: 2 },
        TextField: { size: 'small' },
      },
      theme: {
        palette: { primary: { main: '#4A6CF7' } },
      },
      fields: {
        email: {
          validation: (v) => v?.includes('@') ? undefined : 'Invalid',
        },
      },
    },
  },
};

πŸ›‘οΈ Backend Library (C#)

Core Interfaces

// All entities must implement IEntity
public interface IEntity
{
    string Id { get; set; }
    DateTime CreatedAt { get; set; }
    DateTime UpdatedAt { get; set; }
}

// All services must implement IEntityService
public interface IEntityService<TEntity, TCreateDto, TUpdateDto>
{
    Task<ListResponse<TEntity>> GetAllAsync(int page, int pageSize, string? search);
    Task<TEntity?> GetByIdAsync(string id);
    Task<TEntity> CreateAsync(TCreateDto dto);
    Task<TEntity> UpdateAsync(string id, TUpdateDto dto);
    Task DeleteAsync(string id);
    Task<bool> ExistsAsync(string id);
}

// All controllers must implement IAFrameController
public interface IAFrameController<TEntity, TCreateDto, TUpdateDto>
{
    Task<ActionResult> GetAll(int page, int pageSize, string? search);
    Task<ActionResult> GetById(string id);
    Task<ActionResult> Create(TCreateDto dto);
    Task<ActionResult> Update(string id, TUpdateDto dto);
    Task<ActionResult> Delete(string id);
}

Creating a Controller

[ApiController]
[Route("api/[controller]")]
public class UserController : AFrameControllerBase<User, CreateUserDto, UpdateUserDto>
{
    public UserController(IEntityService<User, CreateUserDto, UpdateUserDto> service)
        : base(service) { }
    
    // All CRUD endpoints automatically provided
}

API Endpoints

GET    /api/users                    # List with pagination
GET    /api/users/{id}               # Get single
POST   /api/users                    # Create
PATCH  /api/users/{id}               # Update
DELETE /api/users/{id}               # Delete

πŸ“š Documentation

Full documentation available in /docs:

cd docs
npm install
npm run dev

Visit http://localhost:3000 for:

  • Getting started guide
  • Architecture overview
  • API inference rules
  • Configuration options
  • Code examples
  • Deployment guides

🎨 Demo Application

The demo showcases a complete user management application:

npm run dev

Features:

  • User and Role management
  • Multiple view types (Grid, Cards, Search)
  • Full CRUD operations
  • Relation handling (Users ↔ Roles)
  • Mock API with sample data
  • Responsive Material Design UI

πŸ”§ Commands

# Install dependencies
npm install

# Run demo app
npm run dev

# Generate components from OpenAPI
npm run generate -- -i api.yaml -o ./generated

# Build frontend
npm run build

# Build documentation
cd docs && npm run build

# Deploy documentation
cd docs && npm run build && netlify deploy --prod --dir=dist

πŸš€ Deployment

Frontend

  • Vite-based React app
  • Deploy to Netlify, Vercel, AWS S3, etc.

Backend

  • ASP.NET Core 8.0+
  • Deploy to Azure, AWS, Docker, etc.

Documentation

  • Static Astro site
  • Deploy to Netlify, Vercel, GitHub Pages, etc.

See /docs/DEPLOYMENT.md for detailed instructions.

πŸ“– Example Usage

Complete User Management App

import React, { useState } from 'react';
import { AFrameProvider } from 'aframe';
import { A } from './generated/aframe';

function App() {
  const [selectedId, setSelectedId] = useState(null);

  return (
    <AFrameProvider config={config}>
      <A.User.Search />
      <A.User.DataGrid onRowClick={(row) => setSelectedId(row.id)} />
      {selectedId && <A.User.Card id={selectedId} />}
    </AFrameProvider>
  );
}

Backend Controller

[ApiController]
[Route("api/[controller]")]
public class UserController : AFrameControllerBase<User, CreateUserDto, UpdateUserDto>
{
    public UserController(IEntityService<User, CreateUserDto, UpdateUserDto> service)
        : base(service) { }
}

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“ License

MIT

πŸ”— Links

❓ FAQ

Q: Do I need to write CSS? A: No! Everything is controlled through MUI theme tokens.

Q: Can I customize components? A: Yes! Override at global, entity, or component level.

Q: Does it support TypeScript? A: Yes! Full TypeScript support throughout.

Q: Can I use it with my existing API? A: Yes! Just create an OpenAPI spec for your API.

Q: What about relations between entities? A: Automatically detected from $ref in your OpenAPI spec.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages