Skip to content

Commit b51a19b

Browse files
adrian-rpfCopilot
andauthored
Add Initial Copilot instructions for editor-api (#589)
## Status - Gives a first draft of a copilot instructions to help improve the usefulness of GH Copilot ## Points for consideration: ✅ - Security - repo only document ✅ - Performance - repo only document ## What's changed? - Creation of a new copilot instructions file. ## Steps to perform after deploying to production ✅ - no deployments requirement <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Add a repository Copilot guide outlining architecture, APIs, auth/authorization, conventions, workflows, env vars, and example usages. > > - **Documentation**: > - **New file**: `.github/copilot-instructions.md` with a concise guide for Copilot. > - Architecture: REST/GraphQL surfaces, authentication (OIDC/Bearer), authorization via `cancancan`, domain ops (`lib/concepts/**`), jobs (GoodJob), integrations (Profile/UserInfo/GitHub), storage/CORS. > - Conventions: GraphQL context/IDs, locale fallbacks, Jbuilder shapes, REST pagination, project rules, remix behavior, error handling. > - Developer workflows: Docker setup/run/test, seeds, DB sync, gem updates. > - Env vars: Postgres, Hydra/identity, external APIs, webhooks, CORS/S3, local dev flags. > - Examples: REST endpoints and GraphQL query snippets. > - Pointers: key files/paths for routes, auth, permissions, domain models, API views, GraphQL. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit fae2681. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9216d3f commit b51a19b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/copilot-instructions.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copilot instructions for editor-api
2+
3+
This repo is a Rails 7.1 exposing REST and GraphQL APIs for the Raspberry Pi Foundation Code Editor and Code Editor for Education features.
4+
5+
Architecture and boundaries
6+
- HTTP surfaces: REST under `app/controllers/api/**` (responses via jbuilder in `app/views/api/**`) and GraphQL at `/graphql` (schema in `app/graphql/**`).
7+
- Authentication: Browser/session via OmniAuth (OIDC to Hydra) in `config/initializers/omniauth.rb` and `AuthController`; API token via `Authorization: Bearer <token>` with lookup in `Identifiable#identify_user``User.from_token``HydraPublicApiClient`.
8+
- Authorization: `cancancan` in `app/models/ability.rb`. Permissions differ for students/teachers/owners/admin. Use `load_and_authorize_resource` in controllers and `Types::ProjectType.authorized?` plus `GraphqlController` context `current_ability` for GraphQL.
9+
- Domain: `Project` (+ `Component`) with attachments (`images/videos/audio` via Active Storage). Higher-level operations live under `lib/concepts/**` (e.g., `Project::Create`, `Project::Update`, `Project::CreateRemix`). Prefer calling these from controllers/mutations.
10+
- Jobs: GoodJob (`config/initializers/good_job.rb`, Procfile `worker`). Admin UI is mounted at `/admin/good_job` and gated by `AuthenticationHelper#current_user.admin?`.
11+
- Integrations: Profile API (`lib/profile_api_client.rb`) for schools/students and safeguarding flags; UserInfo API for user detail fan-out; GitHub GraphQL client in `lib/github_api.rb`; GitHub webhooks via `GithubWebhooksController` trigger `UploadJob` when `ref == ENV['GITHUB_WEBHOOK_REF']` and files under `*/code/` change.
12+
- Storage/CORS: Active Storage uses S3 in non-dev; `config/initializers/cors.rb` and `lib/origin_parser.rb` parse `ALLOWED_ORIGINS`. `CorpMiddleware` sets CORP for Active Storage routes.
13+
14+
Key conventions and patterns
15+
- GraphQL context includes: `current_user`, `current_ability`, and `remix_origin` (see `GraphqlController`). Max depth/complexity guard rails in `EditorApiSchema`.
16+
- GraphQL object IDs use GlobalID; locale fallback for projects via `ProjectLoader` in order `[requested, 'en', nil]`.
17+
- Jbuilder responses: see `app/views/api/projects/show.json.jbuilder` for shape (components, media URLs via `rails_blob_url`, optional `parent`).
18+
- Pagination for REST lists returns HTTP `Link` header (see `Api::ProjectsController#pagination_link_header`).
19+
- Project rules: identifiers unique per locale; default component’s name/extension immutable on update; students cannot update `instructions` on school projects; creating a project within a school auto-builds a `SchoolProject`.
20+
- Remix: `Project::CreateRemix` clones media/components, sets `remix_origin` from `request.origin` and clears `lesson_id`.
21+
- Errors: domain ops return `OperationResponse` with `:error`; controllers return 4xx heads for common cases; GraphQL raises `GraphQL::ExecutionError`. Exceptions are reported to Sentry.
22+
23+
Developer workflows (docker-first)
24+
- Setup: copy `.env.example``.env`. Build with `docker-compose build`. Prepare DB: `docker compose run --rm api rails db:setup`.
25+
- Run: `docker-compose up` (API on http://localhost:3009). GraphiQL available in non-production at `/graphql`.
26+
- Tests: `docker-compose run api rspec` (or pass a spec path). Bullet, WebMock, and RSpec rails are configured in `spec/rails_helper.rb`.
27+
- Seeds: run `projects:create_all` and `for_education:*` Rake tasks (examples in README). Experience CS examples auto-run on release (see Procfile `release`).
28+
- DB sync: scripts in `bin/db-sync/*` pull Heroku backups into your local Docker DB and reset Active Storage to `local`.
29+
- Gems: update inside the builder image with `./bin/with-builder.sh bundle update`.
30+
31+
Important env vars (see `.env.example`)
32+
- Postgres: `POSTGRES_HOST/DB/USER/PASSWORD`. Hydra/identity: `HYDRA_PUBLIC_URL`, `HYDRA_PUBLIC_API_URL`, `HYDRA_PUBLIC_TOKEN_URL`, `HYDRA_CLIENT_ID/SECRET`, `IDENTITY_URL`, `HOST_URL`.
33+
- External APIs: `USERINFO_API_URL/KEY`, `PROFILE_API_KEY`. Webhooks: `GITHUB_WEBHOOK_SECRET`, `GITHUB_WEBHOOK_REF`, optional `GITHUB_AUTH_TOKEN` for GitHub GraphQL.
34+
- CORS/storage: `ALLOWED_ORIGINS`, `AWS_*` (S3). Local auth/dev: `BYPASS_OAUTH=true` to stub identity; `SMEE_TUNNEL` for local webhook relay.
35+
36+
Examples to follow
37+
- REST: `GET /api/projects/:id` resolves by identifier+locale (uses `ProjectLoader`); `POST /api/projects/:project_id/images` attaches files; `POST /api/projects/:project_id/remix` creates a remix (requires auth).
38+
- GraphQL query snippet: `projects(userId: "<uuid>") { edges { node { identifier name components { nodes { name extension } } } } }` and `project(identifier: "abc123") { name images { nodes { filename } } }`.
39+
40+
Where to look first
41+
- Routes: `config/routes.rb`. Auth: `config/initializers/omniauth.rb`, `app/helpers/authentication_helper.rb`, `app/controllers/concerns/identifiable.rb`.
42+
- Permissions: `app/models/ability.rb`. Domain ops: `lib/concepts/**`. Data models: `app/models/**`. API views: `app/views/api/**`. GraphQL types/mutations: `app/graphql/**`.

0 commit comments

Comments
 (0)