How pittu777/health works
1. Overall shape
- This is a Next.js App Router project in TypeScript.
- The architecture is centered on an authentication flow rather than a broad application domain.
- The repo is split into route handlers, feature components, shared libraries, middleware, and tests.
2. UI route layer
- src/app/page.tsx is the top-level landing page.
- src/app/(auth)/login/page.tsx and src/app/(auth)/register/page.tsx define the public auth screens.
- src/app/layout.tsx and src/app/globals.css provide the application shell and global styling.
3. API boundary
- src/app/api/auth/login/route.ts
- src/app/api/auth/logout/route.ts
- src/app/api/auth/refresh/route.ts
- src/app/api/auth/register/route.ts
- These route handlers form the server-side contract for authentication operations and are the main backend entry points.
4. Auth flow and session lifecycle
- The presence of login, register, logout, and refresh endpoints indicates a session/token-based auth lifecycle.
- src/lib/auth.ts and src/lib/auth/session.ts appear to hold shared auth/session logic used by both route handlers and UI behavior.
- src/feature/auth/SessionRefresh.tsx suggests the client participates in keeping sessions alive or refreshing credentials.
5. Feature-oriented auth UI
- src/feature/auth/AuthForm.tsx, Login.tsx, Register.tsx, and Logout.tsx are the auth-specific presentation and interaction layer.
- This feature directory separates auth workflows from route definitions, which keeps the UI reusable and easier to diagram as a distinct subsystem.
6. Client-side auth state
- src/feature/hooks/useAuth.ts is the client-side hook boundary for auth state/behavior.
- This likely coordinates user/session status across components rather than embedding auth checks directly in pages.
7. Middleware and protection
- src/middleware/auth.middleware.ts is a request-level guard layer.
- It likely enforces access control or session validation before requests reach protected pages or APIs, making it a key architectural boundary between public and protected areas.
8. Domain and persistence layer
- src/models/user.model.ts represents the user domain entity/model.
- src/config/db.ts indicates a server-side database configuration boundary.
- Together these suggest the auth routes talk to a persistence layer through a model/config abstraction rather than directly from UI code.
9. Shared utilities and errors
- src/lib/AppError.ts provides application-specific error handling.
- src/lib/utils.ts contains shared helper logic.
- These support consistent server/client behavior without coupling auth features to framework-specific details.
10. Reusable UI primitives
- src/components/ui/button.tsx and src/components/ui/input.tsx are shared design-system style components.
- components.json suggests a component-scaffolding or design-system setup, likely used to standardize form controls across auth pages.
11. Testing boundary
- tests/auth/login.spec.ts and tests/auth/register.spec.ts are end-to-end or browser-style tests.
- playwright.config.ts confirms Playwright is used to validate auth flows from the user’s perspective, which means the test layer exercises the public pages and API-backed behavior together.
12. How data moves through the system
- A user interacts with the auth pages in src/app/(auth)/....
- UI components in src/feature/auth submit to /api/auth/* route handlers.
- Those handlers use shared auth/session logic, the user model, and DB configuration to validate or mutate user/session state.
- Middleware can intercept requests to enforce auth status.
- Client-side hooks/components then reflect or refresh that session state back in the UI.
13. Key diagram boundaries
- Browser/UI boundary: app pages, feature components, hooks, and reusable UI primitives.
- Server/API boundary: Next.js route handlers under /api/auth.
- Security boundary: middleware and session refresh logic.
- Persistence boundary: DB config plus user model.
- Quality boundary: Playwright auth specs validating the end-to-end flow.
Main entry points: auth.ts Auth Core · login/route.ts Login API · register/route.ts Register API · layout.tsx App Shell
Components 24
App Router
Public pages and API route handlers in the Next.js app directory.
- Home · Top-level landing page.
src/app/page.tsx - Login Page · Public login screen.
src/app/(auth)/login/page.tsx - Register Page · Public registration screen.
src/app/(auth)/register/page.tsx - App Shell · Global application layout.
src/app/layout.tsx - Globals · Global CSS for the app.
src/app/globals.css - Login API · Server endpoint for login.
src/app/api/auth/login/route.ts - Logout API · Server endpoint for logout.
src/app/api/auth/logout/route.ts - Refresh API · Server endpoint for session refresh.
src/app/api/auth/refresh/route.ts - Register API · Server endpoint for registration.
src/app/api/auth/register/route.ts
Auth Feature
Reusable auth UI and client-side session behavior.
- Auth Form · Shared form scaffolding for auth flows.
src/feature/auth/AuthForm.tsx - Login UI · Login workflow component.
src/feature/auth/Login.tsx - Register UI · Registration workflow component.
src/feature/auth/Register.tsx - Logout UI · Logout interaction component.
src/feature/auth/Logout.tsx - Session Refresh · Client-side session renewal behavior.
src/feature/auth/SessionRefresh.tsx - useAuth · Client auth state hook.
src/feature/hooks/useAuth.ts
Server Core
Shared auth logic, persistence, middleware, and errors.
- Auth Core · Shared auth operations and helpers.
src/lib/auth.ts - Session Logic · Session lifecycle helpers.
src/lib/auth/session.ts - DB Config · Database connection/configuration boundary.
src/config/db.ts - User Model · User entity and persistence model.
src/models/user.model.ts - App Error · Application-specific error abstraction.
src/lib/AppError.ts - Utils · Common utility functions.
src/lib/utils.ts - Auth Middleware · Request-level protection and session validation.
src/middleware/auth.middleware.ts
Tests
End-to-end auth flow coverage.
- Login Spec · Browser-level login flow test.
tests/auth/login.spec.ts - Register Spec · Browser-level registration flow test.
tests/auth/register.spec.ts
Connections 30
- App Shell → Home: wraps · Application shell frames the landing page.
- App Shell → Login Page: wraps · Application shell frames the login page.
- App Shell → Register Page: wraps · Application shell frames the register page.
- Globals → App Shell: styles · Global CSS supports the shell and pages.
- Login Page → Login UI: renders · Login route page composes the login feature.
- Register Page → Register UI: renders · Register route page composes the register feature.
- Login UI → Auth Form: uses · Login UI shares common auth form structure.
- Register UI → Auth Form: uses · Register UI shares common auth form structure.
- Login UI → Login API: submits to · Login UI posts credentials to the login API.
- Register UI → Register API: submits to · Register UI posts data to the register API.
- Logout UI → Logout API: calls · Logout UI invokes the logout endpoint.
- Session Refresh → Refresh API: refreshes · Client session refresh logic calls the refresh endpoint.
- useAuth → Session Refresh: coordinates · Auth hook coordinates session state and refresh behavior.
- Login API → Auth Core: uses · Login handler relies on shared auth logic.
- Register API → Auth Core: uses · Register handler relies on shared auth logic.
- Logout API → Session Logic: uses · Logout handler uses session lifecycle helpers.
- Refresh API → Session Logic: uses · Refresh handler uses session lifecycle helpers.
- Auth Core → Session Logic: depends on · Core auth logic builds on session helpers.
- Auth Core → DB Config: persists via · Auth logic uses database configuration.
- Auth Core → User Model: reads/writes · Auth logic operates on the user model.
- Login API → App Error: raises · Login failures are expressed through app errors.
- Register API → App Error: raises · Registration failures are expressed through app errors.
- Auth Core → Utils: uses · Shared helpers support auth operations.
- Auth Middleware → Session Logic: validates · Middleware checks session state before protected requests.
- Auth Middleware → Login API: guards · Middleware sits in front of auth-related requests.
- Auth Middleware → Register API: guards · Middleware sits in front of auth-related requests.
- Login Spec → Login Page: covers · Playwright spec exercises the login page.
- Login Spec → Login API: covers · Playwright spec exercises the login endpoint.
- Register Spec → Register Page: covers · Playwright spec exercises the register page.
- Register Spec → Register API: covers · Playwright spec exercises the register endpoint.