You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+41-52Lines changed: 41 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,72 +6,61 @@ This repository contains three interconnected applications:
6
6
2. Backend (dotnet) that runs on a server, at src/SIL.XForge and src/SIL.XForge.Scripture
7
7
3. RealtimeServer (Node) that runs on a server, at src/RealtimeServer
8
8
9
-
# Key Architectural Patterns
10
-
11
-
- Data models must be defined in all 3 applications to stay in sync
12
-
- Frontend uses RealtimeService (ShareDB) for real-time data sync, which is defined at src/SIL.XForge.Scripture/ClientApp/src/xforge-common/realtime.service.ts
13
-
- Frontend also sometimes uses JSON-RPC to communicate with Backend.
14
-
- Frontend works offline and uses IndexedDB for storage.
15
-
- User permissions should be checked on both frontend and backend, using the rights service whenever possible, rather than checking the user role. See project-rights.ts, sf-project-rights.ts, and SFProjectRights.cs.
9
+
# Data exchange between the three interconnected applications
10
+
11
+
- Data models must be defined in all 3 applications and stay in sync.
12
+
- An example Backend data model can be seen at src/SIL.XForge.Scripture/Models/SFProject.cs
13
+
- Frontend and RealtimeServer both use the same data model files. An example can be seen at src/RealtimeServer/scriptureforge/models/sf-project.ts
14
+
- Frontend uses src/SIL.XForge.Scripture/ClientApp/src/xforge-common/realtime.service.ts to read and write data. This Realtime document data is stored in IndexedDB and is also automatically kept up to date with the data in RealtimeServer when Frontend has an Internet connection. If Frontend is offline, it continues reading and writing realtime documents using realtime.service.ts, and later data is synced with RealtimeService when Frontend regains an Internet connection.
15
+
- Realtime documents should not be modified directly. Instead, submit ops to modify the realtime documents.
16
+
- RealtimeServer uses ShareDB to merge ops from multiple Frontend clients. Frontend clients synchronize with RealtimeServer and present a live view of the changes from other clients as they work.
17
+
- Frontend also uses JSON-RPC to communicate with Backend, such as seen on Backend at src/SIL.XForge.Scripture/Controllers/SFProjectsRpcController.cs.
18
+
- User permissions should be checked in all of Frontend, Backend, and RealtimeServer, using the rights service whenever possible, rather than checking the user role. See project-rights.ts, sf-project-rights.ts, and SFProjectRights.cs.
19
+
- Follow existing patterns for validation schemas.
20
+
21
+
# Frontend
22
+
23
+
- Most Frontend tasks should work on a mobile phone. In other words, on a device with a narrow and short screen.
24
+
- Most editing and reviewing tasks should work while offline. Changing some settings may require being online.
25
+
- Feature flags (feature-flag.service.ts) can control functionality rollout.
26
+
- Error handling with ErrorReportingService
27
+
- Keep related files together in feature folders
28
+
- Follow existing naming conventions
16
29
17
-
# Frontend Guidelines
30
+
# Frontend localization
18
31
19
-
- Use standalone Angular components with typed inputs/outputs
20
-
- Feature flags (feature-flag.service.ts) can control functionality rollout.
32
+
- Use TranslocoModule for translations
21
33
- Put UI strings in checking_en.json if ANY user might see them
22
34
- Only put strings in non_checking_en.json if community checkers will NEVER see them
23
-
- Use TranslocoModule for translations
24
-
- Prefix async calls that aren't awaited with 'void'
25
-
- Use explicit true/false/null/undefined rather than truthy/falsy
26
-
- Use `@if {}` syntax rather than `*ngIf` syntax.
27
-
28
-
# Data Layer Guidelines
29
-
30
-
- Define interfaces/models in all 3 applications
31
-
- Use RealtimeService for CRUD operations
32
-
- Follow existing patterns for validation schemas
35
+
- Localizations that a Community Checker user might see should be created or edited in src/SIL.XForge.Scripture/ClientApp/src/assets/i18n/checking_en.json. Only localizations that a Community Checker user will not see can be created or edited in src/SIL.XForge.Scripture/ClientApp/src/assets/i18n/non_checking_en.json.
36
+
- Even if something is a system-wide feature that isn't specific to community checking functionality, it should still be placed in checking_en.json if a community checking user would POSSIBLY see it.
33
37
34
-
# Testing Guidelines
38
+
# Testing
35
39
36
40
- Write unit tests for new components and services
37
41
- Follow existing patterns for mocking dependencies
38
42
- Use TestEnvironment pattern from existing tests
39
43
- Test both online and offline scenarios
40
44
- Test permission boundaries
41
45
42
-
# Common Patterns to Follow
46
+
# Code comments
43
47
44
-
- Permission checking in services
45
-
- Error handling with ErrorReportingService
46
-
- Offline-first data access
47
-
- Type-safe data models
48
-
49
-
# File Organization
50
-
51
-
- Keep related files together in feature folders
52
-
- Follow existing naming conventions
53
-
54
-
DO NOT REMOVE COMMENTS ALREADY IN THE CODE. You can add to or edit existing comments, but do not removing the existing comments.
55
-
Do not insert new comments into the code where method calls already make it clear.
56
-
Do not add method comments unless the method would be unclear to an experienced developer.
57
-
Do put comments into the code to make it more clear what is going on if it would not be obvious to an experienced developer.
58
-
Do put comments into the code if the intent is not clear from the code.
59
-
All classes should have a comment to briefly explain why it is there and what its purpose is in the overall system, even if it seems obvious.
60
-
Please do not fail to add a comment to any classes that are created. All classes should have a comment.
48
+
- DO NOT REMOVE COMMENTS ALREADY IN THE CODE. You can add to or edit existing comments, but do not removing the existing comments.
49
+
- Do not insert new comments into the code where method calls already make it clear.
50
+
- Do not add method comments unless the method would be unclear to an experienced developer.
51
+
- Do put comments into the code to make it more clear what is going on if it would not be obvious to an experienced developer.
52
+
- Do put comments into the code if the intent is not clear from the code.
53
+
- All classes should have a comment to briefly explain why it is there and what its purpose is in the overall system, even if it seems obvious.
54
+
- Please do not fail to add a comment to any classes that are created. All classes should have a comment.
61
55
62
-
Never rely on JavaScript's truthy or falsy. Instead, work with actual true, false, null, and undefined values, rather than relying on their interpretation as truthy or falsy. For example, if `someVariable` might be null, or undefined, or zero, don't write code like `if (someVariable)` or `const foo:string = someVariable ? 'a' : 'b'` or `if (count)`. Instead, inspect for the null, undefined, or zero rather than letting the value be interpreted as truthy for falsy. For example, use`if (someVariable == null)` or `const foo:string = someVariable != null 'a' : 'b'` or `if (count > 0)`.
56
+
# TypeScript language
63
57
64
-
Specify types where not obvious, such as when declaring variables and arguments, and for function return types.
65
-
66
-
If you do not have access to a file that you need, stop and ask me.
67
-
68
-
All code that you write should be able to pass eslint linting tests for TypeScript, or csharpier for C#.
69
-
70
-
Don't merely write code for the local context, but make changes that are good overall considering the architecture of the application and structure of the files and classes.
71
-
72
-
The frontend works offline, reading and writing data to and from IndexedDB using src/SIL.XForge.Scripture/ClientApp/src/xforge-common/realtime.service.ts. Do not modify realtime documents directly; instead, submit operations to the realtime documents. Realtime document data is automatically kept up to date with the data on the server when the frontend has an Internet connection. Most of data reading and writing from the frontend should happen by reading Realtime documents and submitting ops to Realtime documents to write to them, with occasional usage of JSON-RPC, such as seen on the C# backend at src/SIL.XForge.Scripture/Controllers/SFProjectsRpcController.cs.
58
+
- Use explicit true/false/null/undefined rather than truthy/falsy
59
+
- Never rely on JavaScript's truthy or falsy. Instead, work with actual true, false, null, and undefined values, rather than relying on their interpretation as truthy or falsy. For example, if `count` might be null, or undefined, or zero, don't write code like `if (count)` or `const foo:string = someVariable ? 'a' : 'b'`. Instead, inspect for the null, undefined, or zero rather than letting the value be interpreted as truthy for falsy. For example, use`if (count == null)` or `const foo:string = someVariable != null 'a' : 'b'` or `if (count > 0)`.
60
+
- Specify types where not obvious, such as when declaring variables and arguments, and for function return types.
61
+
- Use `@if {}` syntax rather than `*ngIf` syntax.
73
62
74
-
Data models are defined in each of the 3 applications, and should stay in sync.
63
+
# Code
75
64
76
-
Localizations that a Community Checker user might see should be created or edited in src/SIL.XForge.Scripture/ClientApp/src/assets/i18n/checking_en.json. Only localizations that a Community Checker user will not see can be created or edited in src/SIL.XForge.Scripture/ClientApp/src/assets/i18n/non_checking_en.json.
77
-
Even if something is a system-wide feature that isn't specific to community checking functionality, it should still be placed in checking_en.json if a community checking user would POSSIBLY see it.
65
+
- All code that you write should be able to pass eslint linting tests for TypeScript, or csharpier for C#.
66
+
- Don't merely write code for the local context, but make changes that are good overall considering the architecture of the application and structure of the files and classes.
0 commit comments