# Milestone 1: Prototype Implementation Plan ## Objective Deliver a functional prototype demonstrating the core infrastructure, basic UI for rule configuration, a mock email processing pipeline, and database schema implementation as outlined in the project roadmap. ## Scope This milestone focuses on establishing the foundational elements required for the Email Organizer. It will not include actual email fetching, complex AI processing, or user authentication. The goal is to have a working skeleton that proves the core concepts. ## File and Folder Structure ``` email-organizer/ ├── app/ # Main application package │ ├── __init__.py # Flask app factory │ ├── models.py # SQLAlchemy models (User, Folder) │ ├── routes.py # Flask routes (UI endpoints) │ ├── static/ # Static files (CSS, JS, images) │ │ └── ... # HTMX, AlpineJS, Tailwind CSS files │ └── templates/ # Jinja2 HTML templates │ └── index.html # Main UI page ├── migrations/ # Alembic migrations ├── tests/ # Unit and integration tests │ ├── __init__.py │ ├── conftest.py # Pytest configuration and fixtures │ ├── test_models.py # Tests for database models │ └── test_routes.py # Tests for UI routes ├── config.py # Application configuration ├── manage.py # CLI commands (e.g., db setup, mock process) ├── requirements.txt # Python dependencies ├── .env # Environment variables (not in VCS) ├── .env.example # Example environment variables ├── README.md └── plans/ └── milestone-1.md # This plan ``` ## Sample Code ### 1. Flask App Factory (`app/__init__.py`) ```python from flask import Flask from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(config_name='default'): app = Flask(__name__) app.config.from_object(config[config_name]) db.init_app(app) from app.routes import main app.register_blueprint(main) return app ``` ### 2. SQLAlchemy Models (`app/models.py`) ```python from app import db from sqlalchemy.dialects.postgresql import UUID import uuid class User(db.Model): __tablename__ = 'users' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) email = db.Column(db.String(255), unique=True, nullable=False) # Placeholders for Milestone 1 password_hash = db.Column(db.LargeBinary) imap_config = db.Column(db.JSONB) class Folder(db.Model): __tablename__ = 'folders' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) user_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=False) name = db.Column(db.String(255), nullable=False) rule_text = db.Column(db.Text) priority = db.Column(db.Integer) user = db.relationship('User', backref=db.backref('folders', lazy=True)) ``` ### 3. Basic UI Route (`app/routes.py`) ```python from flask import Blueprint, render_template, request, jsonify from app.models import Folder main = Blueprint('main', __name__) @main.route('/') def index(): # For prototype, use a mock user ID mock_user_id = '123e4567-e89b-12d3-a456-426614174000' folders = Folder.query.filter_by(user_id=mock_user_id).all() return render_template('index.html', folders=folders) @main.route('/api/folders', methods=['POST']) def add_folder(): # Mock implementation for prototype data = request.get_json() # In a real implementation, this would save to the database # For now, just echo back the data return jsonify({'message': 'Folder added (mock)', 'folder': data}), 201 ``` ### 4. Simple HTML Template (`app/templates/index.html`) ```html