· 4 min read

Creating GradumAcademy

Last updated

GradumAcademy is a company founded by two of my former college soccer teammates and my brother.

Their mission

“Our mission is to advance the evaluation and preparation of aspiring collegiate and professional soccer players aged 14 and up, by coupling traditional, subjective assessment, with cutting-edge technology to more accurately analyze physiological and soccer-specific metrics.”

Technology Needs

The goal of this application, or set of applications, is to centralize managing athletes, parents, and coach information all in a single place.

Data being tracked

  • Polar heart rate data during training sessions

Communications

  • Notes on
    • recruitment status from colleges
    • from coaches to coaches,
    • coaches to athletes
    • coaches to parents?
  • Progress notes

Training plans

  • Weekly/monthly plans

Python API Setup

  1. Create python-api directory
  • Base files (main.py, requirements.txt, .env, Dockefile, .gitignore)
  1. Install FastAPI locally

Set up a virtual environment

python3 -m venv venv
source venv/bin/activate

Install FastAPI and Uvicorn

pip install fastapi uvicorn python-dotenv

Save dependencies to requirements.txt

pip freeze > requirements.txt
  1. Write initial API code
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

# A sample model for POST requests
class DataModel(BaseModel):
    id: int
    name: str

@app.get("/")
def read_root():
    return {"message": "Hello from Python FastAPI!"}

@app.get("/health")
def read_health():
    return {"message": "OK"}

@app.post("/data/")
def create_data(data: DataModel):
    return {"message": f"Received data with id: {data.id} and name: {data.name}"}

Add environment variables to .env

  1. Run the API locally
uvicorn main:app --reload --host 0.0.0.0 --port 8000
  1. Containerize the API with Docker
// python-api/Dockerfile

# Use a slim Python image for lightweight builds
FROM python:3.10-slim

# Set the working directory
WORKDIR /app

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Expose the application port
EXPOSE 8000

# Run the FastAPI application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
  1. Build and Run with Docker
docker build -t python-api .
docker run -d -p 8000:8000 --env-file .env python-api
  1. Verify the API

Access API vis http://localhost:8000

Docs: http://localhost:8000/docs


Go Setup

  1. Create directory and initial file structure
go-api/
├── main.go
├── go.mod
├── .env
├── Dockerfile
├── .gitignore
  1. Initialize the Go Project

Since this is my first time using go, I need to download the go installer and install it on my mac. Search for go download in your browser and download the mac install package (or appropriate package for your system). We’re using the current stable version.

Initialize a new Go module

go mod init go-api

Install the Fiber framework for go

go get github.com/gofiber/fiber/v2

Add Fiber’s logger middleware

go get github.com/gofiber/fiber/v2/middleware/logger
  1. Write the initial API code
package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/logger"
)

func main() {
	app := fiber.New()

	// Add middleware
	app.Use(logger.New())

	// Root route
	app.Get("/", func(c *fiber.Ctx) error {
		return c.JSON(fiber.Map{"message": "Hello from Go Fiber API!"})
	})

	// Example POST route
	app.Post("/data", func(c *fiber.Ctx) error {
		type Request struct {
			ID   int    `json:"id"`
			Name string `json:"name"`
		}

		var req Request
		if err := c.BodyParser(&req); err != nil {
			return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse JSON"})
		}

		return c.JSON(fiber.Map{"message": "Received data", "data": req})
	})

	// Start server
	app.Listen(":8080")
}

Add environment variables

APP_ENV=development
PORT=8080
  1. Run the API locally
go run main.go

Access the API

http://127.0.0.1:8080

  1. Containerize the API with Docker
FROM golang:1.23
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /docker-gs-ping
EXPOSE 8080
CMD ["/docker-gs-ping"]
  1. Build and Run with Docker
docker build -t go-api .
docker run -d -p 8080:8080 --env-file .env go-api

Local Terraform

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Check that terraform installed properly

terraform version

AWS CLI

brew install awscli

AWS

Create User with programmatic access.

  • This will be a temporary admin user to allow for initial creation. We’ll change this later.

Create access key for this user based on the use case

  • CLI

Run aws configure to connect to AWS from cli

This will store your aws credentials on your computer at ~/.aws/credentials

You can vi ~/.aws.credentials to check that it’s correct, or code ~/.aws.credentials if you’re using vscode and have the code command set up.

Your selected region and output format are stored in ~/.aws/config.

Enable AWS Permissions

Make sure to attach policies to your user/user group depending on your needs.

You can verify your IAM identity using

aws sts get-caller-identity

Terraform AWS Provider Configuration

Create a directory for your terraform project

Cd into that directory

Initialize terraform with terraform init

Create a main.tf file

terraform init to set up the required plugins

terraform validate to make sure the configuration is valid

terraform plan to generate an execution plan to review what terraform will do

AWS Buckets

aws s3api create-bucket --bucket frontend --region us-east-1
aws s3api create-bucket --bucket app-api-1 --region us-east-2
aws s3api create-bucket --bucket app-api-2 --region us-east-3
aws s3api create-bucket --bucket app-api-3 --region us-east-4

aws s3api put-bucket-versioning --bucket frontend --versioning-configuration Status=Enabled
aws s3api put-bucket-versioning --bucket api-1 --versioning-configuration Status=Enabled
aws s3api put-bucket-versioning --bucket api-2 --versioning-configuration Status=Enabled
aws s3api put-bucket-versioning --bucket api-3 --versioning-configuration Status=Enabled

Verify buckets

aws s3 ls

Create VPC

Create Subnets

Create tags for subnets