# rituraj2003/bitesize-backend architecture

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

- Interactive diagram: https://gitdiagram.com/rituraj2003/bitesize-backend
- Repository: https://github.com/rituraj2003/bitesize-backend

## Overview

BiteSize is a backend for developer micro-learning: a client authenticates, manages searchable code snippets, and reviews eligible flashcards; it can also request AI-generated explanations. The main API routes own database and AI calls, while authentication middleware verifies tokens and Prisma connects to PostgreSQL. The README documents PostgreSQL full-text search and spaced-repetition scheduling, and the sampled snippet routes show those operations. The optional AI microservice and in-process Gemini fallback are visible in source. The frontend and hosted database are documented external systems; unsampled schema details are not expanded here.

Main entry points: [`src/app.ts`](https://github.com/rituraj2003/bitesize-backend/blob/main/src/app.ts) (Express app), [`src/routes/auth.routes.ts`](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/auth.routes.ts) (Auth routes), [`src/routes/ai.routes.ts`](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/ai.routes.ts) (AI explain route), [`src/routes/snippet.routes.ts`](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/snippet.routes.ts) (Snippet and review routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_server["HTTP server<br/>[server.ts]"]
  node_app["Express app<br/>[app.ts]"]
  node_errors["Error handling<br/>[errorHandler.ts]"]
end

subgraph group_identity["Identity"]
  node_auth_routes["Auth routes<br/>[auth.routes.ts]"]
  node_auth_middleware["Token middleware<br/>[authMiddleware.ts]"]
  node_auth_utils["Password and JWT<br/>[auth.ts]"]
end

subgraph group_learning["Learning features"]
  node_snippet_routes["Snippet and review routes<br/>[snippet.routes.ts]"]
  node_prisma["Prisma client<br/>[prisma.ts]"]
  node_database[("PostgreSQL database")]
end

subgraph group_ai["AI analysis"]
  node_ai_routes["AI explain route<br/>[ai.routes.ts]"]
  node_ai_service["AI microservice<br/>[index.ts]"]
  node_gemini["Google Gemini"]
end

node_client(("Frontend client"))

node_client -->|"sends REST requests"| node_server
node_server -->|"starts"| node_app
node_app -->|"dispatches auth"| node_auth_routes
node_app -->|"dispatches learning"| node_snippet_routes
node_app -->|"dispatches AI"| node_ai_routes
node_app -->|"registers handler"| node_errors
node_auth_routes -->|"reads and writes users"| node_prisma
node_auth_routes -->|"hashes and signs"| node_auth_utils
node_auth_middleware -->|"verifies tokens"| node_auth_utils
node_auth_routes -->|"protects profile"| node_auth_middleware
node_snippet_routes -->|"protects endpoints"| node_auth_middleware
node_snippet_routes -->|"searches and updates snippets"| node_prisma
node_prisma -->|"queries"| node_database
node_ai_routes -->|"protects endpoint"| node_auth_middleware
node_ai_routes -.->|"forwards analysis"| node_ai_service
node_ai_routes -->|"generates fallback analysis"| node_gemini
node_ai_service -->|"generates analysis"| node_gemini
node_auth_routes -->|"forwards failures"| node_errors
node_snippet_routes -->|"forwards failures"| node_errors
node_ai_routes -->|"forwards failures"| node_errors

click node_server "https://github.com/rituraj2003/bitesize-backend/blob/main/src/server.ts"
click node_app "https://github.com/rituraj2003/bitesize-backend/blob/main/src/app.ts"
click node_errors "https://github.com/rituraj2003/bitesize-backend/blob/main/src/middleware/errorHandler.ts"
click node_auth_routes "https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/auth.routes.ts"
click node_auth_middleware "https://github.com/rituraj2003/bitesize-backend/blob/main/src/middleware/authMiddleware.ts"
click node_auth_utils "https://github.com/rituraj2003/bitesize-backend/blob/main/src/utils/auth.ts"
click node_snippet_routes "https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/snippet.routes.ts"
click node_prisma "https://github.com/rituraj2003/bitesize-backend/blob/main/src/db/prisma.ts"
click node_ai_routes "https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/ai.routes.ts"
click node_ai_service "https://github.com/rituraj2003/bitesize-backend/blob/main/services/ai-service/src/index.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_server,node_app,node_errors,node_client toneBlue
class node_auth_routes,node_auth_middleware,node_auth_utils toneAmber
class node_snippet_routes,node_prisma,node_database toneMint
class node_ai_routes,node_ai_service,node_gemini toneRose
```

## Components

### API runtime

- [HTTP server](https://github.com/rituraj2003/bitesize-backend/blob/main/src/server.ts): `src/server.ts`
- [Express app](https://github.com/rituraj2003/bitesize-backend/blob/main/src/app.ts): `src/app.ts`
- [Error handling](https://github.com/rituraj2003/bitesize-backend/blob/main/src/middleware/errorHandler.ts): `src/middleware/errorHandler.ts`

### Identity

- [Auth routes](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/auth.routes.ts): `src/routes/auth.routes.ts`
- [Token middleware](https://github.com/rituraj2003/bitesize-backend/blob/main/src/middleware/authMiddleware.ts): `src/middleware/authMiddleware.ts`
- [Password and JWT](https://github.com/rituraj2003/bitesize-backend/blob/main/src/utils/auth.ts): `src/utils/auth.ts`

### Learning features

- [Snippet and review routes](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/snippet.routes.ts): `src/routes/snippet.routes.ts`
- [Prisma client](https://github.com/rituraj2003/bitesize-backend/blob/main/src/db/prisma.ts): `src/db/prisma.ts`
- **PostgreSQL database**

### AI analysis

- [AI explain route](https://github.com/rituraj2003/bitesize-backend/blob/main/src/routes/ai.routes.ts): `src/routes/ai.routes.ts`
- [AI microservice](https://github.com/rituraj2003/bitesize-backend/blob/main/services/ai-service/src/index.ts): `services/ai-service/src/index.ts`
- **Google Gemini**

### Other components

- **Frontend client**

## Connections

- Frontend client → HTTP server: sends REST requests
- HTTP server → Express app: starts
- Express app → Auth routes: dispatches auth
- Express app → Snippet and review routes: dispatches learning
- Express app → AI explain route: dispatches AI
- Express app → Error handling: registers handler
- Auth routes → Prisma client: reads and writes users
- Auth routes → Password and JWT: hashes and signs
- Token middleware → Password and JWT: verifies tokens
- Auth routes → Token middleware: protects profile
- Snippet and review routes → Token middleware: protects endpoints
- Snippet and review routes → Prisma client: searches and updates snippets
- Prisma client → PostgreSQL database: queries
- AI explain route → Token middleware: protects endpoint
- AI explain route → AI microservice: forwards analysis
- AI explain route → Google Gemini: generates fallback analysis
- AI microservice → Google Gemini: generates analysis
- Auth routes → Error handling: forwards failures
- Snippet and review routes → Error handling: forwards failures
- AI explain route → Error handling: forwards failures
