PhiloGPT is a purpose-built AI philosophical guide designed to help you navigate life's challenges with the timeless wisdom of Marcus Aurelius, Seneca, and Epictetus.
Built with a focus on privacy, speed, and architectural elegance, PhiloGPT combines a stateless backend with a stateful client to provide a seamless, serverless-native experience.
PhiloGPT uses a hybrid state management system to ensure performance and scalability.
flowchart LR
User((User)) -->|Message| Frontend[Next.js Frontend]
Frontend -->|POST /api/chat| Middleware[Middleware]
Middleware -->|Validated| API[API Route]
API -->|Sliding Window Check| Redis[(Upstash Redis)]
Redis -->|Allowed / Blocked| API
API -->|System Prompt + History| AI[AI Provider]
AI -->|Stream Chunks| API
API -->|SSE Stream| Frontend
Frontend -->|Persist| Storage[(LocalStorage)]
- Strategy Pattern: Abstracted AI providers allowing instant switching between Gemini and OpenAI.
- Stateless Backend: The server holds no session state, making it infinitely scalable on Vercel.
- Stateful Client: All chat history and session persistence live in the user's browser for maximum privacy.
- Atomic Rate Limiting: Uses Lua scripting inside Redis to provide an unbreakable sliding window barrier against abuse.
Unlike basic rate limiters that reset on server restarts, PhiloGPT uses a Persistent Sliding Window algorithm:
- Global Memory: All server instances share a single source of truth via Upstash Redis.
- Lua Atomicity: The limit check and increment occur as a single atomic operation, preventing race conditions.
- Sliding Window: Provides a smooth experience by tracking individual request timestamps rather than fixed-minute blocks.
- Node.js 18+
- An Upstash Redis account (Free Tier)
- A Google AI (Gemini) or OpenAI API key
Create a .env.local file in the root directory:
# AI Providers
GEMINI_API_KEY="your-gemini-key"
OPENAI_API_KEY="your-openai-key"
# Global Rate Limiting (Upstash)
UPSTASH_REDIS_REST_URL="https://your-db-url.upstash.io"
UPSTASH_REDIS_REST_TOKEN="your-rest-token-here"
# App Settings
AI_PROVIDER="gemini"npm install
npm run dev- Framework: Next.js 15+ (App Router)
- Styling: Tailwind CSS v4 + Lucide Icons
- AI: Google Generative AI (Gemini Flash)
- Memory: Upstash Redis
- Streaming: Server-Sent Events (SSE)
PhiloGPT is guided by the Dichotomy of Control:
"Some things are within our power, while others are not. Within our power are opinion, motivation, desire, aversion, and, in a word, whatever is our own doing; not within our power are our body, our property, reputation, office, and, in a word, whatever is not our own doing." — Epictetus
Created with focus and reason.