|
| 1 | +# Contributing to @objectstack/plugin-auth |
| 2 | + |
| 3 | +Thank you for your interest in contributing to the ObjectStack Auth Plugin! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +1. **Clone the repository** |
| 8 | + ```bash |
| 9 | + git clone https://github.com/objectstack-ai/plugin-auth.git |
| 10 | + cd plugin-auth |
| 11 | + ``` |
| 12 | + |
| 13 | +2. **Install dependencies** |
| 14 | + ```bash |
| 15 | + npm install |
| 16 | + ``` |
| 17 | + |
| 18 | +3. **Build the project** |
| 19 | + ```bash |
| 20 | + npm run build |
| 21 | + ``` |
| 22 | + |
| 23 | +4. **Watch mode for development** |
| 24 | + ```bash |
| 25 | + npm run dev |
| 26 | + ``` |
| 27 | + |
| 28 | +## Project Structure |
| 29 | + |
| 30 | +``` |
| 31 | +src/ |
| 32 | +├── adapter/ # ObjectQL adapter for Better-Auth |
| 33 | +├── schema/ # GraphQL schema definitions |
| 34 | +├── client/ # React hooks and client utilities |
| 35 | +├── server/ # Server-side initialization |
| 36 | +├── types.ts # TypeScript type definitions |
| 37 | +└── index.ts # Main plugin entry point |
| 38 | +``` |
| 39 | + |
| 40 | +## Architecture Principles |
| 41 | + |
| 42 | +### 1. Storage Agnostic |
| 43 | +- **Never** use direct database calls (SQL, Prisma, Drizzle) |
| 44 | +- **Always** use ObjectQL for data operations |
| 45 | +- Pattern: `ql.entity('EntityName').operation()` |
| 46 | + |
| 47 | +Example: |
| 48 | +```typescript |
| 49 | +// ❌ Bad |
| 50 | +await prisma.user.create({ ... }); |
| 51 | + |
| 52 | +// ✅ Good |
| 53 | +await ql.entity('User').create({ ... }); |
| 54 | +``` |
| 55 | + |
| 56 | +### 2. Type Safety |
| 57 | +- Use TypeScript strict mode |
| 58 | +- Export all public types |
| 59 | +- Leverage Better-Auth's type inference |
| 60 | + |
| 61 | +### 3. Framework Agnostic |
| 62 | +- Core plugin should work with any framework |
| 63 | +- Framework-specific code goes in separate exports |
| 64 | +- Example: React hooks in `client/hooks.ts` |
| 65 | + |
| 66 | +### 4. RBAC Integration |
| 67 | +- Authentication (who you are) via Better-Auth |
| 68 | +- Authorization (what you can do) via ObjectOS |
| 69 | +- Inject permissions into session objects |
| 70 | + |
| 71 | +## Coding Standards |
| 72 | + |
| 73 | +### TypeScript |
| 74 | +- Use strict mode |
| 75 | +- Prefer interfaces over types for objects |
| 76 | +- Use explicit return types for public APIs |
| 77 | +- Document complex logic with comments |
| 78 | + |
| 79 | +### Naming Conventions |
| 80 | +- PascalCase for types, interfaces, classes |
| 81 | +- camelCase for functions, variables |
| 82 | +- UPPER_CASE for constants |
| 83 | +- Prefix private methods with `_` |
| 84 | + |
| 85 | +### File Organization |
| 86 | +- One export per file (with exceptions for related utilities) |
| 87 | +- Group related functionality |
| 88 | +- Keep files focused and under 300 lines |
| 89 | + |
| 90 | +## Testing Guidelines |
| 91 | + |
| 92 | +When adding tests (future work): |
| 93 | +- Test with multiple ObjectQL drivers (Postgres, Redis, etc.) |
| 94 | +- Test RBAC permission injection |
| 95 | +- Test session lifecycle |
| 96 | +- Test error handling |
| 97 | + |
| 98 | +## Pull Request Process |
| 99 | + |
| 100 | +1. **Create a feature branch** |
| 101 | + ```bash |
| 102 | + git checkout -b feature/your-feature-name |
| 103 | + ``` |
| 104 | + |
| 105 | +2. **Make your changes** |
| 106 | + - Follow coding standards |
| 107 | + - Add tests if applicable |
| 108 | + - Update documentation |
| 109 | + |
| 110 | +3. **Verify your changes** |
| 111 | + ```bash |
| 112 | + npm run typecheck |
| 113 | + npm run build |
| 114 | + ``` |
| 115 | + |
| 116 | +4. **Commit with clear messages** |
| 117 | + ```bash |
| 118 | + git commit -m "feat: add new feature" |
| 119 | + ``` |
| 120 | + |
| 121 | + Follow [Conventional Commits](https://www.conventionalcommits.org/): |
| 122 | + - `feat:` New feature |
| 123 | + - `fix:` Bug fix |
| 124 | + - `docs:` Documentation changes |
| 125 | + - `refactor:` Code refactoring |
| 126 | + - `test:` Test additions/changes |
| 127 | + - `chore:` Maintenance tasks |
| 128 | + |
| 129 | +5. **Push and create PR** |
| 130 | + ```bash |
| 131 | + git push origin feature/your-feature-name |
| 132 | + ``` |
| 133 | + |
| 134 | +## Common Tasks |
| 135 | + |
| 136 | +### Adding a New Auth Provider |
| 137 | + |
| 138 | +1. Update `AuthPluginConfig` in `src/index.ts` |
| 139 | +2. Add provider configuration to server setup |
| 140 | +3. Update documentation |
| 141 | +4. Add example to `example.config.ts` |
| 142 | + |
| 143 | +### Extending the Schema |
| 144 | + |
| 145 | +1. Update GraphQL schema in `src/schema/auth.gql` |
| 146 | +2. Update TypeScript types in `src/types.ts` |
| 147 | +3. Update adapter operations in `src/adapter/index.ts` |
| 148 | +4. Update documentation |
| 149 | + |
| 150 | +### Adding Client Hooks |
| 151 | + |
| 152 | +1. Add hook to `src/client/hooks.ts` |
| 153 | +2. Export from `src/index.ts` |
| 154 | +3. Add TypeScript types |
| 155 | +4. Document with JSDoc comments |
| 156 | +5. Add usage example to README |
| 157 | + |
| 158 | +## Questions? |
| 159 | + |
| 160 | +- Open an issue for bugs or feature requests |
| 161 | +- Start a discussion for questions or ideas |
| 162 | +- Tag maintainers for urgent issues |
| 163 | + |
| 164 | +## License |
| 165 | + |
| 166 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
0 commit comments