AgenticPacks
Getting started

Architecture

Learn how the app, the services, and the worker are split.

The repository is split so that a page never talks to the database directly. UI calls a service or an API route. The service is where Prisma, Stripe, and the model call live.

This page covers those layers, the shape every service returns, and where the credit balance is allowed to live.

Layers

src/app and src/components are the UI. They render pages and route handlers. They do not import Prisma.

src/services is the business logic. Chat, Stripe, and, on Pro, file search, teams, and the agent queue are implemented here.

src/lib is shared infrastructure: the Prisma client, env parsing, the error types, and the logger. Auth.js lives in this folder too, not under services.

One Next.js process serves pages and API routes. Postgres is the only data store. The credit balance is a column on the user, read from the database when the UI needs it.

The Next.js process still serves pages and API routes. A second process, packages/agent-worker, consumes the BullMQ queue and runs the LangGraph graph. Both processes ship in one image. The app command is node server.js. The worker command is node dist/worker.mjs.

Redis holds the queue, the cache, and rate limits. Postgres holds users, credits, and document chunks.

Service results

A service returns a result object. Callers branch on success instead of catching an exception from the service.

type Result<T> =
  | { success: true; data: T }
  | { success: false; error: AppError; code: string };

On the failure branch, code is the stable name (DATABASE_ERROR, and so on). The error is already logged inside the service.

Credit balance

The balance stays in Postgres. It is not written onto the session token, so a deduction does not require a new login to show up.

On OSS, the chat screen loads /api/user/profile after a reply and dispatches a credits-updated event. On Pro, the dashboard keeps an event stream open at GET /api/dashboard/stream. That stream sends the current balance and tells the client when the workspace list should be refetched.

Where to go next

Configuration is the env file those processes read on startup.