A production-ready MERN stack template for building AI-powered chat applications, developed with β€οΈ by Team StellarStackLtd For Nexlayer Community. This template provides a robust foundation for creating interactive chat experiences using Google's Gemini Pro API, featuring modern authentication, real-time chat capabilities, and scalable architecture.
- Quick Start
- Features
- System Requirements
- Installation
- Configuration
- Development
- Testing
- Deployment
- API Documentation
- Contributing
- Support
- License
Welcome! You're about to deploy your very own AI-powered chat application to the Nexlayer. By the end of this tutorial, you'll have a live website that anyone can visit and chat with AI.
Your app will have three awesome features:
- Smart AI Chat - Users can have conversations with Google's Gemini AI
- Google Login - Secure authentication so users can save their chat history
- Live on the Internet - Anyone can visit your custom URL and use your app
You'll need:
- A GitHub account (free)
- 15 minutes of your time
- Zero experience with cloud deployment (we'll teach you everything!)
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key" - it's the big blue button
- Copy your key - it starts with
AIza...
- Visit Google Cloud Console
- Create a new project: Click "Select a project" β "New Project"
- Enable OAuth: Go to "APIs & Services" β "Credentials" β "Create Credentials" β "OAuth 2.0 Client ID"
- Set up redirect URIs:
http://localhost:3030/auth/google/callbackhttps://YOUR-APP-NAME.nexlayer.io/auth/google/callback
- Save your Client ID and Client Secret
- Visit the template: Stellar-Ai-Chat-MERN-Template
- Click "Fork" in the top-right corner
- Choose your account as the destination
- Clone your fork:
git clone https://github.com/YOUR-USERNAME/Stellar-Ai-Chat-MERN-Template.git - Open
nexlayer.yamland replace placeholder values with your real API keys - Choose your unique app name (becomes part of your website URL)
- Create a GitHub Personal Access Token with
write:packagesandread:packagespermissions - Add the token to your repository secrets as
GHCR_TOKEN_RW - Enable "Read and write permissions" in Actions settings
- Push your changes:
git add . && git commit -m "Configure deployment" && git push - Watch the magic happen in GitHub Actions
- Your app is live at:
https://YOUR-APP-NAME.nexlayer.io
π Congratulations! You've just deployed a production-ready AI application to the cloud!
project/
βββ client-fe/ # Frontend React app
βββ server/ # Backend Express app
βββ nexlayer.yaml # Main deployment config
βββ docker-compose.yml # Local development
βββ .github/workflows/
βββ build_and_deploy.yml # CI/CD build and deploy to nexlayer pipeline
βββ ci.yml # CI/CD pipeline
- Multi-service apps: Separate containers for frontend/backend
- Database setup: Use platform images with init scripts
- Environment management: Pod-level variable scoping
- Routing: Avoid path conflicts between services
- Template Complexity: This represents advanced use case vs. Hello World
- Scalability Patterns: Multi-pod deployments with proper service communication
- DevOps Integration: Full CI/CD with image building and deployment automation
- Security Best Practices: Secret management and access control patterns
StellarStack AI Chat Template is a comprehensive solution for building AI chat applications, providing:
-
User Authentication:
- Google OAuth V2 integration
- Role-based access control
- Secure session management
-
Chat Features:
- AI-powered conversations using Google Gemini Pro
- Rate limiting for non-authenticated users
- Unlimited access for authenticated users
- Chat history management
-
Modern Architecture:
- MERN Stack (MongoDB, Express.js, React.js, Node.js)
- Redux Toolkit for state management
- Docker containerization
- Scalable microservices architecture
This structure shows you how Nexlayer organizes your application into distinct, manageable pieces. Each pod has its own responsibility and configuration, but they all work together as one cohesive app.
Here's the magic of Nexlayer - all these services discover and connect to each other automatically. This diagram shows exactly how data flows through your application:
- Node.js: 18.x or higher
- npm: 8.x or higher
- MongoDB: 6.0 or higher (local or Atlas)
- Git: 2.x or higher
- Docker: 20.x or higher (for containerized development)
- Docker Compose: 2.x or higher
- RAM: 4GB or more
- Storage: 2GB free space
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- Node.js (v18 or higher)
- MongoDB (local or Atlas)
- Docker (optional)
- Google Cloud Console account (for OAuth and Gemini API)
# Clone the repository
git clone https://github.com/StellarStack/Stellar-Ai-Chat-MERN-Template.git
cd Stellar-Ai-Chat-MERN-Template
# Install dependencies
cd server && npm install
cd ../client-fe && npm install
# Set up environment variables
cp server/.env.example server/.env
cp client-fe/.env.example client-fe/.env
# Edit the .env files with your configuration
# See ENVIRONMENT_SETUP.md for detailed instructionsThe application uses environment variables for configuration. See ENVIRONMENT_SETUP.md for detailed setup instructions.
nexlayer.yaml- Production deployment configurationdocker-compose.yml- Local development with Dockerserver/.env- Backend environment variablesclient-fe/.env- Frontend environment variables
# Start the backend server
cd server
npm run dev
# In a new terminal, start the frontend
cd client-fe
npm start# Start all services with Docker Compose
docker-compose up --build
# Stop all services
docker-compose downnpm run dev # Start development server with nodemon
npm run build # Build for production
npm test # Run tests
npm run lint # Run ESLint
npm run format # Format code with Prettiernpm start # Start development server
npm run build # Build for production
npm test # Run tests
npm run lint # Run ESLint
npm run format # Format code with Prettier# Backend tests
cd server
npm test
# Frontend tests
cd client-fe
npm test
# Run all tests
npm run test:allThe project includes comprehensive test coverage for both frontend and backend components.
GitHub Actions automatically runs tests on every push and pull request:
- Unit tests for both frontend and backend
- Integration tests
- Build verification
- Code quality checks
The template is optimized for deployment on Nexlayer with automatic CI/CD:
- Fork the repository
- Configure environment variables in
nexlayer.yaml - Set up GitHub secrets for automated deployment
- Push to main branch - automatic deployment triggers
# Build Docker images
docker build -t your-app-backend ./server
docker build -t your-app-frontend ./client-fe
# Deploy to your preferred platform
# See platform-specific documentation- Nexlayer (recommended) - Optimized for this template
- Heroku - Easy deployment with Git integration
- AWS - Scalable cloud infrastructure
- Google Cloud - Enterprise-grade hosting
- Vercel - Frontend deployment
- Railway - Full-stack deployment
POST /v1/auth/google- Google OAuth authenticationPOST /v1/auth/refresh- Refresh access tokenGET /v1/auth/logout- User logout
POST /v1/gemini/api/chat- Send message to AIGET /v1/gemini/api/getchathistory- Get user's chat historyPOST /v1/gemini/api/chatdata- Get specific chat data
POST /v1/user/location- Update user locationGET /v1/user/profile- Get user profile
The frontend uses Redux Toolkit for state management and API calls. See the store files in client-fe/src/store/ for implementation details.
- Google Cloud Console: https://console.cloud.google.com/
- Create OAuth 2.0 credentials
- Add authorized redirect URIs
- Google AI Studio: https://makersuite.google.com/app/apikey
- Generate API key for Gemini models
- MongoDB Atlas: https://cloud.mongodb.com/
- Create cluster and database user
- Get connection string
- IP Geolocation API: https://ipgeolocation.io/
- Sign up for API key
- Geocode API: https://geocode.maps.co/
- Get API key for reverse geocoding
- Use
.env.examplefiles as templates - Keep
.envfiles in.gitignore - Use strong, unique secrets for JWT
- Rotate API keys regularly
- Use environment-specific configurations
- Never commit
.envfiles to version control - Don't share API keys publicly
- Don't use default/weak secrets
- Don't hardcode values in source code
Create GitHub PAT with package-write rights:
docker login ghcr.io -u <github-username> -p <PAT-GithubWritePrivileges>Build and push backend:
cd <repo-dir>
docker build -t stellar-gemini-ai-chatapp-backend:v0.1 -f ./server/Dockerfile ./server
docker tag stellar-gemini-ai-chatapp-backend:v0.1 ghcr.io/stellarstack/stellar-gemini-ai-chatapp-backend:v0.1
docker push ghcr.io/stellarstack/stellar-gemini-ai-chatapp-backend:v0.1Build and push frontend:
docker build -t stellar-gemini-ai-chatapp-frontend:v0.1 -f ./client-fe/Dockerfile ./client-fe
docker tag stellar-gemini-ai-chatapp-frontend:v0.1 ghcr.io/stellarstack/stellar-gemini-ai-chatapp-frontend:v0.1
docker push ghcr.io/stellarstack/stellar-gemini-ai-chatapp-frontend:v0.1- Double-check your
GHCR_TOKEN_RWsecret is set correctly - Make sure you enabled "Read and write permissions" in Actions settings
- Go back to Google Cloud Console
- Add your exact Nexlayer URL to the authorized redirect URIs
- Make sure there are no typos in your app name
- Double-check your Gemini API key in
nexlayer.yaml - Make sure you copied the entire key without extra spaces
- Verify the key works by testing it in Google AI Studio
- Check that both
server/andclient-fe/folders havepackage.jsonfiles - Make sure you ran
npm installin both directories - Look at the GitHub Actions logs for specific error messages
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Run tests:
npm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting
We provide issue templates for:
- Environment Setup Guide - Detailed environment configuration
- Contributing Guidelines - How to contribute to the project
- Code of Conduct - Community guidelines
- Changelog - Version history and updates
- Privacy Policy - Privacy and data handling
- Disclaimer - Legal disclaimers
- π Secure Authentication
- π€ AI-Powered Chat
- π± Responsive Design
- π Real-time Updates
- π Analytics Integration
- π Location Services
- π³ Docker Support
- π Advanced Search
- π Chat History
- β‘ Performance Optimized
- π§ͺ Comprehensive Testing
- π CI/CD Pipeline
- π API Documentation
- π Multi-environment Support
Now that your app is live, here are some exciting directions to explore:
- React (Frontend): Build interactive user interfaces
- Express.js (Backend): Create REST APIs
- MongoDB (Database): Store and query data efficiently
- Add more AI features (image generation, text-to-speech)
- Improve user experience (real-time chat, push notifications)
- Scale your app (caching, rate limiting, monitoring)
- Build a todo app with real-time collaboration
- Create an e-commerce site with payments
- Make a social media platform
- Build a dashboard for data visualization
For detailed documentation, visit our Nexlayer Docs.
- Documentation: Environment Setup Guide
- Issues: GitHub Issues
- Email: [email protected]
- Community: GitHub Discussions
This template is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini AI for providing the AI capabilities
- Nexlayer for the deployment platform
- React and Express.js communities
- All contributors and supporters of this project
Built with β€οΈ using the StellarStackLtd AI Chat Template
