Type naturally and FlowWrite predicts the next word inline and offers full sentence continuations, so finishing a thought takes fewer keystrokes.
- Frontend: Next.js 14 (App Router) + Tailwind CSS
- Backend: FastAPI + a custom trigram/bigram/unigram backoff language model (no external API keys or model downloads required — fully offline)
cd backend
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# (corpus.txt is already generated and included, but you can rebuild it with)
python3 corpus_builder.py
uvicorn main:app --reload --port 8000The API is now live at http://localhost:8000. Check http://localhost:8000/api/health.
Endpoints:
POST /api/predict/next-word{ "text": "I want to learn" }→{ "prediction": "how" }POST /api/predict/complete{ "text": "I want to learn", "count": 4, "style": "casual" }→{ "suggestions": [...] }
cd frontend
cp .env.example .env.local # points at http://localhost:8000 by default
npm install
npm run devOpen http://localhost:3000.
For a production build:
npm run build
npm run startflowwrite/
├── backend/
│ ├── corpus_builder.py # generates corpus.txt (diverse, modern sentences)
│ ├── ngram_model.py # the language model (prediction + generation)
│ ├── main.py # FastAPI app & endpoints
│ └── requirements.txt
└── frontend/
├── app/
│ ├── page.tsx # New Text (main editor)
│ ├── history/ # History
│ ├── favourites/ # Favourites
│ ├── settings/ # Settings
│ └── about/ # About
├── components/ # Sidebar, Header, SmartEditor, SuggestionList, ...
└── lib/ # api client, localStorage helpers, theme context
ngram_model.py builds trigram, bigram, and unigram frequency tables from
corpus.txt at startup. For inline prediction it takes the most likely next
token via trigram → bigram → unigram backoff. For "Complete your thought" it
samples several distinct continuations at different temperatures (for
variety) and stops each one at a natural sentence boundary, optionally
reweighting the vocabulary toward a chosen writing style (professional /
casual / creative / simple).
This keeps the whole app self-contained and fast — no API keys, no GPU, no
internet connection needed at runtime. If you'd like sharper, more fluent
completions later, you can swap ngram_model.py's complete_thought to call
an LLM API instead — main.py's request/response shapes won't need to change.
- History, Favourites, and Settings are stored in the browser's
localStorage(per-device, no backend database). - Dark/light theme is applied via a
darkclass on<html>and persisted tolocalStorage. nextis pinned to14.2.35(latest patched 14.x release). Anext auditwill still show advisories tied to Server Actions / Image Optimizer / Middleware — this app uses none of those features, so they don't apply, but you're welcome to upgrade to Next 15/16 later.