Skip to content

Commit 8dd6fa9

Browse files
committed
added some basic copilot instructions
1 parent 1fd31c2 commit 8dd6fa9

File tree

8 files changed

+287
-0
lines changed

8 files changed

+287
-0
lines changed

.github/copilot-instructions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Project Overview
2+
3+
This project is a web application that allows users to manage, search, annotate, analyze and interprete reseach materials.
4+
5+
## Folder Structure
6+
7+
- `/frontend`: Contains the source code for the frontend.
8+
- `/backend`: Contains the source code for the backend.
9+
- `/docker`: Contains docker configurations.
10+
- `/tools`: Contains various scripts.
11+
12+
## Core Concepts
13+
14+
We use the following terms throughout the project:
15+
16+
- **User**: An individual who uses the application.
17+
- **Project**: A collection of source documents, annotations, codes, tags, and memos related to a specific research endeavor.
18+
- **Source Document**: Any document (text, image, audio, video) data that is being analyzed. Short: "sdoc".
19+
- **Metadata**: Information about a source document, such as title, author, date created, etc.
20+
- **Tag**: A label assigned to a source document for categorization.
21+
- **Code**: A category used for annotating source documents.
22+
- **Annotation**: A segment of a source document that has been assigned a code.
23+
- **Span Annotation**: An annotation that applies to a specific span of text within a source document.
24+
- **Sentence Annotation**: An annotation that applies to an entire sentence within a source document.
25+
- **Bbox Annotation**: An annotation that applies to a bounding box within an image document.
26+
- **Memo**: A note or comment added to a source document or annotation.

.github/instructions/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copilot Instructions
2+
3+
We can add context-dependent instructions automatically to our prompts! These instructions are currently stored in:
4+
5+
- `.github/copilot-instructions.md`: Generic instructions always added to prompts
6+
- `.github/instructions`: Context dependent instructions, added to the prompts depending on the file location
7+
8+
Additionally, we can specify reusable prompts or tasks that can be executed:
9+
10+
- `.github/prompts`
11+
- `/backend/.github/prompts`
12+
- `/frontend/.github/prompts`
13+
14+
For more information, see:
15+
16+
- Prompting best practices: https://docs.github.com/en/copilot/get-started/best-practices
17+
- Prompt engineering: https://docs.github.com/en/copilot/concepts/prompting/prompt-engineering
18+
- Custom instructions: https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions#creating-repository-wide-custom-instructions-1
19+
- Example custom instructions: https://docs.github.com/en/copilot/tutorials/customization-library/custom-instructions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
applyTo: "backend/**/*.py"
3+
---
4+
5+
## Backend
6+
7+
The backend is built using Python with FastAPI as the web framework.
8+
It provides RESTful API endpoints for the frontend to interact with.
9+
It follows a modular architecture, separating concerns into different folders and files.
10+
11+
### Libraries and Frameworks
12+
13+
Dependencies are listed in pyproject.toml and managed with uv.
14+
15+
- FastAPI for building the API (REST endpoints)
16+
- SQLAlchemy for database interactions
17+
- Alembic for database migrations
18+
- Pydantic for data validation
19+
- Omegaconf for configuration management
20+
- Loguru for logging
21+
22+
### Databases
23+
24+
The backend works with multiple databases:
25+
26+
- PostgreSQL as the primary relational database
27+
- Weaviate for vector storage and similarity search
28+
- Elasticsearch for full-text search capabilities
29+
- Filesystem storage for storing uploaded files
30+
31+
### Folder Structure
32+
33+
- `/backend/configs`: Configuration files for different environments
34+
- `/backend/src`: Main application code
35+
- `/common`: Utility functions and helpers
36+
- `/core`: Core application logic. All core concepts are implemented here.
37+
- `/migrations`: Alembic database migrations
38+
- `/modules`: Application logic organized by feature. Modules use core services and systems to implement features.
39+
- `/repos`: Connections to external services, e.g., databases, file storage, etc.
40+
- `/systems`: Reusable systems that can be plugged into application logic
41+
- `/backend/tests`: Test cases for the backend code
42+
43+
### File Naming Conventions
44+
45+
The purpose of the file is reflected in its name.
46+
We use the following suffixes to indicate file types:
47+
- `*_endpoint.py`: API endpoint definitions
48+
49+
- `*_dto.py`: Pydantic schemas (Data Transfer Objects) for request and response validation of payloads
50+
- `*_orm.py`: SQL Database models and schemas
51+
- `*_crud.py`: CRUD operations for database models (SQL)
52+
53+
- `*_collection.py`: Weaviate collection schemas
54+
- `*_embedding_crud.py`: CRUD operations for embeddings stored in Weaviate
55+
56+
- `*_elastic_index.py`: Elasticsearch index schemas
57+
- `*_elastic_crud.py`: CRUD operations for Elasticsearch indices
58+
59+
- `*_system.py`: Reusable systems that encapsulate specific functionality
60+
- `*_service.py`: Business logic and service layer implementations
61+
- `*_repo.py`: Data access layer and repository implementations
62+
- `*_utils.py`: Utility functions and helpers
63+
64+
### Coding Instructions
65+
66+
When writing backend code, follow these guidelines:
67+
68+
- Use type hints for function signatures and variable declarations.
69+
- Write docstrings for all public functions and classes.
70+
- Use loguru for logging sensible events and errors.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
applyTo: "backend/test/**/*.py"
3+
---
4+
5+
When writing Python tests:
6+
7+
## Test Structure Essentials
8+
9+
- Use pytest as the primary testing framework
10+
- Follow AAA pattern: Arrange, Act, Assert
11+
- Write descriptive test names that explain the behavior being tested
12+
- Keep tests focused on one specific behavior
13+
14+
## Key Testing Practices
15+
16+
- Test edge cases and error conditions, not just happy paths
17+
18+
## Example Test Pattern
19+
20+
```python
21+
import pytest
22+
from unittest.mock import Mock, patch
23+
24+
class TestUserService:
25+
@pytest.fixture
26+
def user_service(self):
27+
return UserService()
28+
29+
@pytest.mark.parametrize("invalid_email", ["", "invalid", "@test.com"])
30+
def test_should_reject_invalid_emails(self, user_service, invalid_email):
31+
with pytest.raises(ValueError, match="Invalid email"):
32+
user_service.create_user({"email": invalid_email})
33+
34+
@patch('src.user_service.email_validator')
35+
def test_should_handle_validation_failure(self, mock_validator, user_service):
36+
mock_validator.validate.side_effect = ConnectionError()
37+
38+
with pytest.raises(ConnectionError):
39+
user_service.create_user({"email": "test@example.com"})
40+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
applyTo: "frontend/**/*.ts, frontend/**/*.tsx"
3+
---
4+
5+
## Frontend
6+
7+
The frontend is built using Typescript with React as the web framework.
8+
It interacts with the backend through RESTful API endpoints.
9+
It follows a component-based architecture, organizing UI elements into reusable components.
10+
11+
### Libraries and Frameworks
12+
13+
Dependencies are listed in package.json and managed with npm.
14+
15+
- React for building user interfaces
16+
- React Router for client-side routing
17+
- Tanstack Query for data fetching and server state management
18+
- Redux Toolkit for global state management
19+
- React Hook Form for form state management
20+
- React MUI for UI components, styling, theming, and icons
21+
22+
### Folder Structure
23+
24+
- `/frontend/bin`: Various scripts
25+
- `/frontend/public`: Public assets like logos
26+
- `/frontend/src`: Main application code
27+
- `/api`: Generated API client and Hooks for API interactions
28+
- `/auth`: Authentication and authorization logic
29+
- `/components`: Reusable React components
30+
- `/layouts`: Layout components for different page structures
31+
- `/plugins`: Configurations for third-party plugins and integrations (MUI, Tanstack Query, Redux Toolkit, etc.)
32+
- `/router`: React Router route definitions
33+
- `/store`: Redux Toolkit store configuration
34+
- `/utils`: Utility functions and helpers
35+
- `/views`: Page components representing different views/screens
36+
37+
### File Naming Conventions
38+
39+
TODO
40+
41+
### Coding Instructions
42+
43+
When writing frontend code, follow these guidelines:
44+
45+
- Use type hints for function signatures and variable declarations.
46+
- Write docstrings for all public functions and classes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
agent: ask
3+
---
4+
When reviewing code, focus on:
5+
6+
## Security Critical Issues
7+
- Check for hardcoded secrets, API keys, or credentials
8+
- Look for SQL injection and XSS vulnerabilities
9+
- Verify proper input validation and sanitization
10+
- Review authentication and authorization logic
11+
12+
## Performance Red Flags
13+
- Identify N+1 database query problems
14+
- Spot inefficient loops and algorithmic issues
15+
- Check for memory leaks and resource cleanup
16+
- Review caching opportunities for expensive operations
17+
18+
## Code Quality Essentials
19+
- Functions should be focused and appropriately sized
20+
- Use clear, descriptive naming conventions
21+
- Ensure proper error handling throughout
22+
23+
## Review Style
24+
- Be specific and actionable in feedback
25+
- Explain the "why" behind recommendations
26+
- Acknowledge good patterns when you see them
27+
- Ask clarifying questions when code intent is unclear
28+
29+
Always prioritize security vulnerabilities and performance issues that could impact users.
30+
31+
Always suggest changes to improve readability.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Backend Configuration Details
2+
3+
The backend configuration is managed using Omegaconf, allowing for flexible and hierarchical settings management:
4+
5+
Backend:
6+
7+
- Configuration files are stored in the `/backend/configs` directory.
8+
- Different configuration files are used for various environments (e.g., development, production).
9+
- Some settings can be overridden by environment variables (e.g., database credentials, API keys).
10+
- Such environment variables are defined in `/backend/.env` file that is not committed to version control for security reasons.
11+
- Instead, `/backend/.env.example` file is provided to show the required variables.
12+
13+
Docker:
14+
15+
- Docker Compose files (`/docker/`) need to forward relevant environment variables to the backend services.
16+
- Docker Compose files read environment variables from the `/docker/.env` file, which is not committed to version control.
17+
- Again, `/docker/.env.example` is provided to illustrate the necessary variables.
18+
19+
Scripts:
20+
21+
- For easy setup, we provide the `/bin/setup-envs.sh` file which copies the example files to `.env` and initializes environment variables.
22+
23+
## Guidelines for Adding New Configuration Options
24+
25+
When adding new configuration options, consider if they should be configurable via environment variables, especially for sensitive data or settings that may vary between deployments.
26+
27+
If no:
28+
29+
1. Update the configuration files in `/backend/configs`.
30+
31+
If yes:
32+
33+
1. Add the configuration files in `/backend/configs`.
34+
2. Add corresponding environment variable entries in `/backend/.env.example` and `/backend/.env`.
35+
3. Add corresponding entries in `/docker/.env.example` and `/docker/.env`.
36+
4. Update the `/bin/setup-envs.sh` script if necessary to handle new environment variables.
37+
5. Update Docker Compose files in `/docker/` to forward the new environment variables to the backend services.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
agent: agent
3+
---
4+
5+
Your goal is to generate a new React form component.
6+
7+
Ask for the form name and fields if not provided.
8+
9+
Requirements for the form:
10+
11+
- Use `react-hook-form` for form state management:
12+
- Always define TypeScript types for your form data
13+
- Prefer _uncontrolled_ components using register
14+
- Use `defaultValues` to prevent unnecessary rerenders
15+
- Use `yup` for validation:
16+
- Create reusable validation schemas in separate files
17+
- Use TypeScript types to ensure type safety
18+
- Customize UX-friendly validation rules

0 commit comments

Comments
 (0)