<!-- CANONICAL ORIGIN: /home/j-5/CANONICAL_ORIGIN.md -->
<!-- Zero interpretation drift. Scope: all .md, .json, every node, all ancestors, all depths. -->
<!-- Standard: No added, removed, or altered meaning at any level. -->

---
title: The Complete $0/Month AI Stack — Technical Architecture Guide
date: 2026-05-04
author: Jay Drake
slug: complete-zero-ai-stack
---

# The Complete $0/Month AI Stack — Technical Architecture Guide

This is the exact infrastructure I use to run Drake Enterprise. Total monthly cost: $0. Hardware cost: $0 (used laptop already owned).

## Overview

| Component | Technology | Cost |
|-----------|-----------|------|
| LLM Inference | Ollama + local models | $0 |
| Orchestration | Python daemons | $0 |
| Database | SQLite | $0 |
| Web Server | Flask + WSGI | $0 |
| Email | SMTP (Gmail app password) | $0 |
| Tunnel | Cloudflared quick tunnel | $0 |
| Dashboard | Custom Flask app | $0 |
| Monitoring | Self-built health checks | $0 |

## Hardware

- **Machine:** Used ThinkPad T480
- **RAM:** 32GB DDR4
- **Storage:** 500GB NVMe SSD
- **OS:** Ubuntu 22.04 LTS
- **GPU:** None (CPU-only inference)

## LLM Layer

### Ollama Setup

```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

# Pull models
ollama pull qwen2.5:7b
ollama pull llama3.2:3b
ollama pull deepseek-coder:6.7b

# Start daemon
ollama serve
```

### Model Roles

| Model | Parameters | Speed | Role |
|-------|-----------|-------|------|
| qwen2.5:7b | 7B | 40 tok/s | Content generation, blog posts, emails |
| llama3.2:3b | 3B | 80 tok/s | Triage, classification, routing |
| deepseek-coder:6.7b | 6.7B | 25 tok/s | Code review, refactoring |

### Custom Modelfiles

Each model has a custom Modelfile with system prompts optimized for its role:

```dockerfile
FROM qwen2.5:7b
SYSTEM You are a content strategist for Drake Enterprise. Write in Jay Drake's voice: direct, poetic, no filler. Love-first framework: every piece must increase reader autonomy.
PARAMETER temperature 0.7
PARAMETER top_p 0.9
```

## Orchestration Layer

### Daemon Architecture

Each daemon is a Python script that:
1. Loads state from disk (SQLite or JSON)
2. Performs its function
3. Saves state back to disk
4. Logs to file
5. Sleeps until next cycle

```python
# Pattern: checkpoint → work → checkpoint → sleep
import sqlite3, time, json
from pathlib import Path

def run_cycle():
    # Load state
    state = json.loads(Path('state.json').read_text())
    
    # Do work
    result = do_work(state)
    
    # Save state
    state['last_run'] = time.time()
    state['results'].append(result)
    Path('state.json').write_text(json.dumps(state))
    
    # Log
    with open('daemon.log', 'a') as f:
        f.write(f"{time.time()} | {result}\n")

while True:
    run_cycle()
    time.sleep(300)  # 5 minutes
```

### Critical Daemons

| Daemon | Cycle | Function |
|--------|-------|----------|
| income_automation_daemon.py | 1 hour | Full revenue loop |
| ancestor_miner.py | 30 seconds | Mine conversations for IP |
| survivability_governor.py | 5 minutes | Health checks & healing |
| email_capture_server.py | always-on | WSGI email collection |
| unified_dashboard.py | always-on | Flask web server |

## Database Layer

### SQLite Schema

```sql
-- Products
CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    name TEXT,
    price_cents INTEGER,
    gumroad_id TEXT,
    status TEXT
);

-- Email subscribers
CREATE TABLE subscribers (
    id INTEGER PRIMARY KEY,
    email TEXT UNIQUE,
    source TEXT,
    created_at TIMESTAMP
);

-- Ancestor findings
CREATE TABLE findings (
    id INTEGER PRIMARY KEY,
    file_id TEXT,
    name TEXT,
    type TEXT,
    description TEXT,
    value TEXT,
    quote TEXT,
    extracted_at TIMESTAMP
);
```

## Web Layer

### Flask Routes

```python
from flask import Flask, send_from_directory
from pathlib import Path

app = Flask(__name__)
public_html = Path('/home/j-5/public_html')

@app.route('/<path:filename>')
def serve_static(filename):
    target = public_html / filename
    if target.exists() and target.is_file():
        return send_from_directory(str(public_html), filename)
    return "Not Found", 404

@app.route('/capture_email', methods=['POST'])
def capture_email():
    # WSGI email capture
    pass
```

### WSGI Email Server

Standalone WSGI server on port 8768. No Flask, no dependencies.

```python
from wsgiref.simple_server import make_server

def email_app(environ, start_response):
    if environ['PATH_INFO'] == '/capture_email':
        # Parse POST body, validate email, write to SQLite
        pass
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b'OK']

httpd = make_server('0.0.0.0', 8768, email_app)
httpd.serve_forever()
```

## Email Layer

### SMTP Configuration

- **Provider:** Gmail (app password)
- **Host:** smtp.gmail.com
- **Port:** 587 (STARTTLS)
- **Authentication:** OAuth2 bypass via app password

### Nurture Sequence

5-email automated sequence triggered on subscription:
1. Welcome + free guide
2. The $0 stack
3. Biggest mistake
4. Community invitation
5. Product pitch

## Tunnel Layer

### Cloudflared Quick Tunnel

```bash
# No account required
cloudflared tunnel --url http://localhost:8888

# Or permanent tunnel (requires Cloudflare account)
cloudflared tunnel create drake-enterprise
cloudflared tunnel route dns drake-enterprise store.drakeenterprise.com
```

## Monitoring Layer

### Health Checks

Each daemon exposes a health endpoint or writes a heartbeat file:

```python
def check_health():
    daemons = ['income_daemon', 'ancestor_miner', 'email_server', 'dashboard']
    for daemon in daemons:
        pid_file = Path(f'/tmp/{daemon}.pid')
        if not pid_file.exists():
            restart_daemon(daemon)
```

### Resource Monitoring

- Disk usage: `shutil.disk_usage('/')`
- Memory: `psutil.virtual_memory()`
- CPU temp: `cat /sys/class/thermal/thermal_zone*/temp`
- Ollama status: HTTP GET to `:11434/api/tags`

## Security

### Principles

1. **No cloud APIs for core functions** — Zero vendor lock-in
2. **Local inference only** — No data leaves the machine
3. **App passwords, not main passwords** — Compartmentalized credentials
4. **SQLite, not cloud DB** — Full data ownership
5. **No Docker, no K8s** — Simple is secure

### Credential Storage

- `.env` file with 600 permissions
- App passwords for Gmail (not main password)
- API keys in environment variables only
- No secrets in code

## Performance

### Benchmarks

| Task | Model | Time | Quality |
|------|-------|------|---------|
| Blog post (800 words) | qwen2.5:7b | 45s | 8/10 |
| Code review (200 lines) | deepseek-coder:6.7b | 30s | 7/10 |
| Email sequence (5 emails) | qwen2.5:7b | 2m | 8/10 |
| Triage 50 files | llama3.2:3b | 10s | 9/10 |

### Optimizations

- Model caching: Ollama keeps models in RAM
- Batch processing: Process 20 files per cycle instead of 1
- Checkpointing: Resume from disk on restart
- Swap tuning: `vm.swappiness=10` for SSD longevity

## Why This Matters

I don't have venture capital. I don't have a cofounder. I don't have 40 hours a week.

What I have is a used laptop, Python, and the refusal to pay subscriptions for tools that don't fit my life.

This stack isn't enterprise-grade. But it's *mine*. It runs when I sleep. It survives power outages. It doesn't change its terms of service. It doesn't get acquired and shut down.

Autonomy beats perfection.

---

**Full setup scripts and configuration files:** [Sovereign AI Protocol](https://sythaia.tailb509d6.ts.net/store.html)

**Free ADHD Context Switch guide:** [https://sythaia.tailb509d6.ts.net/free-guide.html](https://sythaia.tailb509d6.ts.net/free-guide.html)
