How sukhrajdev/apixy works
Purpose and Entry Points
Apixy is a Node.js/Express REST backend that manages accounts and user-owned LLM provider keys, then proxies Google Gemini requests using those stored credentials. The HTTP process starts in backend/src/server.ts; route modules split the public API into auth, token refresh, user, and provider-key/LLM surfaces: backend/src/routes/auth.route.ts, backend/src/routes/api.route.ts, and backend/src/routes/user.route.ts.
HTTP Layer and Request Dispatch
Controllers translate HTTP requests into service calls and response envelopes. Auth, user lifecycle, and API-key/LLM operations are separated in backend/src/controllers/auth.controller.ts, backend/src/controllers/user.controller.ts, and backend/src/controllers/api.controller.ts. Routes are the primary boundary between untrusted request data and application logic; user input validation is represented by Zod schema code in backend/src/utils/zod/schema/user.schema.ts.
Authentication and Token Lifecycle
Authentication supports registration, login/logout, email verification, password change, and access-token refresh. JWT issuance/verification is centralized in backend/src/providers/token/token.provider.ts; auth orchestration is in backend/src/services/auth.service.ts. Protected routes use bearer-token middleware in backend/src/middlewares/auth.middleware.ts, while refresh tokens are supplied through login-set HTTP-only cookies and the token route at backend/src/routes/token.route.ts.
User and Credential Domain
Prisma persists user records, including account credentials and token-related state, and api records owned by users for provider metadata, encrypted/stored key material, and generated API tokens. The authoritative relational model and PostgreSQL mappings are backend/prisma/schema.prisma, with database evolution under backend/prisma/migrations/. User read/update/delete behavior belongs to backend/src/services/user.service.ts; provider-key CRUD and LLM invocation orchestration belong to backend/src/services/api.service.ts.
Provider-Key Protection and LLM Invocation
A user first creates a Google provider-key record through authenticated API routes. Later, an LLM request identifies a provider/model and includes the stored API token (skKey); API-token middleware/service logic resolves and authorizes the saved credential before use. This boundary is implemented across backend/src/middlewares/Apitoken.middleware.ts, backend/src/services/api.service.ts, and backend/src/providers/llm/google/google.llm.ts. Only Google Gemini is materially implemented, via the Google GenAI SDK; schema enum support for other providers does not imply runtime integration.
External Services and Infrastructure
PostgreSQL is accessed via Prisma configuration/client setup in backend/src/configs/prisma.config.ts and backend/prisma.config.ts. Gmail SMTP/Nodemailer sends verification messages through backend/src/providers/email/email.provider.ts and backend/src/providers/email/templates/verification.template.ts. Environment variables provide database connectivity, JWT secrets/expirations, and SMTP credentials. A Redis configuration exists at backend/src/configs/redis.config.ts, but the supplied structure does not establish it as a required active request-path dependency.
SDK Consumer Layer
A separate TypeScript SDK packages client-facing request and chat abstractions for calling this backend rather than hosting another service. Its public export is sdk/src/index.ts; transport and chat flows are centered in sdk/src/core/request.core.ts and sdk/src/core/chat.core.ts. This creates a clean consumer boundary: SDK callers supply API base/client data, while the backend remains responsible for identity, stored provider credentials, authorization, and Gemini execution.
Main entry points: api.route.ts Public routes · prisma.config.ts Prisma client · auth.service.ts Auth service · api.service.ts Provider-key & LLM service
Components 21
Backend API
Express service that owns identity, credentials, and LLM proxying.
- Express server
backend/src/server.ts - Public routes · Auth, refresh, user, and provider-key/LLM endpoints.
backend/src/routes/api.route.ts - Auth controller
backend/src/controllers/auth.controller.ts - User controller
backend/src/controllers/user.controller.ts - API & LLM controller
backend/src/controllers/api.controller.ts - User schemas · Validates untrusted user input at the HTTP boundary.
backend/src/utils/zod/schema/user.schema.ts - Bearer auth
backend/src/middlewares/auth.middleware.ts - Stored API-token auth · Resolves and authorizes a saved provider credential token.
backend/src/middlewares/Apitoken.middleware.ts - Auth service
backend/src/services/auth.service.ts - JWT provider · Issues and verifies access and refresh tokens.
backend/src/providers/token/token.provider.ts - User service
backend/src/services/user.service.ts - Provider-key & LLM service · Manages user-owned provider keys and orchestrates LLM calls.
backend/src/services/api.service.ts - Google Gemini adapter · Only materially implemented runtime LLM provider.
backend/src/providers/llm/google/google.llm.ts - Verification email
backend/src/providers/email/email.provider.ts
Data & external services
- Prisma client
backend/src/configs/prisma.config.ts - Relational schema · Defines user and user-owned API credential records.
backend/prisma/schema.prisma - PostgreSQL
- Gmail SMTP
TypeScript SDK
Client package for consuming the backend API.
- SDK public API
sdk/src/index.ts - SDK request transport
sdk/src/core/request.core.ts - SDK chat API
sdk/src/core/chat.core.ts
Connections 25
- SDK public API → SDK request transport: exports
- SDK public API → SDK chat API: exports
- SDK chat API → SDK request transport: uses transport
- SDK request transport → Express server: HTTP requests
- Express server → Public routes: mounts
- Public routes → User schemas: validates input
- Public routes → Bearer auth: protects user routes
- Public routes → Stored API-token auth: guards LLM calls
- Public routes → Auth controller: auth endpoints
- Public routes → User controller: user endpoints
- Public routes → API & LLM controller: key and LLM endpoints
- Auth controller → Auth service: auth operations
- Auth service → JWT provider: issues tokens
- Bearer auth → JWT provider: verifies bearer JWT
- Auth service → Verification email: sends verification
- Verification email → Gmail SMTP: SMTP
- User controller → User service: user lifecycle
- API & LLM controller → Provider-key & LLM service: credential and invocation
- Stored API-token auth → Provider-key & LLM service: authorizes skKey
- Provider-key & LLM service → Google Gemini adapter: Gemini request
- Auth service → Prisma client: account state
- User service → Prisma client: user records
- Provider-key & LLM service → Prisma client: provider credentials
- Prisma client → Relational schema: maps model
- Prisma client → PostgreSQL: queries