A Next.js 15 app that browses characters from the public Rick & Morty GraphQL API. Visitors complete a quick profile registration that persists to a cookie before exploring the character catalogue, with both page and modal detail experiences.
- Tech stack
- Key features
- Project layout
- Architecture overview
- Routing
- Data fetching
- Profile & cookies
- UI components
- Styling
- Environment variables
- Getting started
- Available scripts
- Next.js App Router (app/layout.tsx, app/page.tsx)
- React 19
- Apollo Client + GraphQL (lib/gql/apolloClient.ts, lib/gql/queries.ts)
- Tailwind CSS v4 (app/globals.css, postcss.config.mjs)
- Radix UI primitives wrapped with shadcn-inspired components (components/ui)
- Root route redirects to the paginated
/informationcatalogue viaHome. - Character grid with both dedicated page and modal detail routes.
- Cookie-backed profile registration gate enforced by
middleware. - Reusable form, card, dialog, and pagination components for consistent UI.
| Area | Description |
|---|---|
| app/(main) | Authenticated layouts, information catalogue, and profile pages. |
| app/(auth) | Registration flow shown until the profile cookie is present. |
| components | Shared UI primitives, layout chrome, and feature components. |
| lib | Apollo client configuration plus utilities (e.g., pagination helpers). |
| types | TypeScript definitions for characters and profile data. |
| public | Static assets, including the Rick & Morty logo. |
RootLayoutsets global fonts, mountsSiteFooter, and seeds context withgetUserFromCookies.- Authenticated pages share
MainLayout, which fixes theSiteHeaderabove the main content. Homeimmediately redirects to/informationto centralize onboarding.
- Catalogue:
CharactersPagerenders the paginated grid and description. - Pagination handler:
CharactersPaginationwrapsPaginationsto sync query params. - Character detail (page):
CharacterDetailsPagedisplaysCharacterDetails. - Character detail (modal):
CharacterDetailsModalPageopensCharacterDetailsModalalongside the list. - Registration:
RegisterPagecompletes onboarding then forwards users to/information. - Profile management:
ProfilePagelets users review or update stored data. - Not found:
NotFoundPagehandles unknown routes.
- Apollo client is configured in
clientusingGQL_ENDPOINT. - Catalogue queries use
GET_CHARACTERS_QUERY; detail views useGET_CHARACTER_DETAIL. - Errors surface as
PageErrorwith descriptive messaging.
/api/registerPOST/GET (route) persists{ username, jobTitle }into theusercookie.middlewarerequires the cookie before allowing/,/information, and/profile.- Forms reuse
ProfileForm, pulling the initial value fromUserContext.
- Characters:
CharacterCard,CharacterDetails,CharacterInfo,CharacterDetailsModal. - Pagination:
PaginationswithgetPaginationPagesfor compact page sets. - Shared primitives:
PageTitle,Button,Card,Dialog,Input,Field,Label,Separator.
- Theme tokens and global styles live in app/globals.css.
- Tailwind/PostCSS setup is defined in postcss.config.mjs; shadcn component registry resides in components.json.
Set in .env.local or .env.production:
GQL_ENDPOINT– GraphQL API endpoint (defaults to the official API).CHALLENGE_VERSION– Rendered bySiteFooter.
- Install dependencies:
npm install
- Start the dev server:
npm run dev
- Visit http://localhost:3000 — unauthenticated users are redirected to
/registeruntil theusercookie is set. - Build and run production:
npm run build npm start
npm run dev– Launch the Turbopack dev server.npm run build– Produce an optimized production build.npm start– Serve the production build.npm run lint– Run ESLint with eslint.config.mjs.