-
Notifications
You must be signed in to change notification settings - Fork 0
Add React + Flask full-stack scaffold #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/setup-flask-api-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
877be67
Initial plan
Copilot 03b8de0
Add React frontend with Flask API backend
Copilot a83cc79
Merge branch 'main' into copilot/setup-flask-api-backend
lloydmckie-lang 7288e06
feature: point to new frontend build
lloyd-mc 06a928f
fix: build
lloyd-mc fee4b03
docs: add copilot instructions file
lloyd-mc 30e1a6c
Merge branch 'main' into copilot/setup-flask-api-backend
lloydmckie-lang d5b6ccf
fix: contributing guidelines to match new project folders
lloyd-mc e185b9b
Merge branch 'main' into copilot/setup-flask-api-backend
lloydmckie-lang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copilot Instructions for `github-agentic-workflows` | ||
|
|
||
| ## Big picture architecture | ||
| - This is a **2-part app**: Flask API in `backend/` and React (Vite) UI in `frontend/`. | ||
| - UI talks to API via relative `/api/*` calls (see `frontend/src/App.jsx`). | ||
| - Vite dev server proxies `/api` to `http://localhost:5000` (see `frontend/vite.config.js`), so frontend code should not hardcode backend hostnames. | ||
| - Backend state is currently **in-memory** (`items`, `next_id` in `backend/app.py`), so data resets on server restart. | ||
|
|
||
| ## Service boundaries and data flow | ||
| - API routes are in `backend/app.py`: | ||
| - `GET /api/health` | ||
| - `GET /api/items` | ||
| - `POST /api/items` with body `{ "name": string }` | ||
| - `DELETE /api/items/<id>` | ||
| - Frontend behavior in `frontend/src/App.jsx` mirrors these endpoints: | ||
| - initial load -> `fetch('/api/items')` | ||
| - add -> `POST /api/items` | ||
| - delete -> `DELETE /api/items/:id` | ||
| - Keep request/response shapes aligned across both layers when changing endpoints. | ||
|
|
||
| ## Critical workflows (local) | ||
| - Backend setup/run: | ||
| - `cd backend && pip install -r requirements.txt` | ||
| - `python app.py` | ||
| - Frontend setup/run: | ||
| - `cd frontend && npm install` | ||
| - `npm run dev` | ||
| - Frontend quality gates: | ||
| - `npm run lint` | ||
| - `npm run build` | ||
| - `npm test` | ||
| - Backend tests: | ||
| - `cd backend && python -m pytest test_app.py -v` | ||
|
|
||
| ## CI/CD behavior to respect | ||
| - GitHub Actions build job in `.github/workflows/build-deploy.yml` runs from `frontend/` using Node 20. | ||
| - CI currently installs with `npm ci` and runs `npm run build` (not frontend lint/test, and not backend tests). | ||
| - If you add required checks, ensure workflow updates stay consistent with existing `frontend/` working-directory assumptions. | ||
|
|
||
| ## Project-specific patterns | ||
| - Frontend tests mock `global.fetch` directly (`frontend/src/test/App.test.jsx`) and use Testing Library + Vitest. | ||
| - Test environment is configured in `frontend/vite.config.js` with `jsdom` and `frontend/src/test/setup.js`. | ||
| - Flask tests reset mutable module globals before each test (`reset_items` fixture in `backend/test_app.py`). Preserve this pattern when adding backend tests around global state. | ||
|
|
||
| ## Integration and change guidance | ||
| - For API changes, update **all three** together: | ||
| 1) `backend/app.py` routes/validation, | ||
| 2) `frontend/src/App.jsx` fetch calls/UI handling, | ||
| 3) tests in `backend/test_app.py` and/or `frontend/src/test/App.test.jsx`. | ||
| - Prefer small, vertical changes (API + UI + tests) over partial edits to avoid broken contract states. | ||
| - Keep paths and folder naming as-is (`backend/`, `frontend/`); root `README.md` documents this layout and should be updated if commands/structure change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import os | ||
| from flask import Flask, jsonify, request | ||
| from flask_cors import CORS | ||
|
|
||
| app = Flask(__name__) | ||
| CORS(app) | ||
|
|
||
| # In-memory store for items | ||
| items = [ | ||
| {"id": 1, "name": "Item One"}, | ||
| {"id": 2, "name": "Item Two"}, | ||
| ] | ||
| next_id = 3 | ||
|
|
||
|
|
||
| @app.route("/api/health", methods=["GET"]) | ||
| def health(): | ||
| """Health check endpoint.""" | ||
| return jsonify({"status": "ok"}) | ||
|
|
||
|
|
||
| @app.route("/api/items", methods=["GET"]) | ||
| def get_items(): | ||
| """Return all items.""" | ||
| return jsonify(items) | ||
|
|
||
|
|
||
| @app.route("/api/items", methods=["POST"]) | ||
| def create_item(): | ||
| """Create a new item.""" | ||
| global next_id | ||
| data = request.get_json() | ||
| if not data or not data.get("name"): | ||
| return jsonify({"error": "name is required"}), 400 | ||
| item = {"id": next_id, "name": data["name"]} | ||
| next_id += 1 | ||
| items.append(item) | ||
| return jsonify(item), 201 | ||
|
|
||
|
|
||
| @app.route("/api/items/<int:item_id>", methods=["DELETE"]) | ||
| def delete_item(item_id): | ||
| """Delete an item by id.""" | ||
| global items | ||
| original_len = len(items) | ||
| items = [i for i in items if i["id"] != item_id] | ||
| if len(items) == original_len: | ||
| return jsonify({"error": "item not found"}), 404 | ||
| return jsonify({"deleted": item_id}) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| debug = os.environ.get("FLASK_DEBUG", "false").lower() == "true" | ||
| app.run(debug=debug, port=5000) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| flask>=3.1.0 | ||
| flask-cors>=5.0.0 | ||
| pytest>=8.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import pytest | ||
| from app import app, items | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def reset_items(): | ||
| """Reset items list and next_id before each test.""" | ||
| import app as app_module | ||
| app_module.items = [ | ||
| {"id": 1, "name": "Item One"}, | ||
| {"id": 2, "name": "Item Two"}, | ||
| ] | ||
| app_module.next_id = 3 | ||
| yield | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| app.config["TESTING"] = True | ||
| with app.test_client() as client: | ||
| yield client | ||
|
|
||
|
|
||
| def test_health(client): | ||
| response = client.get("/api/health") | ||
| assert response.status_code == 200 | ||
| assert response.get_json() == {"status": "ok"} | ||
|
|
||
|
|
||
| def test_get_items(client): | ||
| response = client.get("/api/items") | ||
| assert response.status_code == 200 | ||
| data = response.get_json() | ||
| assert len(data) == 2 | ||
| assert data[0]["name"] == "Item One" | ||
|
|
||
|
|
||
| def test_create_item(client): | ||
| response = client.post("/api/items", json={"name": "New Item"}) | ||
| assert response.status_code == 201 | ||
| data = response.get_json() | ||
| assert data["name"] == "New Item" | ||
| assert "id" in data | ||
|
|
||
|
|
||
| def test_create_item_missing_name(client): | ||
| response = client.post("/api/items", json={}) | ||
| assert response.status_code == 400 | ||
| assert "error" in response.get_json() | ||
|
|
||
|
|
||
| def test_delete_item(client): | ||
| response = client.delete("/api/items/1") | ||
| assert response.status_code == 200 | ||
| assert response.get_json()["deleted"] == 1 | ||
|
|
||
|
|
||
| def test_delete_item_not_found(client): | ||
| response = client.delete("/api/items/999") | ||
| assert response.status_code == 404 | ||
| assert "error" in response.get_json() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/grumpy