This repository is the main backend for the startup template. For reference implementations, check out our other templates:
Description ๐
A NestJS-based backend API template designed to power AI learning and conversation applications. This project serves as the backend infrastructure for an interactive platform that demonstrates advanced AI conversation features and Ionic mobile development.
๐ฏ Key Features:
- AI conversation management
- Google Cloud Services integration
- Scalable architecture for learning applications
- Ready-to-use authentication system
๐ก Note: While the project is tightly integrated with Google Cloud services, these modules can be easily removed if not needed.
Getting Started ๐
Clone the Project
git clone https://github.com/dataclouder-dev/startup-template-node [your-project-name]
or use the button on github right top corner CREATE TEMPLATE
โ Prerequisites
- node >= 22.0.0
- Make >= 3.0.0 (Optional but highly recommended)
- Docker (Optional)
- Env File, rename .env.example to .env and add your environment variables
- Google Cloud credentials and environment variables- Service account credentials go to:
- If you created a firebase project you already have the Google Cloud, got to the link https://console.cloud.google.com/iam-admin/serviceaccounts?project=[your-project-id] and create a service account
- Give Editor Permissions (Unless you know what you are doing then give minimal privileges) and download the json file
- Copy in .cred/keys.json
- MongoDB credentials
- Get the mongo variables, will be easy if you extract from conection string and copy in .env
- example mongodb+srv://admin:MyPass1234@cluster0.5q5kdhg.mongodb.net/my_db_name
- MONGO_USER=admin
- MONGO_PASS=MyPass1234
- MONGO_HOST=cluster0.5q5kdhg.mongodb.net
- MONGO_DB=my_db_name
Initial Setup
- Clone the repository
- Configure your environment:
- Copy
.env.exampleto.env - Add your environment variables
- Create
.credfolder and add Google Cloud credentials
- Copy
- Customize the user model for your needs
Development ๐ป
Install Dependencies
Run the Project
# Development mode npm run start # Watch mode (recommended for development) npm run start:dev # Production mode npm run start:prod
Testing ๐งช
# Unit tests npm run test # End-to-end tests npm run test:e2d # Test coverage npm run test:cov
Customization ๐ ๏ธ
User and Firebase
You can handle users easialy, create google credentials, for Gcp service, firebase included, and save in .cred/keys.json, check .env.example for variables you may need.
GOOGLE_APPLICATION_CREDENTIALS=./.cred/keys.json
Module Management
You can remove unnecessary modules by:
- Deleting the module folder
- Removing the import from
app.module.ts
Deployment ๐
Local Docker Testing
Before deploying, test locally with Docker:
docker build -t dc-template-node .
docker run -p 8080:8080 --env-file ./.env dc-template-nodeDocker Compose
For a quick setup using the pre-built image from GHCR:
This will start the container using ghcr.io/adamofig/dataclouder-dev-node:latest.
- Port: Access the app at
http://localhost:7991(configurable viaHOST_PORTin.env). - Configuration: Ensure you have your
.envfile and.cred/key-qa.jsonready.
Cloud Deployment
Manual Deployment Steps
-
Authenticate with Google Cloud:
-
Submit the build: i recommend use the make commands i created to automate, but you can use manual gcloud commands if you have the knowledge.
-
First set environments in makefile or .env, you can leave IMAGE_NAME, REGION, SERVICE_NAME, but PROJECT_ID is uniqui to your project
make gcp-enable-services # will ask to enable bill on GCP this is required to deploy make build-push # make deploy-service
-
Next time you can just run:
Automated Deployment With Cloud Build
Note: before try to automate the deployment, i highly recommend do one manual deployment to check if everything is working. specially becouse for every cloud run service, variables need to be set first time, consicutive times no need.
- Fork the repository
- Go to cloud build and create a new trigger
- Grant github access, select the repository and accept conditions
- Add seetings for the trigger to your needs
- Optional: Add permissions to the service account, Logs Writer, Cloud Run Admin or log only default logs
- Add the repository in artifact registry (recommended add policies to remove old versions)
Example Deployment Command
gcloud builds submit --tag gcr.io/ai-learning-dev/node-app-image .
gcloud run deploy ai-learning-service \
--image gcr.io/ai-learning-dev/node-app-image \
--platform managed \
--region us-central1 \
--allow-unauthenticatedClone and Reuse template for new projects
git clone https://github.com/adamofig/dataclouder-template-node [new-project-name]
cd [new-project-name]
npm installUnistall what you don't need
npm uninstall @dataclouder/conversation-card-nestjs @dataclouder/lessons-nestjs @dataclouder/storage-uploader
remove module from app module. you are ready to go.
Contributing ๐ค
Contributions are welcome! Please feel free to submit a Pull Request.
License ๐
MIT License