How lathiya50/codereviewai works
This repository is a Next.js 16 application organized as a full-stack product with a clear split between presentation, typed application APIs, server-side domain services, and background processing.
High-level architecture
The system centers on one workflow: GitHub pull requests are ingested, analyzed by an AI service, stored in PostgreSQL, and then surfaced in a dashboard with analytics and review detail views.
There are four major architectural surfaces:
1. Web UI
- Public marketing/landing experience
- Authentication screens
- Protected dashboard for repositories, reviews, pull requests, and analytics
2. Application API layer
- tRPC endpoints for typed client-server communication
- Auth callback/session routes
- GitHub webhook route
- Inngest webhook/worker route
3. Server domain layer
- Database access via Prisma
- GitHub integration services
- AI review orchestration and provider abstraction
- Background job functions
4. Persistence and external services
- PostgreSQL database
- GitHub API and webhooks
- AI model providers
- Inngest for asynchronous processing
- Better Auth for GitHub OAuth/session management
Frontend structure
The app uses the Next.js App Router with route groups that separate unauthenticated and authenticated experiences:
• src/app/(auth)/...
- Sign-in and sign-up pages
- Auth layout
• src/app/(dashboard)/...
- Analytics page
- Repositories list and repository detail pages
- Pull request detail and comparison views
- Reviews page
- Dashboard layout
The dashboard UI is built from reusable component modules under src/components, with specialized subdomains for:
• analytics charts and KPI cards
• code diff / comparison rendering
• review result display
• session protection and GitHub connection prompts
• shared UI primitives
This indicates a strong “page shell + domain component” pattern: route-level pages assemble reusable widgets rather than embedding business logic in the UI.
Authentication and session boundary
Authentication is handled through Better Auth with GitHub OAuth:
• src/app/api/auth/[...all]/route.ts handles the auth server routes
• src/lib/auth-client.ts provides client-side auth integration
• src/server/auth/index.ts contains server auth setup
• src/components/session-guard.tsx protects authenticated areas
• src/app/(dashboard)/layout.tsx is the main gated shell for signed-in users
The boundary here is important: the UI assumes authenticated access for dashboard routes, while auth state and session lifecycle are managed server-side and surfaced to the client through the auth client and session guard.
API layer
The application exposes multiple server entry points, each with a different responsibility:
tRPC
• src/app/api/trpc/[trpc]/route.ts
• Server routers under src/server/api/routers/
- analytics.ts
- pull-request.ts
- respository.ts "repository" appears misspelled in the tree
- review.ts
• src/server/api/root.ts composes the routers
• src/server/api/trpc.ts configures the tRPC context/runtime
• src/lib/trpc/client.ts, provider.tsx, and index.ts connect the frontend to these endpoints
This is the main typed application API for dashboard data. The frontend likely uses it for repository lists, review history, analytics, and pull request metadata.
GitHub webhooks
• src/app/api/webhooks/github/route.ts
This is the external event ingress point. GitHub pushes PR events into the system here, and those events initiate asynchronous review processing.
Inngest
• src/app/api/inngest/route.ts
• src/server/inngest/client.ts
• src/server/inngest/index.ts
• src/server/inngest/functions/review-pr.ts
This is the background job boundary. Instead of doing review analysis synchronously inside the webhook request, the app offloads work into Inngest for reliability, retries, and non-blocking processing.
Background processing flow
The background review pipeline is one of the most important parts of the architecture:
1. A GitHub webhook is received for a repository or pull request event.
2. The event is translated into a background job or triggered review task.
3. Inngest runs the review-pr function.
4. That function fetches PR data and diff context from GitHub services.
5. The AI review service generates structured feedback and risk assessment.
6. Review results are persisted to the database.
7. Comments/suggestions may be posted back to GitHub.
8. The dashboard later reads the stored results for display and analytics.
This flow cleanly separates:
• external event ingestion
• asynchronous processing
• data persistence
• user-facing visualization
Domain services
GitHub integration
• src/server/services/github.ts
This service is the repository’s GitHub boundary. It likely encapsulates fetching repositories, PR metadata, diffs, file changes, and posting review comments. Keeping this as a dedicated service isolates GitHub API concerns from UI and AI logic.
AI review service
• src/server/services/ai/
- index.ts
- review.ts
- registry.ts
- types.ts
- providers/openai.ts
- providers/groq.ts
This layer abstracts model-specific behavior behind a provider registry. The important architecture point is that review generation is not hardwired to a single model API; it is mediated by a provider interface, allowing the system to switch or route between model backends.
The AI service is responsible for turning code context into:
• review comments
• suggestions
• risk scores or severity classifications
• structured result payloads suitable for persistence and UI rendering
The README mentions Gemini/OpenAI, while the tree shows OpenAI and Groq providers, so the stable architectural idea is “pluggable LLM providers” rather than a single vendor.
Persistence boundary
• prisma/schema.prisma
• src/server/db/index.ts
The database is PostgreSQL accessed through Prisma. The schema is the system of record for:
• users
• OAuth accounts and sessions
• repositories
• review records
This storage layer sits behind the tRPC routers, GitHub sync services, and background jobs. The frontend never talks directly to the database.
From the README and structure, the stored domain entities appear to drive most screens:
• repository list and detail pages
• pull request review history
• analytics dashboards
• review status tracking
Data access pattern
The likely data path is:
• UI components call tRPC procedures
• tRPC procedures call server domain services
• services read/write Prisma models
• responses are returned to the UI through typed contracts
This gives the app a clean boundary between presentation and server logic, and it makes the dashboard screens data-driven rather than client-state-heavy.
Dashboard and analytics subsystem
The analytics area is a distinct subsystem under src/components/analytics and src/app/(dashboard)/analytics.
It contains specialized visualizations such as:
• stats cards
• activity heatmap
• review charts
• risk distribution
• repository leaderboard
• top issues
This indicates the product is not just a review inbox; it also aggregates review history into operational metrics. Those metrics likely come from the analytics tRPC router backed by the review and repository tables.
Review and diff visualization subsystem
The app contains several components specifically for presenting AI findings alongside source changes:
• code-diff.tsx
• diff-viewer.tsx
• code-comparison.tsx
• suggestion-diff-viewer.tsx
• review-result.tsx
• review-comparison-card.tsx
These components suggest a user flow where a reviewer can inspect:
• raw code changes
• AI-generated commentary
• suggested fixes
• before/after comparison context
This is an important presentation boundary because the product is not merely listing reviews; it is rendering AI output in a developer-friendly diff-oriented format.
Route and navigation structure
The app is split into:
• a landing/home experience at src/app/page.tsx
• authenticated application routes under (dashboard)
• auth flows under (auth)
There are also app-level files for:
• global styles
• error handling
• not-found handling
• icon and Open Graph assets
This indicates a conventional consumer-facing SaaS layout with a public entry point and a protected product area.
Cross-cutting UI infrastructure
Several reusable support layers are present:
• src/components/theme-provider.tsx and theme-toggle.tsx for light/dark mode
• src/components/header.tsx and user-menu.tsx for app shell navigation
• src/components/ui/* for shared design system primitives
• src/lib/motion.ts and animated UI components for motion and transitions
• src/lib/utils.ts for shared UI helpers
These do not change the core business architecture, but they explain how the UI shell is assembled consistently across pages.
External integration summary
The repository depends on a few external systems that materially shape the architecture:
• GitHub: source of auth, repo metadata, pull request events, and comment posting
• PostgreSQL: durable storage for users, repositories, reviews, and sessions
• Better Auth: session and OAuth identity management
• AI provider APIs: review generation and risk scoring
• Inngest: asynchronous review execution and background reliability
Diagram-oriented mental model
If you were drawing this system, the clearest structure would be:
• A browser/UI layer at the top
• A Next.js application layer in the middle with:
- App Router pages
- tRPC routes
- auth routes
- webhook routes
- Inngest route
• A server domain layer beneath that with:
- auth
- GitHub integration
- AI review orchestration
- review/background jobs
- database access
• External systems on the side:
- GitHub
- AI provider APIs
- PostgreSQL
- Inngest
The dominant data flow is event-driven for PR reviews, while the dashboard flow is request/response via tRPC over persisted data.
Core architectural takeaway
This repo is a SaaS-style AI code review platform where the frontend is mostly a consumer of typed server APIs, and the real business logic lives in server services and background jobs. The two most important seams are:
1. GitHub event ingestion to background AI review processing
2. Persisted review data back to dashboard analytics and PR detail views
Those two seams define the system’s main runtime behavior and should be the primary focus of any architecture diagram.
Main entry points: root.ts API Routers · review-pr.ts Review Job · (dashboard) Dashboard · header.tsx App Shell
Components 20
Web UI
Public landing, auth screens, and protected dashboard surfaces.
- Landing · Public home and marketing entry point.
src/app/page.tsx - Auth Pages · Sign-in and sign-up route group for unauthenticated users.
src/app/(auth) - Dashboard · Signed-in shell for repositories, reviews, pull requests, and analytics.
src/app/(dashboard) - Analytics UI · Charts and KPI components for review metrics and repository ranking.
src/components/analytics - Review UI · Code diff, comparison, and AI review presentation components.
src/components/review-result.tsx - App Shell · Header, session guard, theme, and shared design primitives.
src/components/header.tsx
Application API
Next.js server entry points for typed APIs, auth, webhooks, and jobs.
- tRPC Route · Typed client-server entry point for dashboard data.
src/app/api/trpc/[trpc]/route.ts - Auth Route · Better Auth server route handling OAuth and session lifecycle.
src/app/api/auth/[...all]/route.ts - GitHub Webhook · Receives pull request and repository events from GitHub.
src/app/api/webhooks/github/route.ts - Inngest Route · Webhook and worker entry point for background execution.
src/app/api/inngest/route.ts
Server Domain
Auth, data access, GitHub integration, AI orchestration, and background jobs.
- API Routers · Composed application routers for analytics, repositories, pull requests, and reviews.
src/server/api/root.ts - Auth Setup · Server-side authentication configuration and session handling.
src/server/auth/index.ts - GitHub Service · Encapsulates GitHub API access, PR metadata, diffs, and comment posting.
src/server/services/github.ts - AI Review · Provider-agnostic review generation and risk scoring.
src/server/services/ai/review.ts - Model Registry · Routes review requests across model backends and provider implementations.
src/server/services/ai/registry.ts - Review Job · Inngest function that fetches context, runs AI review, persists results, and may post comments.
src/server/inngest/functions/review-pr.ts
External Systems
Durable storage and third-party services used by the product.
- PostgreSQL · Primary persistence for users, repositories, reviews, sessions, and analytics data.
prisma/schema.prisma - GitHub · Source of authentication, repository data, pull request events, and review commenting.
- AI Providers · LLM backends used for structured code review generation.
- Inngest · Asynchronous job orchestration and retry infrastructure.
Connections 23
- Landing → App Shell: renders · Public pages compose shared UI primitives and navigation.
- Auth Pages → Auth Route: auth · Auth screens depend on the Better Auth server route.
- Dashboard → Analytics UI: uses · Dashboard pages assemble analytics widgets for metrics views.
- Dashboard → Review UI: uses · Dashboard pages render diffs and AI review results.
- Dashboard → App Shell: guards · Authenticated shell and session guard protect dashboard routes.
- App Shell → Auth Route: session · Client auth state is backed by server auth endpoints.
- tRPC Route → API Routers: serves · tRPC route dispatches into composed application routers.
- API Routers → PostgreSQL: reads/writes · Routers access persisted repositories, reviews, analytics, and sessions.
- API Routers → GitHub Service: fetches · Domain routers use GitHub data for repository and pull request views.
- API Routers → AI Review: returns review data · Review-related procedures surface AI-generated results and status.
- Auth Route → Auth Setup: delegates · Auth route is backed by server-side Better Auth setup.
- Auth Setup → PostgreSQL: sessions · Authentication relies on persisted users and session records.
- GitHub Webhook → GitHub: receives · Webhook route ingests GitHub repository and pull request events.
- GitHub Webhook → Inngest Route: triggers · Incoming events are handed off for asynchronous processing.
- Inngest Route → Inngest: executes · Inngest route connects the app to background job orchestration.
- Review Job → GitHub Service: loads PRs · Background review function fetches repository and diff context.
- Review Job → AI Review: analyzes · Review job invokes AI review generation.
- AI Review → Model Registry: routes · AI review layer selects provider implementations through a registry.
- Model Registry → AI Providers: calls · Provider implementations connect to external model APIs.
- Review Job → PostgreSQL: persists · Generated review results and status are stored durably.
- Review Job → GitHub: comments · Review output may be posted back to GitHub as comments or suggestions.
- Analytics UI → API Routers: queries · Charts and metrics read from typed application procedures.
- Review UI → API Routers: queries · Review detail views load repository and pull request data through tRPC.