Skip to content

Commit c1ede3d

Browse files
Initial commit
0 parents  commit c1ede3d

29 files changed

+2031
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "OctoFit Tracker App codespace",
3+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/github-cli:1": {},
7+
"ghcr.io/devcontainers/features/node:1": {
8+
"version": "lts",
9+
"pnpmVersion": "latest",
10+
"nvmVersion": "latest"
11+
}
12+
},
13+
"postCreateCommand": "sudo chmod +x ./.devcontainer/post_create.sh && ./.devcontainer/post_create.sh",
14+
"postStartCommand": "sudo chmod +x ./.devcontainer/post_start.sh && ./.devcontainer/post_start.sh",
15+
"customizations": {
16+
"vscode": {
17+
"extensions": [
18+
"github.copilot", // GitHub Copilot + Copilot Chat
19+
"markdown-lint.markdownlinter",
20+
"ms-python.python", // Python extension
21+
"ms-python.vscode-pylance", // Pylance extension for Python
22+
"ms-python.debugpy" // Debugpy extension for Python
23+
],
24+
"settings": {
25+
"chat.agent.enabled": true,
26+
}
27+
}
28+
},
29+
"forwardPorts": [
30+
3000, // React default port
31+
8000, // Django default port
32+
27017 // MongoDB default port
33+
],
34+
"portAttributes": {
35+
"3000": { // React port attributes
36+
"label": "octofit-tracker",
37+
"requireLocalPort": true
38+
},
39+
"8000": { // Django port attributes
40+
"label": "octofit-api",
41+
"requireLocalPort": true
42+
}
43+
}
44+
}

.devcontainer/post_create.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# This script is run after the container is created.
3+
# It is used to install any additional dependencies or perform any setup tasks.
4+
5+
wget -qO - https://pgp.mongodb.com/server-6.0.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/mongodb-server-6.0.gpg > /dev/null
6+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
7+
sudo apt-get update
8+
sudo apt-get install -y python3-venv
9+
sudo apt-get install -y mongodb-org
10+
sudo mkdir -p /usr/local/etc/vscode-dev-containers
11+
sudo cp --force ./.devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt

.devcontainer/post_start.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
# This script is run after the container starts up.
3+
4+
set -euo pipefail
5+
6+
die() {
7+
echo "ERROR: $@" >&2
8+
exit 1
9+
}
10+
11+
# Ensure CODESPACE_NAME is set
12+
: "${CODESPACE_NAME:?CODESPACE_NAME environment variable not set. This script should be run in a GitHub Codespace environment.}"
13+
14+
# Port visibility setup
15+
echo "Setting port visibility..."
16+
gh cs ports visibility 8000:public -c "$CODESPACE_NAME" || die "Failed to set 8000 public"
17+
gh cs ports visibility 3000:public -c "$CODESPACE_NAME" || die "Failed to set 3000 public"
18+
19+
echo "Preparing MongoDB data dir..."
20+
sudo mkdir -p /data/db || die "mkdir failed"
21+
sudo chmod 777 /data/db || die "chmod failed"
22+
23+
LOGFILE=/tmp/mongod.log
24+
MAX_START_TRIES=3 # How many times to attempt (re)starting mongod
25+
READY_CHECK_RETRIES=15 # How many readiness checks per start attempt
26+
READY_CHECK_INTERVAL=1 # Seconds between readiness checks
27+
is_running() {
28+
pgrep -x mongod >/dev/null 2>&1
29+
}
30+
31+
start_mongod() {
32+
if is_running; then
33+
echo "mongod already running"
34+
return 0
35+
fi
36+
# Clean old log (keep last one for inspection)
37+
> "$LOGFILE"
38+
echo "Launching mongod (dbpath=/data/db, log=$LOGFILE)..."
39+
mongod --dbpath /data/db --fork --logpath "$LOGFILE"
40+
}
41+
42+
ready_check() {
43+
# Success if log shows ready OR port is open
44+
if grep -q "Waiting for connections" "$LOGFILE" 2>/dev/null; then
45+
return 0
46+
fi
47+
if command -v nc >/dev/null 2>&1; then
48+
if nc -z 127.0.0.1 27017 2>/dev/null; then
49+
return 0
50+
fi
51+
fi
52+
# If mongo/mongosh client exists, try a ping (quietly)
53+
if command -v mongosh >/dev/null 2>&1; then
54+
mongosh --quiet --eval 'db.runCommand({ping:1})' >/dev/null 2>&1 && return 0 || true
55+
elif command -v mongo >/dev/null 2>&1; then
56+
mongo --quiet --eval 'db.runCommand({ping:1})' >/dev/null 2>&1 && return 0 || true
57+
fi
58+
return 1
59+
}
60+
61+
wait_for_ready() {
62+
for ((i=1; i<=READY_CHECK_RETRIES; i++)); do
63+
if ready_check; then
64+
echo "mongod is ready (after $i checks)."
65+
return 0
66+
fi
67+
sleep "$READY_CHECK_INTERVAL"
68+
done
69+
return 1
70+
}
71+
72+
echo "Starting MongoDB with retries..."
73+
for ((attempt=1; attempt<=MAX_START_TRIES; attempt++)); do
74+
echo "Start attempt $attempt/$MAX_START_TRIES"
75+
if start_mongod; then
76+
if wait_for_ready; then
77+
tail -20 "$LOGFILE" || true
78+
echo "MongoDB started successfully."
79+
break
80+
else
81+
echo "Readiness check failed for attempt $attempt."
82+
fi
83+
else
84+
echo "mongod launch command failed on attempt $attempt."
85+
fi
86+
87+
if (( attempt == MAX_START_TRIES )); then
88+
tail -40 "$LOGFILE" || true
89+
die "MongoDB failed to start after $MAX_START_TRIES attempts"
90+
fi
91+
92+
echo "Cleaning up before next attempt..."
93+
if is_running; then
94+
pkill -x mongod || true
95+
sleep 2
96+
fi
97+
done
98+
99+
echo "post_start.sh completed successfully."
100+
exit 0

.devcontainer/welcome-message.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
👋 Welcome to building a multi-tier fitness tracker application with GitHub Copilot agent mode!
2+
We are thrilled that you are here and we hope you are excited to explore the capabilities of Copilot!
3+
🏋🏽🔥💪🏼🎧 As the gym teacher of Mergington High School you have been tasked with building a fitness app for your students.
4+
📃 GitHub Copilot documentation: https://docs.github.com/en/copilot
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
applyTo: "octofit-tracker/backend/**"
3+
---
4+
# Octofit-tracker Fitness App Django backend Guidelines
5+
6+
## Django Backend App structure
7+
8+
### settings.py
9+
10+
Should always contain the following:
11+
12+
```python
13+
import os
14+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
15+
if os.environ.get('CODESPACE_NAME'):
16+
ALLOWED_HOSTS.append(f"{os.environ.get('CODESPACE_NAME')}-8000.app.github.dev")
17+
```
18+
19+
## serializers.py
20+
21+
```text
22+
serializers should convert ObjectId fields to strings
23+
```
24+
25+
## REST API Endpoints
26+
27+
```text
28+
use curl to test the endpoints
29+
```
30+
31+
### urls.py
32+
33+
Should always use the codespace environment variable for the URL
34+
35+
```python
36+
import os
37+
codespace_name = os.environ.get('CODESPACE_NAME')
38+
if codespace_name:
39+
base_url = f"https://{codespace_name}-8000.app.github.dev"
40+
else:
41+
base_url = "http://localhost:8000"
42+
43+
urlpatterns = [
44+
path('admin/', admin.site.urls),
45+
path('api/', api_root, name='api-root'),
46+
path('api/', include(router.urls)),
47+
]
48+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
applyTo: "octofit-tracker/**"
3+
---
4+
# Octofit-tracker Fitness App React frontend Guidelines
5+
6+
## REACT Frontend App structure
7+
8+
Make sure in all commands we point to the `octofit-tracker/frontend` directory
9+
10+
```bash
11+
npx create-react-app octofit-tracker/frontend --template cra-template --use-npm
12+
13+
npm install bootstrap --prefix octofit-tracker/frontend
14+
15+
# Add the Bootstrap CSS import at the very top of src/index.js:
16+
sed -i "1iimport 'bootstrap/dist/css/bootstrap.min.css';" octofit-tracker/frontend/src/index.js
17+
18+
npm install react-router-dom --prefix octofit-tracker/frontend
19+
20+
```
21+
22+
## Images for the OctoFit Tracker App
23+
24+
The image to use for the app is in the root of this repository docs/octofitapp-small.png
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
applyTo: "**"
3+
---
4+
# Octofit-tracker Fitness App Setup and Structure Guidelines
5+
6+
## Explain the Octofit Tracker App goals and steps
7+
8+
I want to build an Octofit Tracker app that will include the following:
9+
10+
* User authentication and profiles
11+
* Activity logging and tracking
12+
* Team creation and management
13+
* Competitive leader board
14+
* Personalized workout suggestions
15+
16+
## Never change directories when agent mode is running commands
17+
18+
- Never change directories
19+
- Instead point to the directory when issuing commands
20+
21+
## Forwarded ports
22+
23+
- 8000: public
24+
- 3000: public
25+
- 27017: private
26+
27+
Do not propose any other ports to forward or to make public
28+
29+
## OctoFit Tracker App structure
30+
31+
The section defines the OctoFit Tracker App's structure
32+
33+
```text
34+
octofit-tracker/
35+
├── backend/
36+
│ ├── venv/
37+
| ├── octofit_tracker/
38+
└── frontend/
39+
```
40+
41+
## Create the OctoFit Tracker Python virtual environment
42+
43+
- To create the virtual environment, run the following command:
44+
45+
```bash
46+
python3 -m venv octofit-tracker/backend/venv
47+
```
48+
49+
## OctoFit Tracker Python required packages
50+
51+
### Create file octofit-tracker/backend/requirements.txt
52+
53+
- add the following to octofit-tracker/backend/requirements.txt
54+
- Install the Python packages below only for our OctoFit Tracker project
55+
56+
```text
57+
Django==4.1.7
58+
djangorestframework==3.14.0
59+
django-allauth==0.51.0
60+
django-cors-headers==4.5.0
61+
dj-rest-auth==2.2.6
62+
djongo==1.3.6
63+
pymongo==3.12
64+
sqlparse==0.2.4
65+
stack-data==0.6.3
66+
sympy==1.12
67+
tenacity==9.0.0
68+
terminado==0.18.1
69+
threadpoolctl==3.5.0
70+
tinycss2==1.3.0
71+
tornado==6.4.1
72+
traitlets==5.14.3
73+
types-python-dateutil==2.9.0.20240906
74+
typing_extensions==4.9.0
75+
tzdata==2024.2
76+
uri-template==1.3.0
77+
urllib3==2.2.3
78+
wcwidth==0.2.13
79+
webcolors==24.8.0
80+
webencodings==0.5.1
81+
websocket-client==1.8.0
82+
```
83+
84+
## Python virtual environment requirements
85+
86+
Create a requirements.txt with the following Python required packages:
87+
Install the requirements that we created in requirements.txt.
88+
89+
```bash
90+
source octofit-tracker/backend/venv/bin/activate
91+
pip install -r octofit-tracker/backend/requirements.txt
92+
```
93+
94+
## mongodb-org service and data creation
95+
96+
- always use `ps aux | grep mongod` for checking for mongod running
97+
- mongodb-org is the official MongoDB package
98+
- mongosh is the official client tool
99+
- Always use Django's ORM, not direct MongoDB scripts to create the database structure and data
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
mode: 'agent'
3+
model: GPT-4.1
4+
description: 'Create a Django project, start it, and run it'
5+
---
6+
7+
Your task is to create the Django project in octofit-tracker/backend/octofit_tracker directory using the Python
8+
virtual environment we already created in directory octofit-tracker/backend/venv which contains all the prerequisites.
9+
10+
11+
To create the Django project follow these steps.
12+
1. Make sure we are in the root directory and don't change directories
13+
2. source octofit-tracker/backend/venv/bin/activate
14+
3. django-admin startproject octofit_tracker in the octofit-tracker/backend directory
15+
4. python manage.py migrate
16+
5. Instruct the user to run the django app from the .vscode/launch.json configuration that is in the repository
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
mode: 'agent'
3+
model: GPT-4.1
4+
description: 'Setup, configure, and populate the octofit_db database with test data for the Octofit Tracker Django app.'
5+
---
6+
7+
# Environment Setup
8+
- Use the existing Python virtual environment in `octofit-tracker/backend/venv`.
9+
- Do not create a new Python virtual environment.
10+
- Activate with: `source octofit-tracker/backend/venv/bin/activate`
11+
- `mongodb-org-shell` is already installed; use `mongosh` to interact with MongoDB.
12+
- The Django project is in `octofit-tracker/backend/octofit_tracker`.
13+
14+
# Database Initialization & Population
15+
1. Ensure the MongoDB service is running.
16+
2. Configure Django in `settings.py` to connect to the `octofit_db` database using Djongo, with no authentication or password required.
17+
3. Make sure `octofit_tracker`, `rest_framework`, and `djongo` are in `INSTALLED_APPS`.
18+
4. Enable CORS in `settings.py` to allow all origins, methods, and headers. Allow all hosts `*`.
19+
5. Install and configure CORS middleware components.
20+
6. Run `makemigrations` and `migrate` in the Python virtual environment.
21+
7. Initialize the `octofit_db` database and create collections for users, teams, activities, leaderboard, and workouts.
22+
8. Ensure a unique index on the `email` field for the user collection (e.g., `db.users.createIndex({ "email": 1 }, { unique: true })`).
23+
9. Populate the database with test data for all collections using the Django management command in `octofit-tracker/backend/octofit_tracker/management/commands/populate_db.py`
24+
a. help message: 'Populate the octofit_db database with test data'.
25+
b. Django ORM for data deletion and insertion
26+
c. Make the sample data super heroes and use team marvel and team dc.
27+
10. Verify the database and collections were created and populated successfully using `mongosh`.
28+
11. List the collections in the `octofit_db` database and show sample documents from each.
29+
30+
# Verification
31+
- After population, verify with `mongosh` that the `octofit_db` database contains the correct collections and test data.
32+
- Confirm Django REST API endpoints are available for all collections.

0 commit comments

Comments
 (0)