Beginner

Project Setup

Set up the project structure, install OpenAI and FastAPI, and create the foundation for an AI writing assistant with grammar checking, style analysis, and content generation.

Architecture

User Types Text
    |
    v
[Rich Text Editor] --> [FastAPI Backend]
                              |
                    +---------+---------+
                    |         |         |
                    v         v         v
              [Grammar]  [Style]  [Generation]
              [Checker]  [Analyzer] [Engine]
                    |         |         |
                    +---------+---------+
                              |
                              v
                    [Inline Suggestions UI]

Project Structure

writing-assistant/
+-- app/
|   +-- main.py           # FastAPI entry point
|   +-- config.py          # Settings
|   +-- grammar.py         # Grammar checking
|   +-- style.py           # Style analysis
|   +-- generator.py       # Content generation
|   +-- models.py          # Request/response models
+-- frontend/
|   +-- index.html         # Rich text editor
|   +-- editor.js          # Editor logic
|   +-- style.css          # Editor styles
+-- extension/             # Chrome extension
|   +-- manifest.json
|   +-- content.js
|   +-- popup.html

Dependencies

# requirements.txt
fastapi==0.115.6
uvicorn[standard]==0.34.0
openai==1.58.1
python-dotenv==1.0.1
pydantic-settings==2.7.1
httpx==0.28.1
textstat==0.7.3
sse-starlette==2.2.1

Configuration

# app/config.py
from pydantic_settings import BaseSettings
from functools import lru_cache

class Settings(BaseSettings):
    openai_api_key: str
    openai_model: str = "gpt-4o-mini"
    max_text_length: int = 10000
    log_level: str = "INFO"
    class Config:
        env_file = ".env"

@lru_cache()
def get_settings(): return Settings()

FastAPI Entry Point

# app/main.py
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

app = FastAPI(title="Writing Assistant API", version="1.0.0")
app.add_middleware(CORSMiddleware, allow_origins=["*"],
    allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
app.mount("/static", StaticFiles(directory="frontend"), name="static")

@app.get("/")
async def root(): return FileResponse("frontend/index.html")

@app.get("/health")
async def health(): return {"status": "healthy"}
📝
Checkpoint: Start the server with uvicorn app.main:app --reload and verify the health endpoint at localhost:8000/health.

Key Takeaways

  • Three writing modules (grammar, style, generation) provide comprehensive assistance.
  • FastAPI handles real-time suggestions with async endpoints and streaming support.
  • The frontend uses contenteditable for a clean, framework-free editing experience.