# gnshx/codepulse architecture

> Architecture diagram of the GitHub repository gnshx/codepulse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gnshx/codepulse
- Repository: https://github.com/gnshx/codepulse

## Overview

#### Purpose and Runtime
CodePulse is a modular-monolith competitive-programming intelligence platform: it ingests linked coding-platform activity, persists normalized history, computes learner analytics, and serves dashboards, recommendations, roadmaps, goals, and AI coaching. It runs as a Next.js 16 / React 19 TypeScript application, with background work delegated to Inngest.

Primary UI entry points are `src/app/page.tsx`, dashboard routes under `src/app/dashboard/`, and the root layout `src/app/layout.tsx`.

#### Application Boundary: App Router
The Next.js App Router provides server-rendered pages, route handlers, and server actions. Dashboard pages consume domain services rather than provider APIs directly; user-facing mutation/auth flows enter through actions and API endpoints.

Key boundaries:
- UI/dashboard: `src/app/dashboard/layout.tsx`, `src/app/dashboard/page.tsx`
- API endpoints: `src/app/api/analytics/route.ts`, `src/app/api/user/profile/route.ts`
- Auth actions: `src/app/actions/auth.ts`, `src/app/login/actions.ts`

#### Authentication and Identity
Auth.js supports credentials plus Google and GitHub OAuth. Authentication configuration, password handling, and input validation are isolated from UI and other domains.

Core paths: `src/modules/auth/config.ts`, `src/modules/auth/password.ts`, `src/app/api/auth/[...nextauth]/route.ts`.

#### Persistence and Read Performance
PostgreSQL is the source of truth, accessed through Prisma. The relational schema separates user/profile/platform activity from derived analytics, goals, achievements, and refresh history; migrations establish the durable contract. Redis is an optional fail-open read-through cache, not a correctness dependency.

Core paths: `prisma/schema.prisma`, `prisma/migrations/0_init/migration.sql`, `src/shared/db/client.ts`, `src/shared/cache/redis.ts`.

#### Platform Ingestion and Background Orchestration
Platform-specific adapters isolate external response formats for LeetCode and Codeforces. Synchronization is initiated asynchronously and processed by Inngest, preventing slow or unreliable provider calls from blocking requests. The job can coordinate provider work, normalization, persistence, and recomputation, with retries/concurrency controls supplied by Inngest.

Core paths: `src/modules/sync/service.ts`, `src/modules/leetcode/service.ts`, `src/modules/codeforces/service.ts`, `src/jobs/platform-refresh.ts`, `src/app/api/inngest/route.ts`.

#### Analytics and Derived Intelligence
Raw submissions are transformed into persisted learner signals: solved and attempted activity, acceptance rate, difficulty distribution, topic mastery, trends, and streaks. This persisted read model is the boundary between ingestion and consumers, keeping dashboard reads and downstream personalization efficient.

Core paths: `src/modules/analytics/service.ts`, `src/modules/learning/live-analytics.ts`, `src/app/api/analytics/route.ts`.

#### Personalization Consumers
Recommendation, learning/roadmap, goals, and AI modules consume analytics rather than provider-specific data. The AI service uses OpenAI when configured and falls back to deterministic analytics-based guidance, preserving core coaching behavior during provider failure.

Core paths: `src/modules/recommendations/service.ts`, `src/modules/goals/service.ts`, `src/modules/ai/service.ts`, `src/app/dashboard/roadmap/page.tsx`, `src/app/dashboard/ai-coach/page.tsx`.

#### External Infrastructure
Material integrations are PostgreSQL via Prisma, Upstash Redis, Inngest event/job infrastructure, LeetCode and Codeforces APIs, Auth.js OAuth providers, and optional OpenAI. Deployment is intended for Vercel; runtime configuration is represented by `prisma.config.ts` and Next.js configuration in `next.config.ts`.

Main entry points: [`src/modules/analytics/service.ts`](https://github.com/gnshx/codepulse/blob/main/src/modules/analytics/service.ts) (Analytics read model), [`src/app/dashboard/page.tsx`](https://github.com/gnshx/codepulse/blob/main/src/app/dashboard/page.tsx) (Dashboard pages), [`src/modules/sync/service.ts`](https://github.com/gnshx/codepulse/blob/main/src/modules/sync/service.ts) (Sync coordinator), [`src/shared/db/client.ts`](https://github.com/gnshx/codepulse/blob/main/src/shared/db/client.ts) (Prisma data access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_root_ui["Root UI and layout<br/>App Router UI<br/>[layout.tsx]"]
  node_dashboard["Dashboard pages<br/>server pages<br/>[page.tsx]"]
  node_auth_entry["Auth actions and route<br/>auth entrypoints<br/>[auth.ts]"]
  node_analytics_api["Analytics API<br/>route handler<br/>[route.ts]"]
  node_inngest_endpoint["Inngest endpoint<br/>route handler<br/>[route.ts]"]
end

subgraph group_domains["Domain services"]
  node_auth["Auth and identity<br/>Auth.js module<br/>[config.ts]"]
  node_analytics["Analytics read model<br/>derived intelligence<br/>[service.ts]"]
  node_recommendations["Recommendations<br/>personalization service<br/>[service.ts]"]
  node_goals["Goals<br/>personalization service<br/>[service.ts]"]
  node_ai_coach["AI coaching<br/>coaching service<br/>[service.ts]"]
end

subgraph group_platforms["Platform ingestion"]
  node_sync_service["Sync coordinator<br/>ingestion service<br/>[service.ts]"]
  node_platform_job["Platform refresh job<br/>Inngest job"]
  node_leetcode["LeetCode adapter<br/>provider adapter<br/>[service.ts]"]
  node_codeforces["Codeforces adapter<br/>provider adapter<br/>[service.ts]"]
end

subgraph group_data["Data and infrastructure"]
  node_prisma["Prisma data access<br/>database client<br/>[client.ts]"]
  node_postgres[("PostgreSQL<br/>system of record<br/>[schema.prisma]")]
  node_redis[("Redis cache<br/>fail-open cache<br/>[redis.ts]")]
end

subgraph group_external["External services"]
  node_inngest["Inngest<br/>job infrastructure"]
  node_provider_apis{{"Coding platform APIs<br/>external APIs"}}
  node_oauth{{"Google and GitHub OAuth<br/>identity providers"}}
  node_openai{{"OpenAI<br/>optional AI provider"}}
end

node_root_ui -->|"renders"| node_dashboard
node_dashboard -->|"reads signals"| node_analytics
node_dashboard -->|"gets guidance"| node_recommendations
node_dashboard -->|"manages"| node_goals
node_dashboard -->|"coaching"| node_ai_coach
node_auth_entry -->|"authenticates"| node_auth
node_auth -->|"OAuth"| node_oauth
node_auth -->|"identity data"| node_prisma
node_analytics_api -->|"serves"| node_analytics
node_inngest_endpoint -->|"receives events"| node_inngest
node_inngest -->|"executes"| node_platform_job
node_platform_job -->|"runs"| node_sync_service
node_sync_service -->|"fetches"| node_leetcode
node_sync_service -->|"fetches"| node_codeforces
node_leetcode -->|"LeetCode"| node_provider_apis
node_codeforces -->|"Codeforces"| node_provider_apis
node_sync_service -->|"normalizes and persists"| node_prisma
node_sync_service -->|"recomputes"| node_analytics
node_analytics -->|"stores read model"| node_prisma
node_prisma -->|"reads and writes"| node_postgres
node_analytics -.->|"caches reads"| node_redis
node_recommendations -->|"consumes"| node_analytics
node_goals -->|"consumes"| node_analytics
node_ai_coach -->|"consumes"| node_analytics
node_ai_coach -.->|"optional generation"| node_openai

click node_root_ui "https://github.com/gnshx/codepulse/blob/main/src/app/layout.tsx"
click node_dashboard "https://github.com/gnshx/codepulse/blob/main/src/app/dashboard/page.tsx"
click node_auth_entry "https://github.com/gnshx/codepulse/blob/main/src/app/actions/auth.ts"
click node_analytics_api "https://github.com/gnshx/codepulse/blob/main/src/app/api/analytics/route.ts"
click node_inngest_endpoint "https://github.com/gnshx/codepulse/blob/main/src/app/api/inngest/route.ts"
click node_auth "https://github.com/gnshx/codepulse/blob/main/src/modules/auth/config.ts"
click node_analytics "https://github.com/gnshx/codepulse/blob/main/src/modules/analytics/service.ts"
click node_recommendations "https://github.com/gnshx/codepulse/blob/main/src/modules/recommendations/service.ts"
click node_goals "https://github.com/gnshx/codepulse/blob/main/src/modules/goals/service.ts"
click node_ai_coach "https://github.com/gnshx/codepulse/blob/main/src/modules/ai/service.ts"
click node_sync_service "https://github.com/gnshx/codepulse/blob/main/src/modules/sync/service.ts"
click node_platform_job "https://github.com/gnshx/codepulse/blob/main/src/jobs/platform-refresh.ts"
click node_leetcode "https://github.com/gnshx/codepulse/blob/main/src/modules/leetcode/service.ts"
click node_codeforces "https://github.com/gnshx/codepulse/blob/main/src/modules/codeforces/service.ts"
click node_prisma "https://github.com/gnshx/codepulse/blob/main/src/shared/db/client.ts"
click node_postgres "https://github.com/gnshx/codepulse/blob/main/prisma/schema.prisma"
click node_redis "https://github.com/gnshx/codepulse/blob/main/src/shared/cache/redis.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root_ui,node_dashboard,node_auth_entry,node_analytics_api,node_inngest_endpoint toneBlue
class node_auth,node_analytics,node_recommendations,node_goals,node_ai_coach toneAmber
class node_sync_service,node_platform_job,node_leetcode,node_codeforces toneMint
class node_prisma,node_postgres,node_redis toneRose
class node_inngest,node_provider_apis,node_oauth,node_openai toneIndigo
```

## Components

### Next.js application

- [Root UI and layout](https://github.com/gnshx/codepulse/blob/main/src/app/layout.tsx): App Router UI · `src/app/layout.tsx`
- [Dashboard pages](https://github.com/gnshx/codepulse/blob/main/src/app/dashboard/page.tsx): server pages · Dashboard reads domain services instead of platform APIs. · `src/app/dashboard/page.tsx`
- [Auth actions and route](https://github.com/gnshx/codepulse/blob/main/src/app/actions/auth.ts): auth entrypoints · `src/app/actions/auth.ts`
- [Analytics API](https://github.com/gnshx/codepulse/blob/main/src/app/api/analytics/route.ts): route handler · `src/app/api/analytics/route.ts`
- [Inngest endpoint](https://github.com/gnshx/codepulse/blob/main/src/app/api/inngest/route.ts): route handler · `src/app/api/inngest/route.ts`

### Domain services

- [Auth and identity](https://github.com/gnshx/codepulse/blob/main/src/modules/auth/config.ts): Auth.js module · Credentials, OAuth, password handling, and validation boundary. · `src/modules/auth/config.ts`
- [Analytics read model](https://github.com/gnshx/codepulse/blob/main/src/modules/analytics/service.ts): derived intelligence · Persists learner signals for efficient downstream reads. · `src/modules/analytics/service.ts`
- [Recommendations](https://github.com/gnshx/codepulse/blob/main/src/modules/recommendations/service.ts): personalization service · `src/modules/recommendations/service.ts`
- [Goals](https://github.com/gnshx/codepulse/blob/main/src/modules/goals/service.ts): personalization service · `src/modules/goals/service.ts`
- [AI coaching](https://github.com/gnshx/codepulse/blob/main/src/modules/ai/service.ts): coaching service · Falls back to deterministic analytics-based guidance. · `src/modules/ai/service.ts`

### Platform ingestion

- [Sync coordinator](https://github.com/gnshx/codepulse/blob/main/src/modules/sync/service.ts): ingestion service · Coordinates provider work, normalization, persistence, and recomputation. · `src/modules/sync/service.ts`
- [Platform refresh job](https://github.com/gnshx/codepulse/blob/main/src/jobs/platform-refresh.ts): Inngest job · Runs sync asynchronously with retries and concurrency controls. · `src/jobs/platform-refresh.ts`
- [LeetCode adapter](https://github.com/gnshx/codepulse/blob/main/src/modules/leetcode/service.ts): provider adapter · `src/modules/leetcode/service.ts`
- [Codeforces adapter](https://github.com/gnshx/codepulse/blob/main/src/modules/codeforces/service.ts): provider adapter · `src/modules/codeforces/service.ts`

### Data and infrastructure

- [Prisma data access](https://github.com/gnshx/codepulse/blob/main/src/shared/db/client.ts): database client · `src/shared/db/client.ts`
- [PostgreSQL](https://github.com/gnshx/codepulse/blob/main/prisma/schema.prisma): system of record · Stores normalized activity and derived learner data. · `prisma/schema.prisma`
- [Redis cache](https://github.com/gnshx/codepulse/blob/main/src/shared/cache/redis.ts): fail-open cache · Optional read-through cache, not a correctness dependency. · `src/shared/cache/redis.ts`

### External services

- **Inngest**: job infrastructure
- **Coding platform APIs**: external APIs · LeetCode and Codeforces activity sources.
- **Google and GitHub OAuth**: identity providers
- **OpenAI**: optional AI provider

## Connections

- Root UI and layout → Dashboard pages: renders
- Dashboard pages → Analytics read model: reads signals
- Dashboard pages → Recommendations: gets guidance
- Dashboard pages → Goals: manages
- Dashboard pages → AI coaching: coaching
- Auth actions and route → Auth and identity: authenticates
- Auth and identity → Google and GitHub OAuth: OAuth
- Auth and identity → Prisma data access: identity data
- Analytics API → Analytics read model: serves
- Inngest endpoint → Inngest: receives events
- Inngest → Platform refresh job: executes
- Platform refresh job → Sync coordinator: runs
- Sync coordinator → LeetCode adapter: fetches
- Sync coordinator → Codeforces adapter: fetches
- LeetCode adapter → Coding platform APIs: LeetCode
- Codeforces adapter → Coding platform APIs: Codeforces
- Sync coordinator → Prisma data access: normalizes and persists
- Sync coordinator → Analytics read model: recomputes
- Analytics read model → Prisma data access: stores read model
- Prisma data access → PostgreSQL: reads and writes
- Analytics read model → Redis cache: caches reads
- Recommendations → Analytics read model: consumes
- Goals → Analytics read model: consumes
- AI coaching → Analytics read model: consumes
- AI coaching → OpenAI: optional generation
