This repository contains two main pieces of the AI Writer project:
AI_Writer_Client– a Next.js application that provides the user interface.AI_Writer_Service– a Cloudflare Worker service that hosts the API and business logic.
The client talks to the service via /api routes and the service relies on a single secret (SCREET_KEY) for authorization and other environment configuration.
/ai-writer
├── AI_Writer_Client/ # Next.js frontend
├── AI_Writer_Service/ # Cloudflare Worker backend
└── README.md # (this file)
Both sub‑projects are independent; you can run them side‑by‑side or deploy them separately.
- Node.js (v16+ recommended)
- npm or yarn
- Wrangler 3 (for Cloudflare Worker deployment)
- A Cloudflare account with Workers & KV namespace if you intend to deploy the service
| Project | File | Variables | Notes |
|---|---|---|---|
| Client | .env.local |
GEMINI_API_KEY |
Gemini / LLM provider key used by the UI |
| Service | .dev.vars (local) or Worker secrets |
SCREET_KEY |
Primary secret used by getSecretKey() |
Security: never commit secrets to git.
.dev.varsis currently in the repo and should be added to.gitignoreimmediately; rotateSCREET_KEYand treat it as leaked.
To set a Worker secret with Wrangler:
wrangler secret put SCREET_KEYOther configuration (e.g. database URL, KV names) lives in AI_Writer_Service/src/env.ts and the accompanying Typescript declarations; update as needed.
cd AI_Writer_Client
npm install
# add your Gemini key to .env.local
npm run devThe UI will start on http://localhost:3000 by default and proxy /api requests to the Worker if configured accordingly (see next.config.ts).
cd AI_Writer_Service
npm install
# create a local .dev.vars with SCREET_KEY and any other secrets
# example:
# SCREET_KEY="your_dev_key"
npm run dev # starts a local Miniflare serverThe service will listen on http://localhost:8787 and exposes the same endpoints used by the client.
To run the database migrations (SQLite/D1) use the scripts in migrations/.
Typical Next.js deployment (Vercel, Netlify, etc.). Make sure to set GEMINI_API_KEY in the host's environment.
Use Wrangler to publish the Worker, e.g.:
cd AI_Writer_Service
wrangler deploy --env productionConfigure KV namespaces and Worker secrets via the wrangler.toml/wrangler.json or through the dashboard.
Make sure to update the client’s next.config.ts API_URL to point at the published Worker.
- Do not commit
.dev.varsor `.env.local - Rotate
SCREET_KEYif it has been exposed. - Consider using a vault or CI secret store for production values.
- Add a git pre‑commit hook or CI check (e.g.
git-secrets) to prevent accidental leaks.
- Clone the repo
- Install dependencies in both
/AI_Writer_Clientand/AI_Writer_Service - Create local environment files
- Start the service with
npm run devinsideAI_Writer_Service - Start the client with
npm run devinsideAI_Writer_Client
AI_Writer_Client/README.md– client‑specific instructions (UI, design tokens, etc.)AI_Writer_Service/AGENTS.md– architecture notes for the backend agentsAI_Writer_Service/migrations– database schema history
Feel free to open issues or pull requests. Ensure any new configuration is documented here and no secrets are checked in.
Generated by GitHub Copilot