
The system will be build on a serverless microservices architecture, primarily utilizing AWS services. This architecture allows for high scalability, cost-effectiveness, and ease of maintenance. The system consists of several interconnected components that work together to deliver a seamless user experience.
The virtual coach is the heart of the AllBlazing system, powered by OpenAI's GPT models. It provides personalized advice, generates fitness challenges, and engages in natural language conversations with users.
pythonclass VirtualCoach:def __init__(self, history=""):self.OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")self.base_data = base_dataset.dataset["qa"]["qa_dataset"]self.persona = base_dataset.dataset["persona"]["tutorial_coach_regular_persona"]self.features = base_dataset.dataset["tutorial_features"]# ... (other initialization code)def call_gpt(self, custom_prompt):# ... (code to call OpenAI API)def create_custom_prompt(self, question):# ... (code to create prompts for the GPT model)
This component interacts with the OpenAI API to generate responses based on user input and context.
The system maintains detailed user profiles, including fitness data, goals, and progress. This information is crucial for providing personalized coaching and tracking improvements over time.
User data is primarily stored in AWS DynamoDB, a NoSQL database that allows for flexible schema and fast retrieval
The application meticulously tracks user activities and health metrics, storing this data in DynamoDB for analysis and progress tracking.
typescriptconst trackActivity = async (userId: string, activityData: ActivityData) => {const enrichedData = await enrichActivityData(activityData);await saveActivityToDatabase(userId, enrichedData);await updateUserStats(userId, enrichedData);};
typescriptconst enrichActivityData = async (activityData: ActivityData) => {const activityType = await detectActivityType(activityData);const caloriesBurned = calculateCaloriesBurned(activityData, activityType);const trainingEffect = calculateTrainingEffect(activityData, activityType);return { ...activityData, activityType, caloriesBurned, trainingEffect };};
typescriptconst syncActivities = async (userId: string, activities: ActivityData[]) => {for (const activity of activities) {await trackActivity(userId, activity);}await notifyUserOfSync(userId);};
typescriptconst generateCoachAdvice = async (userId: string) => {const recentActivities = await getRecentActivities(userId);const userProfile = await getUserProfile(userId);const advice = await callGPTForAdvice(recentActivities, userProfile);return advice;};
typescriptconst updateUserProgress = async (userId: string) => {const activities = await getUserActivities(userId, { last: '30 days' });const progress = calculateProgress(activities);await updateUserProgressInDB(userId, progress);};
typescriptconst updateLeaderboards = async () => {const topRunners = await getTopRunners({ last: '7 days' });await updateLeaderboardInDB('weekly_runners', topRunners);};
typescriptconst generateHealthInsights = async (userId: string) => {const healthMetrics = await getHealthMetrics(userId, { last: '90 days' });const insights = await analyzeHealthTrends(healthMetrics);await saveInsightsToDatabase(userId, insights);};

The application system utilizes the Serverless Framework for efficient deployment and management of AWS resources. This approach simplifies the process of updating and scaling the application as needed.
typescriptimport changeActivityStatus from "@functions/change-activity-status";import chatWithGPT from "@functions/chat-with-gpt";import coachResponse from "@functions/coach-response";// ... (other function imports)// Serverless configuration file
The development environment is set up with npm for package management, including scripts for local development and deployment to different environments:
typescript"scripts": {"test": "echo \"Error: no test specified\" && exit 1","debug": "sls offline start --httpPort 4000 --lambdaPort 4002 --websocketPort 4003 --aws-profile default","deploy": "sls deploy --stage dev --region eu-west-1 --aws-profile default","deploy-prod": "sls deploy --stage prod --region eu-central-1 --aws-profile default"},

This document provides a step-by-step guide on implementing two-factor authentication (2FA) in a NestJS application with ReactJS using Google Authenticator. It covers initializing the NestJS project with basic login password authentication, creating the authentication module, implementing local authentication strategy, adding JWT management, and integrating 2FA. The document includes code snippets and instructions for each step.
Beiryu
Contributor

Trong văn hóa châu Á, đặc biệt là ở Việt Nam, chúng ta thường nghe câu "Có công mài sắt, có ngày nên kim". Điều này hoàn toàn đúng với việc học lập trình. Việc code mỗi ngày, dù chỉ một chút, cũng như giọt nước mưa kiên trì rơi xuống, từng giọt một sẽ tạo nên đại dương mênh mông của kiến thức và kinh nghiệm.
Beiryu
Contributor