

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# AGENTS.md — flagsmith23## Project Overview45Flagsmith is an open-source feature flagging and remote configuration management tool. It allows teams to manage feature releases, perform A/B testing, and toggle application functionality without deploying new code. The tech stack is centered around a Python/Django backend API and a TypeScript/React single-page application frontend, designed to be self-hosted with Docker or used as a SaaS product.67## Tech Stack89- **Languages**: Python, TypeScript10- **Frameworks**: Django, Django REST Framework, React, Redux Toolkit11- **Database**: PostgreSQL12- **Dependency Management**: Poetry (Backend), npm (Frontend)13- **Testing**: `pytest` (Backend Unit & Integration), Jest (Frontend Unit), TestCafe (Frontend E2E)14- **Formatting & Linting**: `black`, `isort` (Backend); Prettier, ESLint (Frontend)15- **DevOps & Infrastructure**: Docker, Docker Compose16- **Error Monitoring**: Sentry, Prometheus1718## Architecture1920The project uses a monorepo structure, separating the backend, frontend, and documentation into distinct top-level directories. It follows a client-server model with a monolithic Django API and a React Single-Page Application (SPA).2122- `api/`: The monolithic Django backend.23 - `api/features/`, `api/organisations/`, `api/users/`: Modular Django apps, each containing its own models, views, and serializers, promoting separation of concerns.24 - `api/tests/`: Contains all backend tests, subdivided into `unit/` and `integration/`.25 - `api/pyproject.toml`: Defines all Python dependencies managed by Poetry.26- `frontend/`: The React SPA frontend.27 - `frontend/web/`: Main source code for the application.28 - `frontend/web/components/`: Reusable React components form the core of the UI.29 - `frontend/common/`: Contains shared logic, including state management.30 - `frontend/common/store.ts`: The central Redux Toolkit store configuration.31 - `frontend/common/service.ts`: The single RTK Query service definition that handles all API communication.32 - `frontend/e2e/`: End-to-end tests written with TestCafe.33 - `frontend/package.json`: Defines all frontend dependencies managed by npm.34- `docs/`: Project documentation built with Docusaurus.35- `docker-compose.yml`: The entry point for setting up the entire local development environment.3637## Code Style3839The codebase maintains a strict and consistent style through automated formatters and linters.4041**Backend (Python):**42- **Formatting**: Code is formatted with `black` and imports are sorted with `isort`. These tools are configured in `api/pyproject.toml` and must be run before committing.43- **Naming**: Follows standard Python PEP 8 conventions (e.g., `snake_case` for variables and functions, `PascalCase` for classes).44- **Views**: Class-based views are used, inheriting from Django REST Framework's `APIView`. Business logic should not reside in the view itself but be abstracted into model methods or service functions.4546Example of a backend view (`api/audit/views.py`):47```python48from rest_framework.response import Response49from rest_framework.views import APIView50from audit.models import AuditLog5152class AuditLogCount(APIView):53 def get(self, request, *args, **kwargs):54 count = AuditLog.objects.count()55 return Response({'count': count})56```5758**Frontend (TypeScript/React):**59- **Formatting**: Code is automatically formatted using **Prettier**.60- **Linting**: **ESLint** is used to enforce code quality and best practices.61- **Components**: Functional components with Hooks are standard.62- **Data Fetching**: All data fetching is done via auto-generated RTK Query hooks.6364Example of a frontend component (`frontend/web/components/AuditLogCounter.tsx`):65```typescript66import React from 'react';67import { useGetAuditLogCountQuery } from 'common/service';6869export const AuditLogCounter = () => {70 const { data, isLoading, error } = useGetAuditLogCountQuery({});7172 if (isLoading) return <div>Loading...</div>;73 if (error) return <div>Error fetching count!</div>;7475 return <h1>Total Audit Logs: {data?.count}</h1>;76};77```7879## Anti-Patterns & Restrictions8081To maintain architectural integrity and code quality, the following rules must be strictly followed:8283- **Frontend:**84 - **NEVER** make direct API calls from components using `fetch` or `axios`. **ALWAYS** use the RTK Query service layer defined in `frontend/common/service.ts`.85 - **NEVER** introduce a new global state management library. All global state must be managed via the existing Redux Toolkit store (`frontend/common/store.ts`).8687- **Backend:**88 - **NEVER** bypass the Django ORM for database operations unless it is for a critical, well-documented performance optimization.89 - **AVOID** placing complex business logic directly within Django views (`views.py`). This logic should be abstracted into separate service functions or model methods to keep views lean and focused on handling the HTTP request/response cycle.9091## Database & State Management9293The application manages state and data flow differently on the backend and frontend.9495**Backend (Database):**96- The primary database is **PostgreSQL**.97- All database interactions are handled exclusively through the **Django ORM**. Direct SQL queries are forbidden except in rare, documented cases.98- Database schemas are defined as Django models within each app's `models.py` file (e.g., `api/features/models.py`).99- Schema changes must be managed through Django's migration system. New migrations are created with `poetry run python manage.py makemigrations` and applied with `poetry run python manage.py migrate`.100101**Frontend (State):**102- **Server State & Caching**: All interactions with the backend API (fetching, creating, updating, deleting data) are managed by **RTK Query**. The API service definition is located in `frontend/common/service.ts`. This provides hooks that handle the entire data lifecycle, including caching, invalidation, and optimistic updates.103- **Global UI State**: Global state that is not persisted on the server (e.g., modal visibility, UI themes) is managed by **Redux Toolkit**. The store is configured in `frontend/common/store.ts`. New state is added by creating a new "slice" with `createSlice`.104105## Error Handling & Logging106107- **Backend**:108 - **Logging**: Uses Python's standard `logging` module, configured in `api/app/settings/common.py`. Logs should be used to record important events and debug issues.109 - **Error Reporting**: In production, unhandled exceptions are captured and reported to **Sentry**. The Sentry integration is configured via environment variables.110111- **Frontend**:112 - **Error Reporting**: Unhandled client-side exceptions are captured and sent to **Sentry**.113 - **Error Boundaries**: Components that have a high chance of failing or depend on fragile data should be wrapped in React **Error Boundaries**. This prevents a component-level error from crashing the entire application and allows a fallback UI to be displayed.114115## Testing Commands116117- **Run the full application stack (API, Frontend, DB):**118```bash119 docker-compose up120```121- **Build and run the stack from scratch:**122```bash123 docker-compose up --build124```125- **Run backend tests:**126```bash127 cd api128 poetry run pytest129```130- **Run frontend linter:**131```bash132 cd frontend133 npm run lint134```135- **Run frontend dev server (with Hot Module Replacement):**136```bash137 cd frontend138 npm install139 npm run dev140```141142## Testing Guidelines143144**Backend (`pytest`):**145- All test files are located in the `api/tests/` directory.146- Test files should be named following the `test_*.py` pattern.147- **Unit Tests**: Located in `api/tests/unit/`. These tests should focus on a single function or class and mock external dependencies (like database or network calls) where necessary.148- **Integration Tests**: Located in `api/tests/integration/`. These tests verify the interaction between different components of the backend, often involving database access.149- Fixtures are heavily used to set up test data and clients. For example, `admin_client` provides an authenticated API client.150151Example backend test (`api/tests/unit/audit/test_views.py`):152```python153def test_get_audit_log_count(admin_client):154 # When155 response = admin_client.get("/api/v1/audit/count/")156 # Then157 assert response.status_code == 200158 assert response.json()["count"] >= 0159```160161**Frontend (`Jest` & `TestCafe`):**162- **Unit/Component Tests (`Jest`)**: Test files should be co-located with the components they are testing (e.g., `Component.tsx` and `Component.test.tsx`). These tests should verify component rendering and behavior in isolation.163- **End-to-End Tests (`TestCafe`)**: E2E test scripts are located in the `frontend/e2e/` directory. These tests simulate real user workflows by interacting with the application in a browser.164165## Security & Compliance166167- **Secrets Management**: **NEVER** hard-code secrets (API keys, passwords, tokens) in the source code. All secrets must be managed through environment variables. The `docker-compose.yml` file serves as a reference for required variables in local development.168- **Authentication**: The API uses a built-in authentication system to protect endpoints.169- **Authorization**: Permissions are managed using a Role-Based Access Control (RBAC) model to ensure users can only access resources appropriate for their role.170- **Vulnerability Reporting**: Any discovered security vulnerabilities must be reported privately to `support[at]flagsmith[dot]com`. Do not disclose them publicly in GitHub issues.171172## Dependencies & Environment173174The entire development environment is containerized with Docker to ensure consistency.175176- **Runtime Environment**: The primary way to run the project is via Docker. `docker-compose up` will start all required services (backend, frontend, database).177- **Backend Dependencies (Python)**:178 - Managed by **Poetry**.179 - Defined in `api/pyproject.toml`.180 - To install: `cd api && poetry install`181 - To add a new dependency: `cd api && poetry add <package-name>`182- **Frontend Dependencies (JavaScript/TypeScript)**:183 - Managed by **npm**.184 - Defined in `frontend/package.json`.185 - To install: `cd frontend && npm install`186 - To add a new dependency: `cd frontend && npm install <package-name>`187- **Environment Variables**: The application is configured using environment variables. See `docker-compose.yml` for a list of variables needed for local development.188189## PR & Git Rules190191The project follows a standard GitHub feature-branch workflow.192193- **Branch Naming**: Branch names should be descriptive and prefixed with a type, such as `feature/`, `bugfix/`, or `chore/`. Example: `feature/new-audit-log-export`.194- **Commit Messages**: Commits should be atomic and have clear, descriptive messages explaining the "what" and "why" of the change.195- **Workflow**:196 1. First, create a GitHub Issue to discuss the proposed change.197 2. Create a feature branch from an up-to-date `main` branch.198```bash199 git checkout main200 git pull origin main201 git checkout -b feature/my-new-feature202```203 3. Implement changes and add corresponding tests.204 4. Ensure all code is formatted and linted correctly.205 5. Push the branch to your fork and open a Pull Request (PR) against the `flagsmith/flagsmith:main` branch.206 6. The PR must be linked to the issue it resolves and must pass all Continuous Integration (CI) checks before it can be considered for merging.207208## Documentation Standards209210- **System & User Documentation**: The public-facing documentation for users and administrators is maintained in the `/docs` directory and built with **Docusaurus**. Significant changes to functionality should be accompanied by updates to this documentation.211- **Code Documentation**:212 - **Python**: Use **docstrings** for public modules, classes, and functions to explain their purpose, arguments, and return values.213 - **TypeScript/React**: Use **TSDoc** comments (`/** ... */`) to document complex components, props, and functions.214215## Common Patterns216217- **Backend: Service Layer Abstraction**: Avoid putting business logic directly in Django views. Abstract complex operations into service functions or model methods. This keeps views thin and focused on HTTP concerns.218```python219 # Good: Logic is in the model/manager220 class AuditLogCount(APIView):221 def get(self, request, *args, **kwargs):222 # The 'how' is hidden from the view223 count = AuditLog.objects.get_total_count()224 return Response({'count': count})225226 # Bad: Logic is coupled to the view227 class AuditLogCount(APIView):228 def get(self, request, *args, **kwargs):229 # Complex filtering and counting logic here...230 count = AuditLog.objects.filter(is_archived=False).count()231 return Response({'count': count})232```233- **Frontend: Declarative Data Fetching**: **ALWAYS** use the RTK Query service for all API interactions. This pattern centralizes data fetching logic, provides automatic caching, and simplifies component code by using hooks.234```typescript235 // In frontend/common/service.ts236 getAuditLogCount: builder.query<{ count: number }, {}>({237 query: () => ({ url: `audit/count/` }),238 }),239240 // In a React component241 import { useGetAuditLogCountQuery } from 'common/service';242243 const MyComponent = () => {244 // The hook handles loading, error, and data states automatically245 const { data } = useGetAuditLogCountQuery({});246 return <div>Count: {data?.count}</div>;247 }248```249- **Full-Stack Development**: New features typically require coordinated changes in both the `api/` and `frontend/` directories. This involves adding a DRF endpoint, serializing data, adding the endpoint to the RTK Query service, and creating a React component to consume it.250251## Agent Workflow / SOP252253When approaching a task, follow this Standard Operating Procedure (SOP):2542551. **Analyze the Request**: Determine if the task is backend-only, frontend-only, or full-stack.2562. **Identify Key Files**:257 - **Backend**: Locate the relevant Django app in `api/`. Changes will likely involve `models.py`, `serializers.py`, `views.py`, and `urls.py`. Tests will be in `api/tests/`.258 - **Frontend**: For UI changes, find the component in `frontend/web/components/`. For data/state changes, the primary files are `frontend/common/service.ts` (API interaction) and `frontend/common/store.ts` (global UI state).2593. **Implement Backend Changes (if required)**:260 - Modify the Django model in `models.py` and create a migration (`poetry run python manage.py makemigrations`).261 - Create or update a serializer in `serializers.py` to control the JSON representation.262 - Create or update the view in `views.py`. Keep business logic out of the view.263 - Register the URL route in `urls.py`.264 - Write unit or integration tests in `api/tests/` to cover the new logic.2654. **Implement Frontend Changes (if required)**:266 - If a new API endpoint is involved, add it to the `builder` in `frontend/common/service.ts`.267 - In the relevant React component, use the auto-generated RTK Query hook (e.g., `useGetMyDataQuery`) to fetch or mutate data.268 - **Strictly avoid** using `fetch()` or `axios()` directly in components.269 - Update or create React components to display the new data or provide new functionality.270 - Add Jest unit tests for new components or complex logic.2715. **Format and Lint**: Before finalizing, run the formatters and linters to ensure code style compliance.272 - Backend: `black .` and `isort .` within the `api/` directory.273 - Frontend: `npm run lint` within the `frontend/` directory.2746. **Verify Locally**: Use `docker-compose up --build` to run the entire application and manually verify that your changes work as expected end-to-end.275276## Few-Shot Examples277278### Good: Following the RTK Query Pattern for Data Fetching279280This example correctly uses the centralized RTK Query service to fetch data and display it in a component.281282**1. Define the endpoint in `frontend/common/service.ts`:**283```typescript284// Good: The endpoint definition is centralized and declarative.285getAuditLogCount: builder.query<{ count: number }, {}>({286 query: () => ({287 url: `audit/count/`,288 }),289}),290```291292**2. Use the generated hook in `frontend/web/components/AuditLogCounter.tsx`:**293```typescript294import React from 'react';295import { useGetAuditLogCountQuery } from 'common/service';296297// Good: The component is simple, declarative, and leverages the hook for all async logic.298export const AuditLogCounter = () => {299 const { data, isLoading, error } = useGetAuditLogCountQuery({});300301 if (isLoading) return <div>Loading...</div>;302 if (error) return <div>Error fetching count!</div>;303304 return <h1>Total Audit Logs: {data?.count}</h1>;305};306```307308### Bad: Bypassing the RTK Query Service Layer309310This example violates the core architectural rule by making a direct API call from a component.311312**`frontend/web/components/AuditLogCounter.tsx`:**313```typescript314import React, { useEffect, useState } from 'react';315316// Bad: This component violates the rule against direct API calls.317// It manually handles loading, error, and data states, which is redundant318// and inconsistent with the rest of the application.319export const AuditLogCounter = () => {320 const [data, setData] = useState<{ count: number } | null>(null);321 const [isLoading, setIsLoading] = useState(true);322 const [error, setError] = useState<Error | null>(null);323324 useEffect(() => {325 // DO NOT DO THIS. Use the RTK Query service instead.326 fetch('http://localhost:8000/api/v1/audit/count/')327 .then(res => res.json())328 .then(setData)329 .catch(setError)330 .finally(() => setIsLoading(false));331 }, []);332333 if (isLoading) return <div>Loading...</div>;334 if (error) return <div>Error fetching count!</div>;335336 return <h1>Total Audit Logs: {data?.count}</h1>;337};338339```
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| originalankur/GenerateAgents.mdprojects/fastapi/AGENTS.md · 254 | AGENTS.md | setuptestlint-formatstyle+10 | 88/100 | 14 days ago | |
| originalankur/GenerateAgents.mdAGENTS.md · 254 | AGENTS.md | setupteststylearch+8 | 93/100 | 14 days ago | |
| originalankur/GenerateAgents.mdprojects/flask/AGENTS.md · 254 | AGENTS.md | lint-formatstylesecuritydo-not | 89/100 | 14 days ago | |
| originalankur/GenerateAgents.mdprojects/dspy/AGENTS.md · 254 | AGENTS.md | setupbuildtestlint-format+11 | 96/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| unoplat/unoplat-code-confluenceunoplat-code-confluence-frontend/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 13 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 201k | AGENTS.md | buildteststylearch+3 | 100/100 | 14 days ago | |
| deepseek-ai/deepseek-harnessnative/landlock-run/AGENTS.md · 104k | AGENTS.md | setupteststylearch+3 | 100/100 | today | |
| vllm-project/vllmAGENTS.md · 89k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 14 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 52 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 13 days ago | |
| OnlyTerp/prompt-cache-skillsAGENTS.md · 113 | AGENTS.md | setupbuildtestlint-format+5 | 100/100 | 14 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | today | |
| unoplat/unoplat-code-confluenceunoplat-code-confluence-query-engine/AGENTS.md · 95 | AGENTS.md | setupbuildtestlint-format+5 | 98/100 | 13 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/originalankur-generateagents-md-projects-flagsmith-agents)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.