How inkithai/nexus works
Purpose and Runtime
Nexus is a small authenticated internal portal: users register/login, then create and read team announcements. It is a Next.js 14 App Router application running on Node.js with React/TypeScript and Tailwind CSS. Primary browser entry points are the root redirect, login page, and protected dashboard: app/page.tsx, app/login/page.tsx, app/dashboard/page.tsx.
Routing and UI Composition
Next.js file-based routing owns navigation and API dispatch. The root layout supplies application-wide document/UI structure in app/layout.tsx. The dashboard composes the announcement vertical slice from components/announcements/announcement-form.tsx, components/announcements/announcement-list.tsx, and components/announcements/announcement-card.tsx. Client-side state is intentionally local to this slice; submit/refresh behavior keeps the displayed list current.
Authentication Boundary
Custom session authentication uses HTTP-only cookies rather than browser-managed tokens. Auth lifecycle endpoints are app/api/auth/register/route.ts, app/api/auth/login/route.ts, app/api/auth/logout/route.ts, with current-user lookup at app/api/auth/me/route.ts. Session creation, verification, and cookie handling are centralized in lib/auth/session.ts; passwords are bcrypt-hashed before persistence.
Authorization Control Flow
middleware.ts is the outer route-protection boundary, preventing unauthenticated access to protected navigation before page handling. API handlers also validate the session, so browser UI protection is not the sole access control. Typical flow: unauthenticated user reaches login/register → login sets an HTTP-only session cookie → middleware admits dashboard requests → dashboard/API calls identify the current session user → logout clears it.
Announcement API and Data Flow
app/api/announcements/route.ts exposes the announcement resource with GET for ordered reads and POST for creation. The browser dashboard fetches announcements, renders cards, and submits form data to this route; successful writes trigger the list update. Server-side validation (Zod per project design) and authenticated-user resolution form the trust boundary between UI inputs and database writes.
Persistence Model
Prisma is the data access layer, with one reusable client in lib/prisma.ts and relational User/Announcement definitions in prisma/schema.prisma. Announcements are associated with their author through schema foreign keys; API reads can return author data for card rendering. SQLite is the only required datastore, configured through DATABASE_URL; Prisma migrations are tracked under prisma/migrations.
Infrastructure and Configuration
Required environment inputs are documented in .env.example: DATABASE_URL for the local SQLite file and AUTH_SECRET for session security. The application depends on Next.js server route handlers, Prisma-generated database client, SQLite, bcrypt, Zod, and browser cookie support. Styling is Tailwind-driven with global baseline styles in app/globals.css.
Main entry points: page.tsx Protected dashboard · login/route.ts Auth endpoints · announcements/route.ts Announcements API · prisma.ts Prisma client
Components 16
Browser UI
- Login / register
app/login/page.tsx - Protected dashboard
app/dashboard/page.tsx - Announcement form
components/announcements/announcement-form.tsx - Announcement list · Locally refreshes displayed announcements after writes.
components/announcements/announcement-list.tsx - Announcement card
components/announcements/announcement-card.tsx - Global styles
app/globals.css
Next.js application
- Root redirect
app/page.tsx - App layout · Provides document structure and global UI baseline.
app/layout.tsx - Route middleware · Blocks unauthenticated protected navigation before page handling.
middleware.ts - Auth endpoints · Register, login, logout, and current-user API lifecycle.
app/api/auth/login/route.ts - Announcements API · Authenticated GET reads and validated POST creation.
app/api/announcements/route.ts - Session service · Creates and verifies HTTP-only cookie sessions.
lib/auth/session.ts - Runtime secrets · DATABASE_URL configures SQLite; AUTH_SECRET secures sessions.
.env.example
Persistence
- Prisma client · Reusable server database client.
lib/prisma.ts - User + Announcement schema · Defines author relationship and foreign keys.
prisma/schema.prisma - SQLite database
Connections 19
- Root redirect → Login / register: redirects unauthenticated users
- App layout → Protected dashboard: wraps
- App layout → Global styles: loads
- Route middleware → Protected dashboard: admits authenticated requests
- Login / register → Auth endpoints: registers / logs in
- Protected dashboard → Auth endpoints: gets current user
- Protected dashboard → Announcement form: composes
- Protected dashboard → Announcement list: composes
- Announcement list → Announcement card: renders
- Announcement form → Announcements API: POST announcement
- Announcement list → Announcements API: GET announcements
- Auth endpoints → Session service: creates and verifies session
- Announcements API → Session service: resolves authenticated user
- Auth endpoints → Prisma client: persists users
- Announcements API → Prisma client: reads and writes announcements
- Prisma client → User + Announcement schema: uses model definitions
- Prisma client → SQLite database: queries
- Runtime secrets → Session service: provides AUTH_SECRET
- Runtime secrets → SQLite database: provides DATABASE_URL