-
Notifications
You must be signed in to change notification settings - Fork 0
docs: Add CLAUDE.md and mark safeServerCall with warning #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theodorklauritzen
wants to merge
2
commits into
main
Choose a base branch
from
docs/update-claude-md-and-mark-warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Project Next is the website for Sanctus Omega Broderskab, built with Next.js 16, TypeScript, Prisma, and PostgreSQL. The application runs in Docker containers for both development and production. | ||
|
|
||
| ## Development Commands | ||
|
|
||
| ### Running the Application | ||
|
|
||
| ```bash | ||
| npm run docker:dev | ||
| ``` | ||
| or | ||
| ```bash | ||
| docker compose -f docker-compose.dev.yml up --build | ||
| ``` | ||
|
|
||
| ### Testing | ||
|
|
||
| Run all tests: | ||
| ```bash | ||
| npm test | ||
| ``` | ||
|
|
||
| Tests use Jest with a custom Prisma test environment. The environment variable `IGNORE_SERVER_ONLY=true` is required for tests. | ||
|
|
||
| ### Linting | ||
|
|
||
| ```bash | ||
| npm run lint | ||
| ``` | ||
|
|
||
| Auto-fix linting errors: | ||
| ```bash | ||
| npm run lint -- --fix | ||
| ``` | ||
|
|
||
| ### Database Operations | ||
|
|
||
| Reseed the database (deletes all data and re-seeds): | ||
| ```bash | ||
| npm run docker:seed | ||
| ``` | ||
|
|
||
| Regenerate Prisma client after schema changes: | ||
| ```bash | ||
| npx prisma generate | ||
| ``` | ||
|
|
||
| Access Prisma Studio for database exploration: | ||
| ```bash | ||
| npm run prisma-studio | ||
| ``` | ||
|
|
||
| Access the container shell: | ||
| ```bash | ||
| docker exec -it -w /workspaces/projectNext pn-dev /bin/bash | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Service Layer Pattern | ||
|
|
||
| The codebase uses a ServiceOperation pattern for all business logic. Services are located in `src/services/` and organized by domain (e.g., `users`, `groups`, `cms`, `events`). | ||
|
|
||
| **Key concepts:** | ||
| - **ServiceOperation**: Core abstraction defined in `src/services/serviceOperation.ts`. All business logic is wrapped in ServiceOperations. | ||
| - **Server Actions**: Client-callable functions created by wrapping ServiceOperations with `makeAction()` from `src/services/serverAction.ts`. | ||
| - **Authorization**: Custom authorization system with Authorizer classes (see `src/auth/authorizer/`). Each ServiceOperation specifies its required permissions. | ||
| - **Transaction Management**: ServiceOperations can open database transactions via the `opensTransaction` option. | ||
|
|
||
| **Pattern example:** | ||
| ```typescript | ||
| // Define a ServiceOperation | ||
| const myServiceOperation = defineOperation({ | ||
| paramsSchema: z.object({ id: z.number() }), | ||
| dataSchema: z.object({ name: z.string() }), | ||
| authorizer: ({ params }) => MyAuthorizer.dynamicFields({ id: params.id }), | ||
| operation: async ({ params, data, session, prisma }) => { | ||
| // Business logic here | ||
| } | ||
| }) | ||
|
|
||
| // Wrap it as a Server Action for client use | ||
| export const myAction = makeAction(myServiceOperation) | ||
| ``` | ||
|
|
||
| ### Prisma Schema Organization | ||
|
|
||
| Prisma schemas are split into multiple domain-specific files in `src/prisma/schema/`: | ||
| - `schema.prisma` - Main configuration (generator, datasource) | ||
| - `user.prisma`, `group.prisma`, `cms.prisma`, etc. - Domain models | ||
|
|
||
| The Prisma client is generated to `generated/pn-prisma/` outside the src folder. | ||
|
|
||
| ### Authentication | ||
|
|
||
| - Uses NextAuth.js v4 with custom JWT tokens | ||
| - Auth configuration in `src/auth/nextAuth/` | ||
| - Session management via `ServerSession` and `Session` classes | ||
| - Custom visibility and authorization system | ||
|
|
||
| ### Path Aliases | ||
|
|
||
| The project uses extensive TypeScript path aliases (see `tsconfig.json`): | ||
| - `@/lib/*` → `src/lib/*` | ||
| - `@/components/*` → `src/app/_components/*` | ||
| - `@/services/*` → `src/services/*` | ||
| - `@/prisma-pn-client-instance` → `src/prisma/client.ts` | ||
| - `@/prisma-generated-pn-client` → `generated/pn-prisma/client.ts` | ||
| - Many more domain-specific aliases | ||
|
|
||
| ### Project Structure | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── app/ # Next.js app directory (pages, routes, layouts) | ||
| │ ├── _components/ # Shared React components | ||
| │ ├── api/ # API routes (NextAuth, etc.) | ||
| │ ├── admin/ # Admin pages | ||
| │ └── [feature]/ # Feature-specific pages | ||
| ├── auth/ # Authentication & authorization | ||
| │ ├── authorizer/ # Authorization classes | ||
| │ ├── session/ # Session management | ||
| │ └── nextAuth/ # NextAuth configuration | ||
| ├── services/ # Business logic layer (ServiceOperations) | ||
| │ ├── users/ | ||
| │ ├── groups/ | ||
| │ ├── cms/ | ||
| │ └── [domain]/ # Domain-specific services | ||
| ├── prisma/ # Database | ||
| │ ├── schema/ # Prisma schema files (split by domain) | ||
| │ ├── seeder/ # Database seeding | ||
| │ └── client.ts # Prisma client instance | ||
| ├── lib/ # Utility libraries | ||
| │ ├── jwt/ # JWT token utilities | ||
| │ ├── dates/ # Date handling (Luxon) | ||
| │ └── paging/ # Pagination utilities | ||
| ├── contexts/ # React contexts | ||
| ├── hooks/ # React hooks | ||
| ├── styles/ # Global SCSS styles | ||
| └── typings/ # TypeScript type definitions | ||
|
|
||
| generated/ | ||
| └── pn-prisma/ # Generated Prisma client | ||
| ``` | ||
|
|
||
| ### CMS System | ||
|
|
||
| The project includes a custom CMS for content management: | ||
| - CMS components in `src/app/_components/Cms/` | ||
| - CMS services in `src/services/cms/` | ||
| - Articles, sections, paragraphs, images, and links as composable content parts | ||
| - Edit mode for authorized users | ||
|
|
||
| ## Important Patterns | ||
|
|
||
| ### Server-Only Code | ||
|
|
||
| Files that must run only on the server import `'@pn-server-only'` at the top. This is enforced to prevent accidental client-side execution of sensitive code. | ||
|
|
||
| ### Error Handling | ||
|
|
||
| - Service operations use custom error classes from `src/services/error.ts` | ||
| - `Smorekopp` - Base error class for service errors | ||
| - `ParseError` - Validation/parsing errors | ||
| - Error handling is managed internally by the ServiceOperation system via `makeAction()` | ||
|
|
||
| ### Form Handling | ||
|
|
||
| Forms typically use Server Actions with FormData: | ||
| 1. Define a dataSchema using `zod-form-data` (`zfd`) | ||
| 2. Create a ServiceOperation with the schema | ||
| 3. Wrap it with `makeAction()` | ||
| 4. Call from a client component with FormData | ||
|
|
||
| ## Testing | ||
|
|
||
| - Tests located in `tests/` directory | ||
| - Custom Prisma test environment (`tests/PrismaTestEnvironment.ts`) | ||
| - Test setup in `tests/setup.ts` | ||
| - Use `IGNORE_SERVER_ONLY=true` environment variable when running tests | ||
|
|
||
| ## Migration from OmegaWeb Basic | ||
|
|
||
| The project includes migration tooling from an older system (OmegaWeb Basic): | ||
| - Schema in `src/prisma/owSchema/` | ||
| - Migration command: `npm run dobbelOmega:run` | ||
| - Only relevant for data migration tasks | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong.
opensTransactionindicates that the service is going to open a transaction. This does not open a transaction automatically. Such an argument is needed as nesting transactions is not possible, thus to make the typing and internal validation work a service need to know it can be called from within another transaction. If you have a better name suggestion go ahead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the doc string for
define Operationdisappeared at some point... 😞There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the doc string for
define Operationdisappeared at some point... 😞