Katatan Logo
KATATAN
Blog
Semantic Coding Theory: Maximizing Code Quality in AI-Driven Development

Semantic Coding Theory: Maximizing Code Quality in AI-Driven Development

Semantic Coding Theory is a design philosophy for the AI-driven development era — embedding meaning into code structure, naming, types, and tests rather than documentation. Learn how to build a codebase that AI agents can explore, understand, and change with minimal friction.

conceptbest-practiceai-agent

How AI-Driven Development Redefines Code Quality

As AI-driven development takes hold, the very definition of code quality is being challenged at its foundation.

Traditional coding standards were built around human readability. Avoid overly short variable names, write thorough comments, maintain design documents — all of it was an investment in making code understandable to people.

Today, AI agents are the primary consumers of code. They read it, understand it, modify it, and write tests for it. As AI becomes the main actor in development, the quality attributes we optimize for must change too.

The new criteria are:

  • Easy for AI to understand
  • Easy for AI to explore
  • Easy for AI to modify
  • Easy for AI to reconstruct specifications from

Semantic Coding Theory is a design philosophy built to satisfy all four.

From Documentation-Driven to Semantic Code-Driven

The core idea of Semantic Coding Theory can be stated simply:

Embed the system's meaning (semantics) into the code structure itself — not into documentation.

In traditional development, meaning flowed like this:

README → Design Docs → Spec Docs → Code

AI agents prioritize code over documentation. No matter how carefully written a specification document is, the AI agent reads the code first. So meaning should live in the code, not in documents that sit beside it.

In AI-driven development, the information flow reverses:

Code Search → Type Definitions → Tests → Implementation

This is Semantic Code Driven Development — a shift away from Documentation Driven Development that forms the foundation of code quality in the AI era.

The Five Core Principles

Principle 1: Embed Meaning in Names, Not Comments

Comments rot. Implementations change while comments don't. AI agents trust names over comments.

// Bad: meaning compensated by a comment
// Creates a user
class Service {}

// Good: the name carries the meaning
class CreateUserUseCase {}

When class names, function names, and variable names are self-explanatory, comments become unnecessary.

Principle 2: Embed Meaning in Types, Not Prose

Writing "status is a number from 1 to 5" in a document gives AI no way to connect that constraint to the code. Define it as a type, and the AI understands the specification by reading the type definition alone.

// Bad: spec described in a comment
// status is 1–5
status: number

// Good: the type expresses the specification
type Status = 1 | 2 | 3 | 4 | 5

TypeScript's union types and literal types exist precisely for this purpose. The more you lean into the type system, the denser the meaning in your codebase.

Principle 3: Embed Meaning in Directory Structure, Not Design Docs

Directory structure is a projection of your architecture. Organizing by feature rather than by technical layer dramatically improves AI exploration efficiency.

# Bad: organized by technical layer
controllers/
models/
repositories/

# Good: organized by feature
features/
 ├─ project/
 ├─ billing/
 └─ user/

When a task is "modify the project feature," everything relevant lives under features/project/. The AI reads fewer files and consumes less context.

Principle 4: Embed Meaning in Tests, Not Spec Documents

Tests are the most reliable documentation that exists. If a test passes, the code behaves exactly as described in that test. No spec document can make the same guarantee.

// Bad: specification lives only in a document
// "An expired subscription cannot access premium features"

// Good: the test expresses the specification
it("expired subscription cannot access premium feature", () => {
  // ...
})

When test names read like specification sentences, AI agents can understand system behavior by reading the test suite alone.

Principle 5: Embed Meaning in Dependencies, Not Operational Rules

"No reverse references — see the Wiki" is among the most fragile rules in software. Nobody reads it, nobody enforces it, and AI agents have no idea it exists.

Enforce architectural constraints through linter rules instead.

UI
 ↓
UseCase
 ↓
Repository

When dependency direction is enforced by a linter, the rule holds without a Wiki page. Code generated by AI agents will comply with the same rule automatically.

Three Key Concepts for the AI Era

Semantic Coding Theory introduces three evaluation axes for assessing a codebase's AI-readiness.

Semantic Density

The density of meaning information carried by code.

// High density: names communicate meaning on their own
CreateProjectUseCase
ProjectRepository
ProjectCreatedEvent

// Low density: too generic to mean anything
Manager
Handler
Processor

Names like Manager or Handler can be applied anywhere, which means they communicate nothing specific. AI agents learn nothing from them and cannot use them as navigation anchors.

Discoverability

How easily AI can reach the code relevant to a given task.

# High: features are clearly separated
project/
 ├─ create/
 ├─ update/
 └─ delete/

# Low: everything packed into one file
ProjectViewModel (2,000 lines)

Reading a 2,000-line file costs significant tokens. Splitting features into focused files allows the AI to read only what it needs.

Semantic Recoverability

The degree to which AI can reconstruct the domain model from the codebase alone — without external documentation.

In the ideal state, an AI reading only the code can infer:

  • What use cases exist
  • Who has which permissions
  • What events are emitted
  • How the domain model is structured

High Semantic Recoverability means a new AI agent can be dropped into a project and begin contributing with minimal context onboarding.

Architecture Principles for the AI Era

Translating Semantic Coding Theory into concrete architecture produces a clear set of guidelines.

Minimize File Responsibility

One file, one responsibility. Aim for 500 lines or fewer. AI context windows are finite — smaller files mean the AI reads only what it needs and wastes nothing.

UseCase-Centric Design

// Recommended: the operation is explicit
CreateProjectUseCase
DeleteProjectUseCase
ArchiveProjectUseCase

// Not recommended: intent is unclear
ProjectManager
ProjectService
ProjectModel

Design UseCases at the same granularity as API endpoints. Align feature name, file name, test name, and domain term so they all say the same thing.

Stateless Business Logic

class CreateProjectUseCase {
  execute(input: CreateProjectInput): Promise<Project> {
    // Pure execution logic — no internal state
  }
}

UseCases hold no state. State belongs in Stores, State objects, Caches, and Repositories. This simple rule lets AI understand, test, and modify a UseCase in isolation.

Rethinking MVVM

MVVM (Model-View-ViewModel) is widely adopted in frontend development, but it deserves scrutiny through the lens of the AI era.

The "bloated ViewModel" problem is endemic to MVVM — a single ViewModel accumulates:

  • API calls
  • Validation logic
  • State management
  • Navigation
  • Permission checks

Meaning is scattered across a wide surface, forcing AI to read a large scope to locate any specific responsibility.

The ideal structure for the AI era is:

View
 ↓
ViewModel  (UI state only)
 ↓
UseCase    (business logic)
 ↓
Repository (data access)
 ↓
Store      (state management)

ViewModel focuses solely on UI state. Business logic is delegated to UseCases.

Treating Software Structure as an API

One of Semantic Coding Theory's most useful mental models is designing internal structure at the same granularity as external APIs.

External API              Internal Structure
POST /projects       ←→   CreateProjectUseCase
DELETE /projects/{id} ←→  DeleteProjectUseCase

When this correspondence holds, reading the code tells you the API surface, and knowing the API surface tells you where to find the code. This is the most explorable form a codebase can take for AI agents.

Optimizing for Exploration Efficiency

The target of optimization in software development has evolved over time.

Traditional  → Optimize runtime performance
Recent       → Optimize maintenance efficiency
AI era       → Optimize exploration efficiency

In AI-driven development, the most expensive process is the one where AI collects the right context. The metrics that matter now are:

  • Number of code searches required
  • Number of files read
  • Tokens consumed
  • Context window size used
  • Number of inference calls

Practicing Semantic Coding Theory reduces all of these.

The Future: Code Becomes the Specification

Today's workflow looks like this:

Specification → Implementation

The future workflow looks like this:

Implementation → Specification generated

In a codebase with high Semantic Recoverability, AI can read the code and auto-generate specifications. The chronic problem of stale documentation is structurally eliminated.


Summary: Defining Semantic Coding Theory

Semantic Coding Theory is:

A design philosophy that enables both AI and humans to easily reconstruct a system's domain model by embedding meaning into code structure, naming, types, dependencies, and tests — rather than into documentation.

Practicing the five principles, measuring against the three evaluation axes, and applying the concrete architecture guidelines produces a codebase that is understandable and changeable for both AI agents and human developers alike.

Getting the most out of AI-driven development requires a codebase that AI can explore effectively. Semantic Coding Theory provides a systematic approach to building exactly that.

Questions or feedback? Reach us at contact@katatan.com.