idea.mdā¢5.65 kB
# Smart Home Automation System - Development Spec
## šÆ Project Overview
Build a **modular smart home automation system** that bridges IoT devices with AI agents via Model Context Protocol (MCP). Designed as a monorepo for development efficiency, but structured for easy splitting into multiple GitHub repos later.
## šļø Architecture
```
GitHub/n8n ā Cloudflare Tunnel ā Raspberry Pi ā IoT Network (Smart Devices)
ā
MCP Server ā ā Smart Home API ā ā Device Controllers
```
## š Monorepo Structure
```
smart-home-automation/
āāā README.md (system overview)
āāā docker-compose.yml (full stack)
āāā packages/
ā āāā smart-home-core/ # ā Future: smart-home-api repo
ā ā āāā package.json & README.md (standalone)
ā ā āāā Dockerfile & docker-compose.yml
ā ā āāā src/
ā ā āāā controllers/ (device APIs)
ā ā āāā devices/ (kasa.ts, tuya.ts, hue.ts)
ā ā āāā app.ts (Express server)
ā āāā smart-home-mcp/ # ā Future: smart-home-mcp repo
ā ā āāā package.json & README.md (standalone)
ā ā āāā Dockerfile & docker-compose.yml
ā ā āāā src/
ā ā āāā tools/ (lighting.ts, scenes.ts, alerts.ts)
ā ā āāā server.ts (MCP server)
ā āāā smart-home-dashboard/ # ā Future: smart-home-dashboard repo
ā ā āāā src/ (React app for manual control)
ā āāā shared-types/ # ā Future: @yourname/smart-home-types npm
ā āāā src/ (TypeScript interfaces)
āāā tools/
ā āāā split-repos.sh (automated repo splitting)
āāā examples/
āāā n8n-workflows/
āāā claude-config/
```
## š§ Technology Stack
- **Languages**: TypeScript/Node.js
- **Deployment**: Docker + Docker Compose
- **Networking**: Cloudflare Tunnel (Pi ā Internet)
- **Hardware**: Raspberry Pi (any version)
- **Devices**: TP-Link Kasa, Tuya-based smart lights/plugs
- **AI Integration**: Model Context Protocol (MCP)
## š Development Phases
### **Phase 1: Core Infrastructure** (Weekend 1)
1. **Setup Raspberry Pi** with fresh OS + Docker
2. **Build smart-home-core** package:
- Express.js server on port 3001
- Device discovery and control
- REST API endpoints: `/api/lights/:id/color`, `/api/scenes/:name`
3. **Test device control** with direct HTTP calls
4. **Docker deployment** working locally
### **Phase 2: MCP Integration** (Weekend 2)
1. **Build smart-home-mcp** package:
- MCP server on port 3000
- Tools: `setBuildStatus()`, `createFocusEnvironment()`, `flashAlert()`
- Wraps smart-home-core API calls
2. **Test with Claude Desktop** locally
3. **Setup Cloudflare Tunnel** for external access
4. **n8n integration** via MCP Client Tool node
### **Phase 3: Automation & Polish** (Weekend 3)
1. **GitHub webhook workflows** in n8n
2. **Web dashboard** for manual control
3. **Documentation** and demos
4. **Prepare for repo splitting**
## š ļø Key Implementation Details
### **Device Control Examples**
```typescript
// TP-Link Kasa
await fetch(`http://${ip}:9999`, {
method: 'POST',
body: kasaEncrypt(command)
});
// Tuya devices
const tuya = new TuyaDevice({ ip, id, key });
await tuya.set({ switch: true });
```
### **MCP Tools**
```typescript
export const tools = {
setBuildStatus: async (status: 'success' | 'failure' | 'running') => {
await fetch('http://localhost:3001/api/scenes/build-status', {
method: 'POST',
body: JSON.stringify({ status })
});
}
};
```
### **n8n Integration**
```
GitHub Webhook ā Parse Build Status ā MCP Client Tool ā Lights Change Color
```
## š Future Repo Split Strategy
**Target GitHub repos after splitting:**
1. **smart-home-api** - Device control server
2. **smart-home-mcp** - AI integration layer
3. **smart-home-dashboard** - Web interface
4. **smart-home-examples** - Workflows & configs
5. **@yourname/smart-home-types** - NPM package
**Split command**: `./tools/split-repos.sh` (automated with git subtree)
## š Networking Setup
### **Network Architecture**
- **Main Network**: Pi + NAS (192.168.1.x)
- **IoT Network**: Smart devices (192.168.50.x)
- **Pi Bridge**: Connect both networks OR firewall rules
### **External Access**
- **Cloudflare Tunnel**: `smart-home.yourdomain.com` ā Pi:3000
- **Security**: Optional Bearer token auth
## š Prerequisites Checklist
- [ ] Raspberry Pi (any version) with network access
- [ ] Smart devices (TP-Link Kasa or Tuya-based)
- [ ] Device IPs identified on IoT network
- [ ] Docker installed on Pi
- [ ] Cloudflare account (free tier)
- [ ] n8n instance running (Hostinger)
## šØ Portfolio Value
**Demonstrates:**
- Microservices architecture
- IoT device integration
- AI tooling (MCP) knowledge
- Docker containerization
- Network security awareness
- Modern TypeScript development
- API design (REST + MCP)
## š Getting Started Tonight
1. **Flash Pi with latest Raspberry Pi OS**
2. **Install Docker**: `curl -fsSL https://get.docker.com | sh`
3. **Clone/create monorepo structure**
4. **Start with device discovery**: Scan network, identify device IPs
5. **Build basic Express server** for device control
6. **Test with one light** using direct API calls
**Success criteria for tonight**: Turn one smart light on/off via HTTP API call to your Pi.
---
**Time Estimate**: 2-3 weekends for full system, 2-4 hours tonight for basic proof of concept.
**Immediate next step**: Get Pi online and scan for your smart device IPs!