AIMFP: AI Modular Functional Procedural Programming

A language-agnostic programming paradigm designed for AI-generated and AI-maintained codebases
Table of Contents
What is AIMFP?
AIMFP (AI Modular Functional Procedural) is a programming paradigm that combines:
- Pure functional programming principles (referential transparency, immutability, composability)
- Procedural execution patterns (explicit sequencing, no hidden state)
- Database-driven project management (persistent state, instant context retrieval)
- Directive-based AI guidance (deterministic workflows, automated compliance)
Two Ways to Use AIMFP
Use Case 1: Regular Software Development
- Build applications (web apps, libraries, CLI tools, etc.)
- AIMFP enforces FP compliance and manages your project
- You write code, AI assists with FP standards and project tracking
- Example: Building a web server, calculator library, data processor
Use Case 2: Custom Directive Automation
- Define automation rules (home automation, cloud management, workflows)
- AIMFP generates and manages the automation codebase for you
- You write directive definitions (YAML/JSON/TXT), AI generates the implementation
- The project's code IS the automation code generated from your directives
- Example: Smart home control system, AWS infrastructure manager, workflow automator
Key Principle: One AIMFP instance per project directory. You would NOT mix a web app with home automation directives. Run separate instances for separate purposes.
Why AIMFP?
Traditional programming paradigms were designed for humans. AIMFP is optimized for AI-human collaboration:
| Challenge | Traditional Approach | AIMFP Solution |
|---|
| Context Loss | AI forgets between sessions | Database-driven persistent state |
| OOP Complexity | Classes, inheritance, polymorphism | Pure functions, explicit data structures |
| Infinite Development | Projects never "complete" | Finite completion paths with milestones |
| Code Reasoning | Parse source code repeatedly | Pre-indexed functions, dependencies, interactions |
| Inconsistent Standards | Style guides, linters, reviews | Immutable directives enforcing compliance |
Core Principles
1. Functional-Procedural Hybrid
# β
AIMFP-Compliant
def calculate_total(items: List[Item]) -> float:
"""Pure function: deterministic, no side effects"""
return reduce(lambda acc, item: acc + item.price, items, 0.0)
# β Not AIMFP-Compliant
class Calculator:
def __init__(self):
self.total = 0 # Hidden state
def add_item(self, item):
self.total += item.price # Mutation
2. Database-Indexed Logic
Every function, file, and dependency is tracked in SQLite. AI accesses this data through helper tools β not raw SQL:
AI calls: get_functions_by_file(file_id)
β Returns: all functions in that file with name, purpose, parameters, returns
No source code reparsing required. Instant context retrieval across sessions.
3. AI-Readable Code
- Flat structure: No deep inheritance hierarchies
- Explicit dependencies: All parameters passed explicitly
- Pure functions: Same inputs β same outputs
- Metadata annotations: Machine-readable function headers
4. Finite Completion Paths
Project: MatrixCalculator
βββ Completion Path (3 stages)
β βββ 1. Setup (completed)
β βββ 2. Core Development (in progress)
β β βββ Milestone: Matrix Operations
β β β βββ Task: Implement multiply
β β β βββ Task: Implement transpose
β β β βββ Task: Add validation
β β βββ Milestone: Vector Operations
β βββ 3. Finalization (pending)
5. Language-Agnostic
AIMFP works with Python, JavaScript, TypeScript, Rust, Go, and more. FP directives adapt to language-specific syntax while maintaining universal standards.
Architecture Overview
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Assistant (Claude, GPT-4, etc.) β
β - Receives natural language commands β
β - Follows directives (FP baseline + project mgmt) β
β - Calls MCP tools to read/write databases β
β - Generates FP-compliant code β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β MCP Protocol (JSON-RPC over stdio)
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β MCP Server β
β - Exposes helper tools via JSON-RPC β
β - Manages four-database connections β
β - Provides CRUD helpers for all databases β
β - No business logic β AI makes all decisions β
βββββ¬βββββββββββββββββββββ¬ββββββββββββββββββββββββββ¬βββ
β β β
βββββΌβββββββββββββββ βββββΌβββββββββββββββββ βββββββΌββββββββββββββββββ ββββββββΌβββββββββββββββββ
β aimfp_core.db β β project.db β β user_preferences.db β β user_directives.db β
β (Global, β β (Per-Project, β β (Per-Project, β β (Per-Project, β
β Read-Only) β β Mutable) β β Mutable) β β Optional) β
β β β β β β β β
β - FP directives β β - Project metadata β β - Directive prefs β β - User directives β
β - Project mgmt β β - Files & funcs β β - User settings β β - Execution stats β
β - User prefs β β - Task hierarchy β β - AI learning log β β - Dependencies β
β - User systems β β - Themes & flows β β - Tracking features β β - Generated code refs β
β - Helper defs β β - Completion path β β (All opt-in) β β - Source file trackingβ
β - Directive flow β β - Runtime notes β β β β (Logs in files) β
ββββββββββββββββββββ ββββββββββββββββββββββ βββββββββββββββββββββββββ βββββββββββββββββββββββββ
Use Case 2 adds a second path that never touches the MCP server. Your
automation has to run when no AI session is open, so it imports AIMFP as a plain
library instead:
ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
β cron / systemd / your daemon β β AI Assistant (a session) β
β runs forever; AIMFP does not β β present only when you are β
βββββββββββββββββ¬βββββββββββββββ βββββββββββββββββ¬βββββββββββββββ
β starts β MCP
βββββββββββββββββΌβββββββββββββββ βββββββββββββββββΌβββββββββββββββ
β runner.py (YOUR project) β β MCP Server β
β generated by AIMFP, owned β β β
β and editable by you β β check_directive_health β
β β β get_directive_execution_statsβ
β import aimfp.hooks ββββββββββΌββ a β get_recent_directive_errors β
β get_due_directives(...) β library β
β run_directive(...) β call, βββββββββββββββββ¬βββββββββββββββ
βββββββββββββββββ¬βββββββββββββββ not RPC β reads
β writes β
ββββββββββββββΊ user_directives.db ββββββ
+ .aimfp-project/logs/
The runner writes; the AI reads it back later. AIMFP itself is inert in
between β it has no timer and starts nothing.
Database Architecture
aimfp_core.db (Global, Read-Only)
Location: Within MCP server installation directory (user-defined location, configured in AI client)
Purpose: Immutable knowledge base containing all AIMFP standards, directives, and helper definitions.
Key Tables:
directives: All FP, project, and user preference directives (workflows, keywords, thresholds)
helper_functions: Database, file, Git, and FP utilities organized across multiple registry files
directive_helpers: Many-to-many junction table mapping directives to their helper functions with execution metadata
categories: Directive groupings (purity, immutability, task management, etc.)
directive_flow: Status-driven directive navigation and routing
Helper-Directive Relationship (New in v1.4):
- One directive can use many helpers, one helper can serve many directives
- Junction table stores: execution context, sequence order, parameter mappings
- Enables flexible helper reuse and clear execution flow
- Defined in
directive_helpers junction table in aimfp_core.db
Helper Classification:
- Tool: All helpers are exposed as MCP tools (AI calls directly via MCP)
- Sub-helper (
is_sub_helper = TRUE): Internal utility called by other helpers only (not exposed to AI)