Live Demo: https://npc-memory-webservice.onrender.com
Interactive F1 car building experience with AI-powered assistant Dax, featuring OAuth 2.0 authentication, GDPR compliance, and cloud-based LLM integration
An immersive F1 car configuration system where players interact with Dax, an AI race engineer powered by Groq's LLM API. Players build custom Formula 1 cars by selecting chassis, engines, tires, and aerodynamic components while receiving real-time AI guidance and technical advice.
- ๐ OAuth 2.0 Authentication - Login with Google or GitHub, or use email/password
- ๐ค AI Race Engineer (Dax) - Powered by Groq API (Llama 3.1 8B Instant)
- ๐๏ธ Real-Time Car Building - Select 5 F1 components with live preview
- ๐พ Auto-Save Progress - Parts selection saved to database instantly
- ๐ง Memory System - AI remembers your conversation and build status
- ๐ญ Sentiment Analysis - NPC responds to player emotions
- ๐ PostgreSQL Database - Cloud-hosted on Neon.tech
- ๐ GDPR Compliant - Full privacy policy and data protection
- ๐จ Cinematic UI - F1 briefing-style interface with video backgrounds
Player Login (OAuth/Email) โ Cover Page โ Chat Interface
โ
Part Selection โ Auto-Save DB โ AI Assistant (Groq API)
โ
Build Complete โ Submit Feedback โ Portfolio Redirect
| Component | Technology |
|---|---|
| Backend API | FastAPI (Python) |
| Database | PostgreSQL (Neon.tech) |
| AI Model | Groq API - Llama 3.1 8B (150 tokens/response) |
| Authentication | OAuth 2.0 (Google, GitHub) + JWT |
| Sentiment Analysis | RoBERTa Transformer |
| Frontend | HTML/CSS + Vanilla JavaScript |
| Deployment | Render.com (ready) |
- Python 3.8+
- Git
- PostgreSQL database (Neon.tech recommended)
- Groq API key (free tier: 30 requests/min)
- Google OAuth credentials (optional)
- GitHub OAuth app (optional)
git clone https://github.com/NJVinay/npc_memory.git
cd npc_memorypython -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activatepip install -r requirements.txt# Copy environment template
cp .env.example .env
# Edit .env file with your credentialsRequired Environment Variables:
# Database
DATABASE_URL=postgresql://username:password@host:port/database
# AI/LLM Configuration
USE_EXTERNAL_LLM=true
LLM_PROVIDER=groq
LLM_API_KEY=your_groq_api_key_here
LLM_MODEL=llama-3.1-8b-instant
# Authentication
JWT_SECRET_KEY=your_secret_key_here
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
# Application
ENVIRONMENT=development
ALLOWED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000
SERVICE_API_KEY=your-service-api-key-here
REQUIRE_SERVICE_API_KEY=true
ALLOWED_EMAIL_DOMAINS=example.com
ALLOWED_EMAILS=Note: API endpoints intended for programmatic access require x-service-key when REQUIRE_SERVICE_API_KEY=true. Browser UI routes use JWT cookies.
Groq API (Free):
- Go to https://console.groq.com
- Create account and get API key
- Free tier: 30 requests/min
Google OAuth (Optional):
- Go to https://console.cloud.google.com
- Create OAuth 2.0 Client ID
- Add redirect URI:
http://127.0.0.1:8000/auth/callback/google
GitHub OAuth (Optional):
- Go to https://github.com/settings/developers
- Create new OAuth App
- Add callback URL:
http://127.0.0.1:8000/auth/callback/github
uvicorn main:app --reloadOpen your browser: http://localhost:8000
cp .env.example .env
### 6. Run Application
```bash
uvicorn main:app --reload
Open your browser and navigate to: http://localhost:8000
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Login page |
/login |
GET | Login page (alias) |
/cover |
GET | Cinematic F1 briefing page |
/chat |
GET | AI-powered car builder (Dax) |
/chat_static |
GET | Static dialogue car builder (TurboTom) |
/chat_api |
POST | Submit dialogue to AI (JSON) |
/save_car_build |
POST | Auto-save car build progress |
/create_player_form |
POST | Email/password registration |
/verify_player |
POST | Email/password login |
/auth/login/google |
GET | Google OAuth login |
/auth/login/github |
GET | GitHub OAuth login |
/auth/callback/google |
GET | Google OAuth callback |
/auth/callback/github |
GET | GitHub OAuth callback |
/terms |
GET | Privacy policy & GDPR terms |
/evaluation |
GET | Feedback submission page |
/health |
GET | System health check |
- Login - Sign in with Google, GitHub, or email/password
- Cover Page - Watch cinematic F1 briefing intro
- Start Building - Randomized between AI chat or static flow
- Select Parts - Choose chassis, engine, tires, front wing, rear wing
- AI Guidance - Dax provides real-time advice and tracks progress
- Auto-Save - Build saved to database on every part selection
- Complete Build - Submit feedback and return to portfolio
Chassis:
- Standard Monocoque
- Ground Effect Optimized
Engine:
- 2004 V10 (high power, fuel-hungry)
- 2006 V8 (balanced performance)
Tires:
- C5 Slick (dry conditions)
- Full Wet (rain conditions)
Front Wing:
- High Lift (better cornering, more drag)
- Simple Outwash (streamlined)
Rear Wing:
- High Downforce (stability)
- Low Drag (top speed)
MODEL_MAX_TOKENS = 150 # Max response length
MODEL_TEMPERATURE = 0.4 # Response creativity (0.0-1.0)
CONTEXT_WINDOW = 10 # Recent messages for contextACCESS_TOKEN_EXPIRE = 15 # Minutes
REFRESH_TOKEN_EXPIRE = 7 # Days
JWT_ALGORITHM = "HS256"- Players - User accounts (email, password hash, OAuth data)
- CarBuild - F1 car configurations
- NPCMemory - Conversation history with sentiment
- Consent - GDPR consent records
git add .
git commit -m "Deploy F1 car builder"
git push origin main- Go to https://render.com
- New โ Web Service
- Connect GitHub repo:
NJVinay/npc_memory - Runtime: Python 3
- Build:
pip install -r requirements.txt - Start:
uvicorn main:app --host 0.0.0.0 --port $PORT
Add these in Render dashboard:
DATABASE_URL=<neon-postgresql-url>
LLM_API_KEY=<groq-api-key>
GOOGLE_CLIENT_ID=<google-client-id>
GOOGLE_CLIENT_SECRET=<google-secret>
GITHUB_CLIENT_ID=<github-client-id>
GITHUB_CLIENT_SECRET=<github-secret>
JWT_SECRET_KEY=<random-secret-key>
USE_EXTERNAL_LLM=true
LLM_PROVIDER=groq
LLM_MODEL=llama-3.1-8b-instant
ENVIRONMENT=production
ALLOWED_ORIGINS=https://your-app.onrender.com
SERVICE_API_KEY=<random-service-key>
REQUIRE_SERVICE_API_KEY=true
ALLOWED_EMAIL_DOMAINS=yourdomain.com
ALLOWED_EMAILS=
After deployment (e.g., https://your-app.onrender.com):
Google OAuth Console:
- Add:
https://your-app.onrender.com/auth/callback/google
GitHub OAuth Settings:
- Add:
https://your-app.onrender.com/auth/callback/github
curl http://localhost:8000/healthpython -c "from database import get_db; next(get_db()); print('โ
Database connected')"python -c "from sentiment import analyze_sentiment; print(analyze_sentiment('I love this!'))"python -c "from llm_adapter import generate_with_groq; print(generate_with_groq('Hello'))"OAuth Redirect Error
# Add redirect URIs in OAuth settings:
# Google: https://console.cloud.google.com/apis/credentials
# GitHub: https://github.com/settings/developers
# Add: http://127.0.0.1:8000/auth/callback/google
# Add: http://127.0.0.1:8000/auth/callback/githubDatabase Connection Error
# Verify .env DATABASE_URL
# Test connection:
python -c "from database import engine; print(engine.connect())"Groq API Rate Limit
# Free tier: 30 requests/minute
# Upgrade to paid tier for higher limits
# Or switch to OpenAI/HuggingFace in llm_adapter.pyCookie Security Warning
# Development: secure=False (localhost)
# Production: Set ENVIRONMENT=production (auto-enables HTTPS cookies)Chat Box Overflow
# Already fixed in templates/chat.html
# Chat box is 320px wide, 500px tall with auto-scrolling
# Text wraps with break-words for long messages- API Response Time: ~2-5 seconds (Groq free tier)
- Database Queries: <100ms (Neon.tech)
- Page Load: ~1-2 seconds
- Memory Usage: ~200-300MB (no local model)
- Storage: Minimal (~50MB codebase)
Groq Free Tier Limits:
- 30 requests/minute
- Llama 3.1 8B Instant model
- 150 tokens max per response
- Production-ready reliability
- OAuth 2.0 authentication (Google + GitHub)
- Email/password authentication with bcrypt
- JWT token management (15min access, 7 day refresh)
- Groq API integration (cloud-based LLM)
- Auto-save car builds on part selection
- Real-time chat with AI assistant
- Sentiment analysis for player messages
- GDPR-compliant privacy policy
- Cinematic F1 briefing cover page
- Portfolio redirect button
- Database migrations removed
- Production-ready deployment config
- Secure HTTPS cookies for production
- Multiple AI engineers (different personalities)
- Voice input/output for Dax
- 3D car preview (Three.js)
- Race simulation with built car
- Leaderboards and sharing
- Mobile app version
- Multi-language support
Originally developed as a Bachelor's thesis on "Memory-Driven NPC Behavior" at Blekinge Institute of Technology, this project has been upgraded to a job-ready portfolio piece showcasing:
- Full-stack web development (FastAPI + PostgreSQL)
- Modern authentication patterns (OAuth 2.0, JWT)
- AI/LLM integration (Groq API)
- GDPR compliance and data protection
- Production deployment (Render.com)
- Clean architecture and code organization
- Modular emotion-aware NPC systems
- Static vs. dynamic dialogue comparison
- Cloud LLM vs. local model tradeoffs
- User experience evaluation frameworks
This project is developed for academic research and portfolio purposes.
Developer:
- Jyotir Vinay Naram
- Portfolio: https://jyotirvinay-portfolio.netlify.app
- Email: jv5102003@gmail.com
Institution:
- Blekinge Institute of Technology
- Computer Science Program
- Karlskrona, Sweden
Project Links:
- ๐ GitHub: https://github.com/NJVinay/npc_memory
- ๐ Live Demo: [Deploy on Render]
- ๐ง Contact: jyna24@student.bth.se
- Groq - Free LLM API access
- Neon.tech - Serverless PostgreSQL hosting
- Render.com - Free web service deployment
- Google/GitHub - OAuth 2.0 infrastructure
- Hugging Face - RoBERTa sentiment model
Built with โค๏ธ for the F1 racing community and AI enthusiasts