Skip to content

Commit 7dfc785

Browse files
khvn26Copilotmatthewelwell
authored
docs: Add developer documentation, AGENTS.md (#6448)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Matthew Elwell <matthew.elwell@flagsmith.com>
1 parent 618c9fb commit 7dfc785

15 files changed

Lines changed: 174 additions & 104 deletions

File tree

.github/pull_request_template.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
Thanks for submitting a PR! Please check the boxes below:
22

3-
- [ ] I have added information to `docs/` if required so people know about the feature!
4-
- [ ] I have filled in the "Changes" section below?
5-
- [ ] I have filled in the "How did you test this code" section below?
6-
- [ ] I have used a [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/) title for this Pull Request
3+
- [ ] I have read the [Contributing Guide](/CONTRIBUTING.md).
4+
- [ ] I have added information to `docs/` if required so people know about the feature.
5+
- [ ] I have filled in the "Changes" section below.
6+
- [ ] I have filled in the "How did you test this code" section below.
77

88
## Changes
99

10+
Contributes to <!-- insert issue # or URL -->
11+
12+
<!-- Change "Contributes to" to "Closes" if this PR, when merged, completely resolves the referenced issue.
13+
Leave "Contributes to" if the changes need to be released first. -->
14+
1015
_Please describe._
1116

1217
## How did you test this code?

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ src/CI_COMMIT_SHA
2323
.DS_Store
2424
.idea
2525
*.iml
26+
27+
AGENTS.local.md

AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Prioritise @AGENTS.local.md, if present.
2+
3+
Use British English.
4+
5+
# Tasks
6+
7+
Install Git hooks: `make install-hooks`
8+
For backend code, read @api/README.md
9+
For frontend code, read @frontend/README.md
10+
For docs.flagsmith.com source, read @docs/README.md

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Read @AGENTS.md

CONTRIBUTING.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
# Contributing
1+
# Contributing Guide
22

3-
We're always looking to improve this project, open source contribution is encouraged so long as they adhere to these
4-
guidelines.
3+
We're always looking to improve this project, and we welcome your participation! Flagsmith accepts contributions via GitHub pull requests (PRs). This guide is intended to help ensure the success of your contribution.
54

6-
## Pull Requests
5+
## Create an issue
76

8-
The Flagsmith team will be monitoring for pull requests. When we get one, a member of team will test the work against
9-
our internal uses and sign off on the changes. From here, we'll either merge the pull request or provide feedback
10-
suggesting the next steps.
7+
Before opening a PR, we encourage you to [create an issue](https://github.com/Flagsmith/flagsmith/issues/new/choose) describing your problem or feature request.
118

12-
### A couple things to keep in mind
9+
We don't leave PRs unattended, but it will be easier for us to prioritise a review of your PR when there is a relevant issue at hand.
1310

14-
- If you've changed APIs, update the documentation.
15-
- Keep the code style (indents, wrapping) consistent.
16-
- If your PR involves a lot of commits, squash them using `git rebase -i` as this makes it easier for us to review.
17-
- Keep lines under 80 characters.
11+
You can submit a PR directly for problems such as spelling mistakes or other things where it's clear what the problem is.
1812

19-
### Windows support
13+
If you decide to create an issue, be sure to search for an existing one first.
2014

21-
Flagsmith development under Windows is not currently supported. If you are contributing from Windows, consider using Windows Subsystem for Linux.
15+
## Find an issue
16+
17+
If you are prepared to contribute but are uncertain as to how, consider narrowing your search with issue filters. For instance:
18+
- [is:issue state:open type:Bug no:assignee](https://github.com/Flagsmith/flagsmith/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20no%3Aassignee) includes all current bugs.
19+
- [is:issue state:open label:"good first issue" no:assignee](https://github.com/Flagsmith/flagsmith/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22%20no%3Aassignee) lists issues we think are good for newcomers.
20+
21+
## Submit a PR
22+
23+
1. The target branch should always be set to `main`, unless otherwise asked in the respective issue.
24+
1. Feel free to open a draft pull request. If you open a regular PR, a reviewer will be assigned immediately and your PR will be considered ready for review, unless you specify otherwise in a PR comment. You're welcome to use a PR to run checks against unfinished code.
25+
1. Once you have addressed the review feedback, preferably in new commits, reply to review comments, ensure the checks are passing and re-request a review. It is okay to not address the nitpicks and notes.
26+
1. An approved PR is eventually merged into `main`. Documentation changes will get deployed immediately afterwards. Your frontend changes will get deployed to SaaS, and you can expect both backend and frontend changes to be included in the next release.
27+
28+
## Setup local development
29+
30+
The development tooling is intended for use with Linux or macOS, and [GNU Make](https://www.gnu.org/software/make/). Consider using Windows Subsystem for Linux (WSL) to develop on Windows.
31+
32+
To install Git hooks, run `make install-hooks`.
33+
34+
Each component provides its own Makefile in its respective subdirectory, and documents its usage and dependencies in a `README.md` file.

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
.PHONY: install-pre-commit
2+
install-pre-commit:
3+
curl -LsSf uvx.sh/pre-commit/install.sh | sh
4+
5+
.PHONY: install-hooks
6+
install-hooks: install-pre-commit
7+
pre-commit install
8+
19
.PHONY: install
210
install:
3-
cd api && $(MAKE) install
4-
cd docs && $(MAKE) install
11+
$(MAKE) -C api install
12+
$(MAKE) -C docs install
13+
$(MAKE) -C frontend install
514

615
.PHONY: lint
716
lint:
8-
cd api && $(MAKE) lint
9-
cd docs && $(MAKE) lint
17+
$(MAKE) -C api lint
18+
$(MAKE) -C docs lint
19+
$(MAKE) -C frontend lint

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,18 @@ Please go to the following page and choose a password: http://localhost:8000/pas
5252

5353
## Flagsmith Open Source
5454

55-
The Flagsmith repository is comprised of two core components - the [REST API](https://github.com/Flagsmith/flagsmith/tree/main/api) and the [frontend dashboard](https://github.com/Flagsmith/flagsmith/tree/main/frontend).
56-
57-
Further documentation for these can be found at:
58-
59-
* [API](https://docs.flagsmith.com/deployment/hosting/locally-api)
60-
* [Frontend](https://docs.flagsmith.com/deployment/hosting/locally-frontend)
55+
We love contributions from the community and are always looking to improve! Here are our [contribution guidelines](https://docs.flagsmith.com/platform/contributing).
6156

6257
## Flagsmith hosted SaaS
58+
6359
You can try our hosted version for free at https://flagsmith.com
6460

65-
## Community Resources + Contribution Guidelines
61+
## Community Resources
6662

6763
* [Visit our docs](https://docs.flagsmith.com/)
6864
* [Chat with other developers on Discord](https://discord.com/invite/hFhxNtXzgm)
6965
* If you need help getting up and running, please [get in touch](https://www.flagsmith.com/contact-us)
7066

71-
We love contributions from the community and are always looking to improve! Here are our [contribution guidelines](https://docs.flagsmith.com/platform/contributing).
72-
7367
## Open Source Philosophy
7468

7569
The majority of our platform is open source under the [BSD-3-Clause license](https://github.com/Flagsmith/flagsmith?tab=BSD-3-Clause-1-ov-file#readme). A small number of repositories are under the MIT license.

api/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
## Flagsmith API
2+
3+
### Local development
4+
5+
The project assumes the following tools installed:
6+
- [Python](https://www.python.org/downloads/). Any version allowed by `requires-python` in `pyproject.toml` is supported.
7+
- [GNU Make](https://www.gnu.org/software/make/).
8+
- Docker or a compatible tool like [Podman](https://podman.io/). We recommend [OrbStack](https://orbstack.dev/) for macOS.
9+
10+
To install dev dependencies, run `make install`.
11+
12+
To run linters, run `make lint`.
13+
14+
To run tests, run `make docker-up test`.
15+
16+
To prepare a dev database, run `make docker-up django-migrate`.
17+
18+
To bring up a dev server, run `make serve`, or `make serve-with-task-processor` to run the Task processor alongside the server.
19+
20+
### Code guidelines: testing
21+
22+
The required diff test coverage for our backend PRs is 100%. This policy gives us more confidence to ship, helps us to find bugs earlier, and promotes the test-driven development (TDD) approach. We encourage you to add new tests, and modify existing ones, ahead of writing the code.
23+
24+
This codebase includes two kinds of tests:
25+
- Black box API tests in `tests/integration` directory. Ideally, these are intended to only invoke API endpoints, and verify their output.
26+
- Tests for individual modules, classes and functions in `tests/unit` directory.
27+
28+
We avoid class-based tests. To manage test lifecycle and dependencies, we rely on Pytest features such as fixtures, markers, parametrisation, and hooks. Read `conftest.py` for commonly used fixtures.
29+
30+
We recommend naming test functions using the `test_{subject}__{condition}__{expected outcome}` template, e.g. `test_get_version__valid_file_contents__returns_version_number`.
31+
32+
We use the Given When Then structure in all our tests.
33+
34+
### Code guidelines: migrations
35+
36+
To auto-generate migrations for your new code, run `make docker-up django-make-migrations`.
37+
38+
The prompt will ask you for a name and not generate one; we avoid auto-generated migration names.
39+
40+
Squash newly added migrations whenever you can.
41+
42+
### Code guidelines: typing
43+
44+
This codebase, including tests, is fully type-checked by Mypy in strict mode. Resolving existing `# type: ignore` comments is always welcome. If you happen to bring a new `# type: ignore` comment, please document the reason, and consider fixing a small number of adjacent `# type: ignore` comments, if possible and appropriate for the scope of your task.
45+
46+
To run a full type check, run `make typecheck`.
47+
48+
### Code guidelines: design and architecture
49+
50+
Core API consists of Django apps with usual Django submodules like:
51+
- `apps.py`
52+
- `middleware.py`
53+
- `models.py`
54+
- `serializers.py`
55+
- `views.py`
56+
- `urls.py`
57+
58+
We tend to add our own layers in the following modules:
59+
- `constants.py` for app-wide constant variables.
60+
- `dataclasses.py` for dataclass definitions, typically used for internal data transfer objects (DTOs).
61+
- `mappers.py` for data mapping logic unrelated to API requests and responses.
62+
- `services.py` for encapsulated business logic. Our goal with this layer is to make the views, models and serialisers leaner, so that the business logic is more clearly defined and easier to compose.
63+
- `tasks.py` for defining asynchronous and recurring tasks.
64+
- `types.py` for custom type definitions, including typed dicts.
65+
66+
### Code guidelines: Flagsmith on Flagsmith
67+
68+
To gate and gradually rollout features in the backend, we use the Flagsmith SDK in local evaluation mode:
69+
70+
```python
71+
from integrations.flagsmith.client import get_client
72+
73+
flagsmith_client = get_client("local", local_eval=True)
74+
flags = flagsmith_client.get_identity_flags(
75+
organisation.flagsmith_identifier,
76+
traits=organisation.flagsmith_on_flagsmith_api_traits,
77+
)
78+
ai_enabled = flags.is_feature_enabled("ai")
79+
```
80+
81+
To modify or add flags, edit [integrations/flagsmith/data/environment.json](integrations/flagsmith/data/environment.json), or run `poetry run python manage.py updateflagsmithenvironment`.

api/readme.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ build:
2222

2323
.PHONY: serve
2424
serve:
25-
npm run serve
25+
npm run start

0 commit comments

Comments
 (0)