
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"},

The purpose of life is to live fully and explore every aspect of existence. The search for a higher, god-given purpose often leads to harm and neglect of life itself. The need for purpose stems from our psychological structure, not the process of life. Achieving balance allows us to dismantle the walls of our psychological maze and experience freedom. This exploration and understanding of all dimensions of life is the true purpose of life.
Beiryu
Contributor

Microservices have become a popular architectural style for building large-scale and complex applications. One of the key aspects of microservices is how they communicate with each other. In this blog post, we'll explore different communication patterns used in microservices and take a closer look at REST APIs, which are widely used for inter-service communication. We'll also discuss the advantages and disadvantages of using REST APIs based on my experience in a current project.
Beiryu
Contributor