|
| 1 | +# AI Coding Agent Instructions for ActivityPub Repository |
| 2 | + |
| 3 | +## Overview |
| 4 | +This repository implements a multitenant ActivityPub server for [Ghost](https://ghost.org/), enabling independent websites to publish content directly to the Fediverse. It is built using [Fedify](https://fedify.dev/) and integrates with various Google Cloud services for production deployment. |
| 5 | + |
| 6 | +## Key Components |
| 7 | +- **`/src`**: Core application code, organized by domain (e.g., `account`, `post`, `notification`). |
| 8 | +- **`/features`**: Cucumber feature files for end-to-end testing. |
| 9 | +- **`/jobs`**: Scripts for one-off production tasks. |
| 10 | +- **`/migrate`**: Database migration scripts and tools. |
| 11 | +- **`/dev`**: Development utilities, including Docker configurations and local emulators. |
| 12 | + |
| 13 | +## Development Workflows |
| 14 | +### Setup |
| 15 | +- Install dependencies: `yarn install` |
| 16 | +- Start the development environment: `yarn dev` |
| 17 | +- Fix environment issues: `yarn fix` |
| 18 | + |
| 19 | +### Testing |
| 20 | +- Run all tests: `yarn test` |
| 21 | +- Run unit tests: `yarn test:unit` |
| 22 | +- Run integration tests: `yarn test:integration` |
| 23 | +- Run end-to-end tests: `yarn test:cucumber` |
| 24 | +- Run a specific test: `yarn test:single path/to/test` |
| 25 | + |
| 26 | +### Database |
| 27 | +- Create a migration: `yarn migration 'migration-name'` |
| 28 | +- Apply migrations: `yarn migrate` |
| 29 | +- Wipe the database: `yarn wipe-db` |
| 30 | + |
| 31 | +## Architectural Patterns |
| 32 | +- **Dependency Injection**: Managed via [Awilix](https://github.com/jeffijoe/awilix) for testability. |
| 33 | +- **Result Pattern**: Prefer returning results over throwing exceptions. |
| 34 | +- **Layered Design**: |
| 35 | + - **Entities**: Contain business logic. |
| 36 | + - **Repositories**: Abstract database operations; accessed only via services. |
| 37 | + - **Services**: Orchestrate business logic and may depend on other services. |
| 38 | + - **Controllers**: Handle HTTP requests and delegate to services. |
| 39 | + - **Views**: Optimize data presentation for clients; may directly query the database but avoid business logic. |
| 40 | + |
| 41 | +## Code Conventions |
| 42 | +- **Testing**: |
| 43 | + - Unit and integration test files use `.test.ts` suffix. |
| 44 | + - Co-locate tests with the code they validate. |
| 45 | + - End-to-end tests reside in `features/`. |
| 46 | +- **Linting and Formatting**: |
| 47 | + - Run linter: `yarn lint` |
| 48 | + - Run formatter: `yarn fmt` |
| 49 | +- **Performance**: |
| 50 | + - Minimize synchronous operations during application boot to optimize for Google Cloud Run. |
| 51 | + |
| 52 | +## External Dependencies |
| 53 | +- **Google Cloud Services**: |
| 54 | + - Cloud Run: Production deployment. |
| 55 | + - Cloud SQL: Managed MySQL database. |
| 56 | + - Pub/Sub: Messaging. |
| 57 | + - Cloud Storage: File storage. |
| 58 | +- **Local Emulators**: |
| 59 | + - Pub/Sub: Port `8085`. |
| 60 | + - Cloud Storage: Port `4443`. |
| 61 | +- **Other Tools**: |
| 62 | + - [Tailscale](https://tailscale.com): Expose local development environment. |
| 63 | + - [Wiremock](https://wiremock.org): API mocking for end-to-end tests. |
| 64 | + |
| 65 | +## Common Practices |
| 66 | +- Follow the outlined architecture and testing patterns. |
| 67 | +- Ensure new functionality is well-tested, lint-free, and adheres to conventions. |
| 68 | +- Optimize for fast test execution (<10 seconds per test). |
| 69 | + |
| 70 | +## Known Quirks |
| 71 | +- Tests run in Docker containers, so additional flags passed to `yarn` may not propagate to the test runner. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +For more details, refer to `AGENTS.md` or the `README.md` file. |
0 commit comments