When I started using AI-powered coding assistants like Claude Code in my daily workflow, I quickly realized that the quality of AI output is directly proportional to how well your project is structured. A messy codebase confuses AI just as much as it confuses developers. This led me to develop what I call "Smart Contracting" — a disciplined folder architecture that acts as a readable contract between you and your AI assistant.
The Problem: AI Drowning in Chaos
In a typical enterprise project, files are scattered across dozens of folders with inconsistent naming. When you ask an AI agent to "add a new API endpoint for leave requests," it has to search through hundreds of files to understand patterns. This wastes tokens, time, and produces inconsistent results.
I noticed that 40% of my prompts were just giving the AI context about where things live. That is wasted effort.
The Solution: Folder Structure as a Contract
I restructured the IQCheckPoint project into a predictable, layered architecture:
• /src/api/controllers — One controller per domain entity
• /src/api/services — Business logic, one service per controller
• /src/api/repositories — Database access layer
• /src/api/models — Request/Response DTOs
• /src/api/entities — Database entity models
• /src/shared/utils — Shared helpers
• /src/shared/middleware — Auth, logging, error handling
Each layer has a clear read/write permission boundary. Controllers only call services. Services only call repositories. No layer skips another.
Read & Write Permissions for AI
The key insight was defining explicit permissions in CLAUDE.md:
• Controllers: READ services, WRITE HTTP responses
• Services: READ/WRITE repositories, READ utils
• Repositories: READ/WRITE database via Entity Framework
• Middleware: READ requests, WRITE modified pipeline
When the AI knows these boundaries, it generates code that respects the architecture automatically. No more service logic leaking into controllers or direct database calls from API endpoints.
Results & Impact
After implementing Smart Contracting:
• AI-generated code followed patterns correctly 90%+ of the time
• Code review rejections dropped by 60%
• New feature development cycles shortened by roughly half
• Onboarding new developers became faster — the structure is self-documenting
The folder structure became a shared language between human developers and AI assistants.
Smart Contracting — Layered Architecture
ControllersREAD Services → WRITE HTTP Response
ServicesREAD/WRITE Repos → READ Utils
RepositoriesREAD/WRITE Database (EF Core)
DatabasePostgreSQL / SQL Server