diff --git a/apps/server/src/app.ts b/apps/server/src/app.ts index 2bddd424e..c5b650722 100644 --- a/apps/server/src/app.ts +++ b/apps/server/src/app.ts @@ -2,8 +2,8 @@ import type Redis from 'ioredis' import type { Env } from './libs/env' import type { OtelInstance } from './libs/otel' -import type { BillingMqService } from './services/billing-mq' -import type { BillingService } from './services/billing-service' +import type { BillingMqService } from './services/billing/billing-mq' +import type { BillingService } from './services/billing/billing-service' import type { CharacterService } from './services/characters' import type { ChatService } from './services/chats' import type { ConfigKVService } from './services/config-kv' @@ -40,8 +40,8 @@ import { createFluxRoutes } from './routes/flux' import { createProviderRoutes } from './routes/providers' import { createStripeRoutes } from './routes/stripe' import { createV1CompletionsRoutes } from './routes/v1completions' -import { createBillingMqService } from './services/billing-mq' -import { createBillingService } from './services/billing-service' +import { createBillingMqService } from './services/billing/billing-mq' +import { createBillingService } from './services/billing/billing-service' import { createCharacterService } from './services/characters' import { createChatService } from './services/chats' import { createConfigKVService } from './services/config-kv' diff --git a/apps/server/src/bin/__test__/run.test.ts b/apps/server/src/bin/__test__/run.test.ts deleted file mode 100644 index a62461ad6..000000000 --- a/apps/server/src/bin/__test__/run.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { describe, expect, it } from 'vitest' - -import { createServerCli, parseServerRole } from '../run' - -describe('server cli', () => { - it('parses supported roles', () => { - expect(parseServerRole(['api'])).toBe('api') - expect(parseServerRole(['billing-consumer'])).toBe('billing-consumer') - }) - - it('returns null for unsupported or missing roles', () => { - expect(parseServerRole([])).toBeNull() - expect(parseServerRole(['unknown'])).toBeNull() - }) - - it('registers all supported roles with cac', () => { - const cli = createServerCli() - - expect(cli.commands.map(command => command.name)).toEqual(expect.arrayContaining([ - 'api', - 'billing-consumer', - ])) - }) -}) diff --git a/apps/server/src/bin/run-billing-consumer.ts b/apps/server/src/bin/run-billing-consumer.ts index 7dd4d8fd5..c5c4d3804 100644 --- a/apps/server/src/bin/run-billing-consumer.ts +++ b/apps/server/src/bin/run-billing-consumer.ts @@ -6,9 +6,9 @@ import { createDrizzle, migrateDatabase } from '../libs/db' import { parseEnv } from '../libs/env' import { initializeExternalDependency } from '../libs/external-dependency' import { createRedis } from '../libs/redis' -import { createBillingConsumerHandler } from '../services/billing-consumer-handler' -import { createBillingMqService } from '../services/billing-mq' -import { createBillingMqWorker } from '../services/billing-mq-worker' +import { createBillingConsumerHandler } from '../services/billing/billing-consumer-handler' +import { createBillingMqService } from '../services/billing/billing-mq' +import { createBillingMqWorker } from '../services/billing/billing-mq-worker' function parsePositiveInteger(rawValue: string, envKey: string): number { const parsed = Number(rawValue) diff --git a/apps/server/src/libs/__test__/eventa-hono-adapter.test.ts b/apps/server/src/libs/tests/eventa-hono-adapter.test.ts similarity index 100% rename from apps/server/src/libs/__test__/eventa-hono-adapter.test.ts rename to apps/server/src/libs/tests/eventa-hono-adapter.test.ts diff --git a/apps/server/src/routes/stripe.ts b/apps/server/src/routes/stripe.ts index f941d2bd0..031a7ab17 100644 --- a/apps/server/src/routes/stripe.ts +++ b/apps/server/src/routes/stripe.ts @@ -1,6 +1,6 @@ import type { Env } from '../libs/env' import type { RevenueMetrics } from '../libs/otel' -import type { BillingService } from '../services/billing-service' +import type { BillingService } from '../services/billing/billing-service' import type { ConfigKVService } from '../services/config-kv' import type { FluxService } from '../services/flux' import type { StripeService } from '../services/stripe' diff --git a/apps/server/src/routes/__test__/characters.test.ts b/apps/server/src/routes/tests/characters.test.ts similarity index 100% rename from apps/server/src/routes/__test__/characters.test.ts rename to apps/server/src/routes/tests/characters.test.ts diff --git a/apps/server/src/routes/__test__/providers.test.ts b/apps/server/src/routes/tests/providers.test.ts similarity index 100% rename from apps/server/src/routes/__test__/providers.test.ts rename to apps/server/src/routes/tests/providers.test.ts diff --git a/apps/server/src/routes/__test__/stripe.test.ts b/apps/server/src/routes/tests/stripe.test.ts similarity index 99% rename from apps/server/src/routes/__test__/stripe.test.ts rename to apps/server/src/routes/tests/stripe.test.ts index 32ee0585e..427acf4ef 100644 --- a/apps/server/src/routes/__test__/stripe.test.ts +++ b/apps/server/src/routes/tests/stripe.test.ts @@ -1,5 +1,5 @@ import type { StripeCheckoutSession, StripeInvoice } from '../../schemas/stripe' -import type { BillingService } from '../../services/billing-service' +import type { BillingService } from '../../services/billing/billing-service' import type { ConfigKVService } from '../../services/config-kv' import type { FluxService } from '../../services/flux' import type { StripeService } from '../../services/stripe' diff --git a/apps/server/src/routes/__test__/v1completions.test.ts b/apps/server/src/routes/tests/v1completions.test.ts similarity index 98% rename from apps/server/src/routes/__test__/v1completions.test.ts rename to apps/server/src/routes/tests/v1completions.test.ts index 9fbc6bfe5..5a9ed7b2f 100644 --- a/apps/server/src/routes/__test__/v1completions.test.ts +++ b/apps/server/src/routes/tests/v1completions.test.ts @@ -1,5 +1,5 @@ -import type { BillingMqService } from '../../services/billing-mq' -import type { BillingService } from '../../services/billing-service' +import type { BillingMqService } from '../../services/billing/billing-mq' +import type { BillingService } from '../../services/billing/billing-service' import type { ConfigKVService } from '../../services/config-kv' import type { FluxService } from '../../services/flux' import type { HonoEnv } from '../../types/hono' diff --git a/apps/server/src/routes/v1completions.ts b/apps/server/src/routes/v1completions.ts index f29d4a229..b978061fa 100644 --- a/apps/server/src/routes/v1completions.ts +++ b/apps/server/src/routes/v1completions.ts @@ -1,9 +1,9 @@ import type { Context } from 'hono' import type { LlmMetrics } from '../libs/otel' -import type { UsageInfo } from '../services/billing' -import type { BillingMqService } from '../services/billing-mq' -import type { BillingService } from '../services/billing-service' +import type { UsageInfo } from '../services/billing/billing' +import type { BillingMqService } from '../services/billing/billing-mq' +import type { BillingService } from '../services/billing/billing-service' import type { ConfigKVService } from '../services/config-kv' import type { FluxService } from '../services/flux' import type { HonoEnv } from '../types/hono' @@ -16,7 +16,7 @@ import { bodyLimit } from 'hono/body-limit' import { authGuard } from '../middlewares/auth' import { configGuard } from '../middlewares/config-guard' import { rateLimiter } from '../middlewares/rate-limit' -import { calculateFluxFromUsage, extractUsageFromBody } from '../services/billing' +import { calculateFluxFromUsage, extractUsageFromBody } from '../services/billing/billing' import { createPaymentRequiredError } from '../utils/error' import { nanoid } from '../utils/id' diff --git a/apps/server/src/services/billing-consumer-handler.ts b/apps/server/src/services/billing/billing-consumer-handler.ts similarity index 91% rename from apps/server/src/services/billing-consumer-handler.ts rename to apps/server/src/services/billing/billing-consumer-handler.ts index 9a5a5169f..45a073732 100644 --- a/apps/server/src/services/billing-consumer-handler.ts +++ b/apps/server/src/services/billing/billing-consumer-handler.ts @@ -1,11 +1,11 @@ -import type { Database } from '../libs/db' +import type { Database } from '../../libs/db' import type { BillingStreamMessage } from './billing-mq' import { useLogger } from '@guiiai/logg' -import * as fluxAuditSchema from '../schemas/flux-audit-log' -import * as fluxLedgerSchema from '../schemas/flux-ledger' -import * as llmRequestLogSchema from '../schemas/llm-request-log' +import * as fluxAuditSchema from '../../schemas/flux-audit-log' +import * as fluxLedgerSchema from '../../schemas/flux-ledger' +import * as llmRequestLogSchema from '../../schemas/llm-request-log' const logger = useLogger('billing-consumer-handler').useGlobalConfig() diff --git a/apps/server/src/services/billing-events.ts b/apps/server/src/services/billing/billing-events.ts similarity index 100% rename from apps/server/src/services/billing-events.ts rename to apps/server/src/services/billing/billing-events.ts diff --git a/apps/server/src/services/billing-mq-worker.ts b/apps/server/src/services/billing/billing-mq-worker.ts similarity index 100% rename from apps/server/src/services/billing-mq-worker.ts rename to apps/server/src/services/billing/billing-mq-worker.ts diff --git a/apps/server/src/services/billing-mq.ts b/apps/server/src/services/billing/billing-mq.ts similarity index 100% rename from apps/server/src/services/billing-mq.ts rename to apps/server/src/services/billing/billing-mq.ts diff --git a/apps/server/src/services/billing-service.ts b/apps/server/src/services/billing/billing-service.ts similarity index 96% rename from apps/server/src/services/billing-service.ts rename to apps/server/src/services/billing/billing-service.ts index 59db8f930..23c44cab8 100644 --- a/apps/server/src/services/billing-service.ts +++ b/apps/server/src/services/billing/billing-service.ts @@ -1,22 +1,22 @@ import type Redis from 'ioredis' -import type { Database } from '../libs/db' -import type { RevenueMetrics } from '../libs/otel' +import type { Database } from '../../libs/db' +import type { RevenueMetrics } from '../../libs/otel' +import type { ConfigKVService } from '../config-kv' import type { BillingEvent } from './billing-events' import type { BillingMqService } from './billing-mq' -import type { ConfigKVService } from './config-kv' import { useLogger } from '@guiiai/logg' import { eq } from 'drizzle-orm' -import { createPaymentRequiredError } from '../utils/error' -import { nanoid } from '../utils/id' -import { fluxRedisKey } from './flux' +import { createPaymentRequiredError } from '../../utils/error' +import { nanoid } from '../../utils/id' +import { fluxRedisKey } from '../flux' -import * as fluxSchema from '../schemas/flux' -import * as fluxAuditSchema from '../schemas/flux-audit-log' -import * as fluxLedgerSchema from '../schemas/flux-ledger' -import * as stripeSchema from '../schemas/stripe' +import * as fluxSchema from '../../schemas/flux' +import * as fluxAuditSchema from '../../schemas/flux-audit-log' +import * as fluxLedgerSchema from '../../schemas/flux-ledger' +import * as stripeSchema from '../../schemas/stripe' const logger = useLogger('billing-service') diff --git a/apps/server/src/services/billing.ts b/apps/server/src/services/billing/billing.ts similarity index 100% rename from apps/server/src/services/billing.ts rename to apps/server/src/services/billing/billing.ts diff --git a/apps/server/src/services/__test__/billing-events.test.ts b/apps/server/src/services/billing/tests/billing-events.test.ts similarity index 100% rename from apps/server/src/services/__test__/billing-events.test.ts rename to apps/server/src/services/billing/tests/billing-events.test.ts diff --git a/apps/server/src/services/__test__/billing-mq-worker.test.ts b/apps/server/src/services/billing/tests/billing-mq-worker.test.ts similarity index 100% rename from apps/server/src/services/__test__/billing-mq-worker.test.ts rename to apps/server/src/services/billing/tests/billing-mq-worker.test.ts diff --git a/apps/server/src/services/__test__/billing-mq.test.ts b/apps/server/src/services/billing/tests/billing-mq.test.ts similarity index 100% rename from apps/server/src/services/__test__/billing-mq.test.ts rename to apps/server/src/services/billing/tests/billing-mq.test.ts diff --git a/apps/server/src/services/__test__/billing-service.test.ts b/apps/server/src/services/billing/tests/billing-service.test.ts similarity index 97% rename from apps/server/src/services/__test__/billing-service.test.ts rename to apps/server/src/services/billing/tests/billing-service.test.ts index 163b39715..6177a70fe 100644 --- a/apps/server/src/services/__test__/billing-service.test.ts +++ b/apps/server/src/services/billing/tests/billing-service.test.ts @@ -1,16 +1,16 @@ import type Redis from 'ioredis' -import type { Database } from '../../libs/db' +import type { Database } from '../../../libs/db' +import type { createConfigKVService } from '../../config-kv' import type { BillingMqService } from '../billing-mq' -import type { createConfigKVService } from '../config-kv' import { eq } from 'drizzle-orm' import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' -import { mockDB } from '../../libs/mock-db' +import { mockDB } from '../../../libs/mock-db' import { createBillingService } from '../billing-service' -import * as schema from '../../schemas' +import * as schema from '../../../schemas' function createMockConfigKV(overrides: Record = {}): ReturnType { const defaults: Record = { INITIAL_USER_FLUX: 100, FLUX_PER_CENT: 1, FLUX_PER_REQUEST: 1, ...overrides } diff --git a/apps/server/src/services/__test__/billing.test.ts b/apps/server/src/services/billing/tests/billing.test.ts similarity index 100% rename from apps/server/src/services/__test__/billing.test.ts rename to apps/server/src/services/billing/tests/billing.test.ts diff --git a/apps/server/src/services/__test__/characters.test.ts b/apps/server/src/services/tests/characters.test.ts similarity index 100% rename from apps/server/src/services/__test__/characters.test.ts rename to apps/server/src/services/tests/characters.test.ts diff --git a/apps/server/src/services/__test__/chats.test.ts b/apps/server/src/services/tests/chats.test.ts similarity index 100% rename from apps/server/src/services/__test__/chats.test.ts rename to apps/server/src/services/tests/chats.test.ts diff --git a/apps/server/src/services/__test__/config-kv.test.ts b/apps/server/src/services/tests/config-kv.test.ts similarity index 100% rename from apps/server/src/services/__test__/config-kv.test.ts rename to apps/server/src/services/tests/config-kv.test.ts diff --git a/apps/server/src/services/__test__/flux-audit.test.ts b/apps/server/src/services/tests/flux-audit.test.ts similarity index 100% rename from apps/server/src/services/__test__/flux-audit.test.ts rename to apps/server/src/services/tests/flux-audit.test.ts diff --git a/apps/server/src/services/__test__/flux.test.ts b/apps/server/src/services/tests/flux.test.ts similarity index 100% rename from apps/server/src/services/__test__/flux.test.ts rename to apps/server/src/services/tests/flux.test.ts diff --git a/apps/server/src/services/__test__/providers.test.ts b/apps/server/src/services/tests/providers.test.ts similarity index 100% rename from apps/server/src/services/__test__/providers.test.ts rename to apps/server/src/services/tests/providers.test.ts diff --git a/apps/server/src/services/__test__/stripe.test.ts b/apps/server/src/services/tests/stripe.test.ts similarity index 100% rename from apps/server/src/services/__test__/stripe.test.ts rename to apps/server/src/services/tests/stripe.test.ts