Modern AI-powered web application built with Next.js 14 (App Router), TypeScript, Tailwind CSS, Radix UI primitives, Supabase auth, and a modular component system.
- Framework: Next.js 14 (App Router)
- Language: TypeScript / React 18
- Styling: Tailwind CSS + Custom utility/components +
tailwind-merge - UI Primitives: Radix UI + Headless component wrappers (
./frontend/components/ui/*) - State: Redux Toolkit (
store.ts) + React hooks - Auth: Supabase (email/password + password reset flows)
- Forms & Validation:
react-hook-form+zod - Data Fetching / HTTP:
axios - Theming:
next-themes(light/dark) + customThemeProvider - Animations:
framer-motion,tailwindcss-animate - Charts / Viz:
recharts - Markdown Rendering:
react-markdown
Using npm:
npm installCreate .env.local in frontend/ with (adjust as needed):
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_API_BASE_URL=https://your-backend-url
(Values read via helpers in frontend/lib/env.ts.)
From frontend/ directory:
npm run devApp runs at http://localhost:3000.
npm run build
npm startnpm run lintfrontend/
app/ # Next.js app router pages
login/ # Login page
register/ # Registration page
forgot-password/ # Request password reset
reset-password/ # Perform password reset
settings/ # User settings
chat/ # Chat / AI interaction UI
layout.tsx # Root layout (providers, global styles)
page.tsx # Landing page
components/ # Reusable components
ui/ # Design system (Radix-based wrappers)
auth-provider.tsx # Auth context / Supabase integration
protected-route.tsx # Auth guard component
theme-provider.tsx # Theme switcher logic
lib/ # Utilities (env, store, hooks)
public/ # Static assets
styles/ # Global styles
hooks/ # Custom hooks (`use-toast`, `use-mobile`)
components/ui/*: Collection of composable UI building blocks (buttons, dialogs, forms, inputs, sheets, menus, etc.).auth-provider.tsx: Wraps Supabase auth and exposes session/user.protected-route.tsx: Simple route guard for authenticated views.theme-provider.tsx: Handles dark/light/system theme.animated-background.tsx: Visual flair component.notification.tsx: Toast/alert utilities.
- User registers via
register/page.tsx(Supabase email signup). - Logs in via
login/page.tsx(session stored client-side). - Forgot password triggers Supabase reset email (
forgot-password/page.tsx). - User follows email link to
reset-password/route to set new password. - Protected pages/components use
protected-route.tsxto check session.
react-hook-formhandles form state/performance.zodschemas provide parsing + validation.- Integrate with components via custom form wrappers in
components/ui/form.tsx.
Redux Toolkit store initialized in lib/store.ts (slices live under lib/slices/). Prefer RTK Query or hooks for async usage—add as project evolves.
- Tailwind for utility-first styling (
globals.css). - Radix UI primitives wrapped for consistent design tokens.
- Theme switching with
next-themesviaThemeProvider.
Set NEXT_PUBLIC_API_BASE_URL to point to the Python backend (FastAPI or similar) in ./backend/. Use axios for calls (add abstraction under frontend/lib/api/).
Python FastAPI service powering authentication sync, AI model management, and chat streaming.
- Framework: FastAPI
- Server: Uvicorn
- Database: PostgreSQL (via SQLAlchemy)
- ORM: SQLAlchemy Declarative
- Auth: Supabase JWT validation (
supabase.py) - AI Providers: Pluggable architecture in
backend/ai_providers/(e.g. Gemini viagoogle-generativeai) - Streaming: Server-Sent Events (SSE) for
/chatsendpoint - Env Management:
python-dotenv
From backend/ directory:
pip install -r requirements.txt(Consider using a virtual environment.)
Create .env in backend/:
DATABASE_URL=postgresql://user:pass@host:5432/dbname
SUPABASE_JWT_SECRET=your_supabase_jwt_secret
SUPABASE_PROJECT_ID=your_project_id
Add any AI provider secrets (e.g. Gemini API key) when required.
uvicorn main:app --reload --port 8000Service at http://localhost:8000.
Currently allow_origins=["*"] in main.py. Change to your deployed frontend origin before production:
allow_origins=["https://your-frontend-domain"]Tables created automatically on startup via:
Base.metadata.create_all(bind=engine)Models defined in models.py. Session helper in database.py.
| Method | Path | Purpose |
|---|---|---|
| GET | / | Health check |
| POST | /sync | Sync Supabase user into local DB |
| POST | /ai-models | Create/update user AI model entry |
| GET | /ai-models | List user's AI models |
| PATCH | /ai-models/{model_id} | Update a model partial |
| DELETE | /models/{id} | Delete a model by internal id |
| PUT | /models/selected | Set current selected model |
| GET | /models/selected/details | Get selected model full info |
| GET | /ai-providers | List available providers |
| POST | /chat | Non-stream chat response |
| POST | /chats | Streaming chat via SSE |
- Client POSTs to
/chatswith messages JSON. - Backend validates Supabase token & selected model.
- Starts async streaming task calling provider adapter.
- Chunks queued & emitted as SSE until
isComplete.
Implement new provider under backend/ai_providers/:
- Create provider module (e.g.
openai.py). - Implement required interface in
providers.py/ service expectsgenerate_response&stream_chatpattern. - Register in provider map so
/ai-providerslists it.
- Frontend sends
Authorization: Bearer <supabase_access_token>. - Backend validates with
validate_supabase_token(decodes JWT, ensures integrity). - User auto-provisioned in
/syncif not present.
Never commit real secrets. Use .env locally and provisioning system / secret manager in production.
Frontend .env.local:
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
Run both:
# Terminal 1
(cd backend && uvicorn main:app --reload --port 8000)
# Terminal 2
(cd frontend && npm run dev)The application is developed under Solutions with Aaqil.
