Akari Art persists all application data in MongoDB Atlas through two Mongoose models:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nayalsaurav/Akari-Art/llms.txt
Use this file to discover all available pages before exploring further.
User (created under model/user.ts) and Post (created under model/post.ts). Both files export a Mongoose Model using the mongoose.models.Model || mongoose.model(...) pattern to avoid model re-registration across hot-reloads and serverless cold-starts. TypeScript interfaces extend Mongoose’s Document type so every model instance is fully typed throughout the codebase.
User Model
TheIUser interface and UserSchema are defined in model/user.ts:
User Field Reference
| Field | Type | Required | Notes |
|---|---|---|---|
_id | ObjectId | Auto | MongoDB-generated document identifier |
name | String | No | Display name pulled from Google profile |
email | String | Yes | Must be unique across the collection |
image | String | No | Avatar URL sourced from Google OAuth profile |
emailVerified | Date | null | No | Populated by NextAuth adapter conventions |
provider | "google" | "email" | No | OAuth provider used at sign-up |
createdAt | Date | Auto | Injected by Mongoose timestamps: true |
updatedAt | Date | Auto | Injected by Mongoose timestamps: true |
A user document is created automatically on the first successful Google sign-in. The
signIn callback in lib/auth.ts calls User.findOne({ email: user.email }) and, if no record exists, runs User.create({ name, email, image, provider }). Subsequent sign-ins with the same email skip creation entirely.Post Model
TheIPost interface and PostSchema are defined in model/post.ts:
Post Field Reference
| Field | Type | Required | Notes |
|---|---|---|---|
_id | ObjectId | Auto | MongoDB-generated document identifier |
name | String | Yes | Author’s display name, trimmed before save |
prompt | String | Yes | The text prompt used to generate the image, trimmed before save |
photo | String | Yes | Cloudinary secure_url — always an https://res.cloudinary.com/... URL |
The
photo field is always a res.cloudinary.com URL. Raw base64 image data from Cloudflare Workers AI is never stored in MongoDB — it is uploaded to Cloudinary inside app/api/image-generation/route.ts first, and only the resulting secure_url is written to the posts collection.Database Connection
lib/database.ts implements a global connection-caching pattern designed for Next.js serverless deployments:
types.d.ts:
How Connection Caching Works
On the first invocation ofdbConnect(), cached.conn is null so Mongoose initiates a new connection via mongoose.connect(). On every subsequent invocation within the same Node.js process (i.e., a warm serverless function), cached.conn is already populated and the function returns immediately — no new connection is opened.
maxPoolSize: 10 limits how many concurrent socket connections the Mongoose driver maintains inside a single process. This prevents connection exhaustion on MongoDB Atlas’s free or shared tiers when multiple Route Handlers execute concurrently.