Backend API Overview
Production-ready NestJS backend API for AI services, authentication, and analytics
Backend API Overview
The Backend API is a production-ready NestJS application that provides secure AI proxy services, user authentication, and usage analytics for the GoGrab platform.
Key Features
🔐 Authentication & Authorization
- JWT-based authentication
- Password hashing with bcrypt
- Role-based access control
- Secure session management
🤖 AI Proxy Services
- OpenAI Integration - GPT-4o, GPT-4o-mini, GPT-3.5-turbo
- Anthropic Integration - Claude 3.5 Sonnet, Claude 3 Opus
- Google Integration - Gemini Pro
- Automatic cost calculation
- Usage tracking per user
📊 Analytics & Tracking
- Real-time usage statistics
- Cost tracking per request
- Provider and model breakdown
- Historical data analysis
🔒 Security Features
- CORS configuration
- Rate limiting (100 req/min)
- Request validation
- Environment-based configuration
Architecture
Backend API
├── Auth Module # User authentication & JWT
├── AI Module # AI proxy for all providers
├── Analytics Module # Usage tracking & stats
└── MongoDB Integration # Data persistence
Quick Start
1. Install Dependencies
yarn install --ignore-engines
2. Configure Environment
Create .env.local in project root:
MONGODB_CONNECTION_STRING=mongodb+srv://...
MONGODB_DATABASE=gograb-api
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...
JWT_SECRET=your-secret-key
3. Start the Server
npx nx serve backend-api
Server will run on: http://localhost:3000/api
API Endpoints
Authentication
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/profile- Get user profile
AI Services (Requires Auth)
POST /api/ai/openai/chat- OpenAI completionPOST /api/ai/anthropic/messages- Anthropic completionPOST /api/ai/google/generate- Google Gemini completion
Analytics (Requires Auth)
GET /api/ai/usage- Get usage statisticsGET /api/ai/usage/providers- Get provider breakdown
Technologies Used
- NestJS - Progressive Node.js framework
- MongoDB - Document database with Mongoose
- JWT - JSON Web Tokens for authentication
- TypeScript - Type-safe development
- class-validator - Request validation
- bcrypt - Password hashing
Next Steps
- API Reference - Complete API documentation
- Setup Guide - Detailed setup instructions
- Security Guide - Security best practices
- Frontend Integration - Connect your frontend
Project Structure
apis/backend-api/
├── src/
│ ├── app/
│ │ ├── auth/ # Authentication module
│ │ ├── ai/ # AI proxy module
│ │ └── app.module.ts # Root module
│ └── main.ts # Application entry
libs/
├── api-contracts/ # Shared types (FE/BE)
└── backend-core/ # MongoDB schemas
Support
For issues or questions:
- Check the Troubleshooting Guide
- Review the API Reference
- See the Setup Guide