Complete Spec File Structure

Here's a complete example of a SED specification file for user authentication. Note the YAML header at the top and the detailed sections below.

---
name: my-app-user-authentication
version: 1.0.0
description: User authentication specification for My App
author: Your Name
email: [email protected]
license: MIT
step: 20
dependencies: my-app/database/specs[users-schema.md], my-app/security/specs[encryption.md#password]
---

## Overview
User authentication system supporting email/password and OAuth 2.0 (Google, Facebook).

## Requirements

### Libraries
- bcrypt ^5.1.0
- jsonwebtoken ^9.0.0
- passport ^0.6.0

### Installation
```bash
npm install bcrypt jsonwebtoken passport
```

## Workflow
1. User submits credentials
2. Validate input format
3. Check user existence in database
4. Verify password hash
5. Generate JWT token
6. Return token to client

## Details

### Function: authenticateUser

**Parameters:**
- email: string (required, valid email format)
- password: string (required, minimum 8 characters)

**Returns:**
- Promise<{ token: string, user: UserProfile }>

**Implementation:**
```typescript
export async function authenticateUser(
  email: string,
  password: string
): Promise<{ token: string; user: UserProfile }> {
  // Validate email format
  if (!isValidEmail(email)) {
    throw new ValidationError('Invalid email format');
  }

  // Query database for user
  const user = await db.users.findOne({ email });
  if (!user) {
    throw new AuthError('Invalid credentials');
  }

  // Verify password using bcrypt
  const isValid = await bcrypt.compare(password, user.passwordHash);
  if (!isValid) {
    throw new AuthError('Invalid credentials');
  }

  // Generate JWT token
  const token = jwt.sign(
    { userId: user.id, email: user.email },
    process.env.JWT_SECRET,
    { expiresIn: '24h' }
  );

  return { token, user: user.profile };
}
```

### Error Handling
- **ValidationError:** Invalid email format or password requirements not met
- **AuthError:** User not found or password mismatch
- **DatabaseError:** Database connection or query failure

### Testing Requirements
```typescript
describe('authenticateUser', () => {
  it('should return token for valid credentials', async () => {
    const result = await authenticateUser('[email protected]', 'Password123!');
    expect(result.token).toBeDefined();
    expect(result.user.email).toBe('[email protected]');
  });

  it('should throw ValidationError for invalid email', async () => {
    await expect(
      authenticateUser('invalid-email', 'Password123!')
    ).rejects.toThrow(ValidationError);
  });

  it('should throw AuthError for wrong password', async () => {
    await expect(
      authenticateUser('[email protected]', 'WrongPassword')
    ).rejects.toThrow(AuthError);
  });
});
```

YAML Header Fields Explained

Every SED specification file begins with a YAML header containing metadata and configuration.

Field Description Example
name Unique identifier for the specification my-app-user-authentication
version Semantic version of the specification 1.0.0
description Brief description of the specification User authentication system
author Specification author's name Your Name
email Author's contact email [email protected]
license License type (MIT, GPL, SED License, etc.) MIT
step Execution order (lower numbers first) 20
dependencies Other specs required for this one my-app/database/specs

Types of Specifications

SED specifications can cover different aspects of your project:

Database Specifications

Includes:

  • DBMS version and edition
  • Table structures with exact field types
  • Indexes and foreign key constraints
  • Migration procedures
  • Backup and recovery procedures

Example: my-app-setup-database.md

API Specifications

Includes:

  • Complete route definitions
  • Request/response schemas
  • Authentication and authorization
  • Error codes and messages
  • Rate limiting and caching

Example: my-app-api-endpoints.md

UI/UX Specifications

Includes:

  • Component structures and props
  • Exact colors, fonts, and spacing
  • Responsive breakpoints
  • User flows and navigation
  • Accessibility requirements

Example: my-app-ui-components.md

Testing Specifications

Includes:

  • Unit test scenarios and assertions
  • Integration test workflows
  • E2E test user journeys
  • Performance benchmarks
  • Coverage requirements (≥80%)

Example: my-app-testing-plan.md

Real-World Use Cases

Challenge: Complex features like user profiles, posts, comments, likes, notifications, and real-time chat.

SED Approach:

  • Create 100+ storyline items covering all user journeys
  • Write detailed specifications for each feature module
  • Define database schemas with complete relationships
  • Specify API endpoints with exact request/response formats
  • Document UI components with pixel-perfect designs
  • Include complete test coverage for all scenarios

Result: AI implements all features precisely as specified, with predictable behavior and zero interpretation errors.

Challenge: Payment processing, inventory management, order tracking, and email notifications with strict security requirements.

SED Approach:

  • Specify exact payment gateway APIs (Stripe, PayPal)
  • Define complete order state machine with all transitions
  • Document security measures (encryption, PCI compliance)
  • Specify error handling for payment failures
  • Include rollback procedures for failed transactions

Result: Secure, compliant payment system with predictable error handling and complete auditability.

Challenge: Supporting 10+ languages with locale-specific formatting, RTL support, and culturally appropriate content.

SED Approach:

  • Create complete translation dictionaries for all languages
  • Specify locale-specific date, number, and currency formats
  • Define RTL layout adjustments for Arabic and Hebrew
  • Document pluralization rules for each language
  • Include context-specific translations for ambiguous terms

Result: Consistent multilingual experience with proper localization across all supported languages.

Using Dependencies

Specifications can reference other specifications to promote reusability. Use the dependencies field in the YAML header to link related specs.

---
name: my-app-user-profile
version: 1.0.0
description: User profile management
dependencies: my-app/database/specs[users-schema.md],
              *my-app/auth/specs[authentication.md],
              **https://cdn.example.com/shared/specs[validation.md]
---

Priority System:

  • No asterisk: Normal priority (default)
  • One asterisk (*): Priority level 1
  • Two asterisks (**): Priority level 2 (highest)

When multiple specs contain conflicting information, higher priority specs override lower priority ones.

Ready to Start?

Now that you've seen examples of SED specifications, you're ready to create your own.

Quick Start Commands

# Initialize your project
npx spec init

# Edit generated spec files in ./specs directory
# Follow SED principles to ensure completeness

# Validate your specifications (coming soon)
npx spec doctor

# Check specification score (coming soon)
npx spec score specs/my-spec.md