API architecture
WeGotWork uses two types of API implementations:Next.js API routes
API routes follow the Next.js App Router convention and are located at/api/* endpoints:
- Authentication:
/api/auth/*- Handled by Better Auth
Server actions
Server actions are the primary way to interact with the backend. They are TypeScript functions marked with"use server" and provide type-safe, direct server-side operations.
Server actions are organized by domain:
- Jobs: Create, edit, delete, and retrieve job postings
- Applicants: Manage job applicants and retrieve application data
- Organizations: Create and manage workspaces
- Categories: Organize jobs into custom categories
- Invitations: Invite team members to organizations
Server actions automatically handle session validation and redirect unauthenticated users to the login page.
Base URL
The API base URL depends on your environment:Response formats
Success responses
Successful server actions return objects with anerror: false field and the requested data:
Error responses
Error responses include anerror: true field and a descriptive message:
Error handling
WeGotWork uses consistent error handling patterns across all server actions:Authentication errors
Unauthenticated requests are redirected to the home page:Validation errors
Input validation uses Zod schemas. Validation failures return field-specific errors:Authorization errors
Unauthorized actions return a clear error message:Server errors
Unexpected errors are caught and return a generic error response:Common patterns
Session validation
All authenticated server actions follow this pattern:Data validation
Server actions use Zod for input validation:Path revalidation
Server actions that modify data use Next.jsrevalidatePath to update the cache:
Rate limiting
Currently, WeGotWork does not implement API rate limiting. Authentication is session-based with the following limits:- Session expires after 7 days
- Session is updated every 24 hours
- Cookie cache enabled for 1 hour
Next steps
Authentication
Learn how to authenticate with Better Auth
Server actions
Explore available server actions