Platform Architecture
APSO is a code generation platform that produces production-ready backend applications from a declarative schema.
System Overview
Core Components
Schema Parser
The schema parser reads and validates .apsorc files:
- JSON Parsing - Load and parse the configuration file
- Schema Validation - Validate against the APSO schema specification
- Reference Resolution - Resolve entity and field references
- Relationship Mapping - Build the relationship graph
Code Generator
The code generator transforms schema into code:
Template Types:
- Entity templates (ORM models)
- Controller templates (API endpoints)
- Service templates (business logic)
- DTO templates (data transfer objects)
- Module templates (framework wiring)
Output Structure
Generated code follows a consistent structure:
generated-backend/
βββ src/
β βββ entities/ # ORM entity definitions
β βββ modules/ # Feature modules
β β βββ {entity}/
β β βββ controller # HTTP handlers
β β βββ service # Business logic
β β βββ dto/ # Request/response schemas
β βββ common/ # Shared utilities
β βββ extensions/ # Your custom code
β βββ main.ts # Application entry point
βββ migrations/ # Database migrations
βββ test/ # Test files
βββ .apsorc # Source schemaData Flow
Request Lifecycle
Multi-Tenancy Flow
Code Generation Pipeline
1. Schema Ingestion
// Input: .apsorc
{
"entities": [
{
"name": "Project",
"fields": [
{ "name": "name", "type": "string", "required": true }
]
}
]
}2. AST Generation
// Intermediate representation
{
entities: [{
name: 'Project',
tableName: 'projects',
fields: [{
name: 'name',
type: 'string',
tsType: 'string',
sqlType: 'varchar(255)',
required: true,
validators: ['IsNotEmpty', 'MaxLength(255)']
}]
}]
}3. Template Application
// Output: project.entity.ts
@Entity('projects')
export class Project {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ nullable: false })
name: string;
}Extension Points
Pre-Generation Hooks
Modify the schema before code generation:
// hooks/pre-generate.ts
export function beforeGenerate(schema: Schema): Schema {
// Add audit fields to all entities
return addAuditFields(schema);
}Post-Generation Hooks
Process generated files:
// hooks/post-generate.ts
export function afterGenerate(files: GeneratedFile[]): void {
// Run prettier on all files
files.forEach(file => prettier.format(file));
}Template Overrides
Override specific templates:
templates/
βββ entity.hbs # Custom entity template
βββ controller.hbs # Custom controller templatePerformance Characteristics
| Metric | Typical Value |
|---|---|
| Schema parsing | < 50ms |
| Code generation | < 2s for 50 entities |
| Hot reload | < 500ms |
| API response (simple) | < 20ms |
| API response (with joins) | < 100ms |
Related
Last updated on