mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
refactor: split src into domain / application / infrastructure layers
Replace the history-driven lib/ + utils/ split with DDD layers: - domain/: aggregate, repositories, value objects, pure parsers/format - application/: feed-service, email-processor, feed-fetcher, stats - infrastructure/: logging, auth, KV/R2 adapters, HTTP, framework glue Pure file relocation; imports updated mechanically. Behaviour unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
ProcessEmailInput,
|
||||
RawAttachment,
|
||||
} from "./email-processor";
|
||||
import { getCounters } from "../utils/stats";
|
||||
import { getCounters } from "../application/stats";
|
||||
|
||||
const iconKey = (domain: string) => `icon:${domain}`;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { EmailParser } from "../utils/email-parser";
|
||||
import { EmailParser } from "../domain/email-parser";
|
||||
import { AttachmentData, EmailMetadata, Env } from "../types";
|
||||
import { notifySubscribers } from "../utils/websub";
|
||||
import { bumpCounters } from "../utils/stats";
|
||||
import { notifySubscribers } from "../infrastructure/websub";
|
||||
import { bumpCounters } from "../application/stats";
|
||||
import {
|
||||
cacheFaviconForDomain,
|
||||
extractEmailDomain,
|
||||
} from "../utils/favicon-fetcher";
|
||||
import { parseOneClickUnsubscribe } from "../utils/unsubscribe";
|
||||
import { getAttachmentBucket } from "../utils/attachments";
|
||||
} from "../infrastructure/favicon-fetcher";
|
||||
import { parseOneClickUnsubscribe } from "../infrastructure/unsubscribe";
|
||||
import { getAttachmentBucket } from "../infrastructure/attachments";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { Feed } from "../domain/feed.aggregate";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
import { logger } from "./logger";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
import { FEED_MAX_BYTES } from "../config/constants";
|
||||
|
||||
export interface RawAttachment {
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Context } from "hono";
|
||||
import { Env, FeedConfig } from "../types";
|
||||
import { bumpCounters } from "../utils/stats";
|
||||
import { waitUntilSafe } from "../utils/worker";
|
||||
import { sendUnsubscribes } from "../utils/unsubscribe";
|
||||
import { getAttachmentBucket } from "../utils/attachments";
|
||||
import { bumpCounters } from "../application/stats";
|
||||
import { waitUntilSafe } from "../infrastructure/worker";
|
||||
import { sendUnsubscribes } from "../infrastructure/unsubscribe";
|
||||
import { getAttachmentBucket } from "../infrastructure/attachments";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
import {
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
scanKvUsage,
|
||||
setStorageSnapshot,
|
||||
} from "./stats";
|
||||
import { getAttachmentBucket } from "./attachments";
|
||||
import { getAttachmentBucket } from "../infrastructure/attachments";
|
||||
import { STATS_KEY, FEEDS_LIST_KEY } from "../config/constants";
|
||||
import { Env } from "../types";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Counters, Env, StatsResponse } from "../types";
|
||||
import { logger } from "../lib/logger";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { CountersRepository } from "../domain/counters-repository";
|
||||
import { WebSubSubscriptionRepository } from "../domain/websub-subscription-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
import { getAttachmentBucket } from "./attachments";
|
||||
import { getAttachmentBucket } from "../infrastructure/attachments";
|
||||
|
||||
const EMPTY_COUNTERS: Counters = {
|
||||
feeds_created: 0,
|
||||
@@ -10,7 +10,7 @@ import { FEEDS_LIST_KEY } from "../config/constants";
|
||||
import { feedKeys } from "./feed-keys";
|
||||
import { Feed } from "./feed.aggregate";
|
||||
import { FeedId } from "./value-objects/feed-id";
|
||||
import { logger } from "../lib/logger";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
|
||||
/**
|
||||
* Single source of truth for KV access to the Feed aggregate. The key schema
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Env, WebSubSubscription } from "../types";
|
||||
import { feedKeys } from "./feed-keys";
|
||||
import { logger } from "../lib/logger";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
|
||||
/**
|
||||
* KV access for per-feed WebSub subscriber lists (`websub:subs:<feedId>`).
|
||||
|
||||
+4
-4
@@ -10,9 +10,9 @@ import { handle as handleHome } from "./routes/home";
|
||||
import { handle as handleFavicon, handleFeedFavicon } from "./routes/favicon";
|
||||
import { hubRouter } from "./routes/hub";
|
||||
import { apiApp } from "./routes/api";
|
||||
import { handleCloudflareEmail } from "./lib/cloudflare-email";
|
||||
import { handleCloudflareEmail } from "./infrastructure/cloudflare-email";
|
||||
import { Env } from "./types";
|
||||
import { logger } from "./lib/logger";
|
||||
import { logger } from "./infrastructure/logger";
|
||||
import { FeedRepository } from "./domain/feed-repository";
|
||||
import { purgeExpiredFeeds } from "./routes/admin/helpers";
|
||||
import {
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
scanR2Usage,
|
||||
scanKvUsage,
|
||||
setStorageSnapshot,
|
||||
} from "./utils/stats";
|
||||
import { getAttachmentBucket } from "./utils/attachments";
|
||||
} from "./application/stats";
|
||||
import { getAttachmentBucket } from "./infrastructure/attachments";
|
||||
import { FORWARD_EMAIL_IPS_CACHE_TTL_MS } from "./config/constants";
|
||||
|
||||
type AppEnv = { Bindings: Env };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import PostalMime from "postal-mime";
|
||||
import { Env } from "../types";
|
||||
import { processEmail, RawAttachment } from "./email-processor";
|
||||
import { normalizeCid } from "../utils/html-processor";
|
||||
import { processEmail, RawAttachment } from "../application/email-processor";
|
||||
import { normalizeCid } from "../infrastructure/html-processor";
|
||||
import { logger } from "./logger";
|
||||
|
||||
export async function handleCloudflareEmail(
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "../config/constants";
|
||||
import { IconRepository } from "../domain/icon-repository";
|
||||
import { EmailAddress } from "../domain/value-objects/email-address";
|
||||
import { logger } from "../lib/logger";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
|
||||
interface IconRecord {
|
||||
data: string | null; // base64 icon bytes, or null for a negative cache entry
|
||||
@@ -1,7 +1,11 @@
|
||||
import { EmailParser } from "../utils/email-parser";
|
||||
import { EmailParser } from "../domain/email-parser";
|
||||
import { Env } from "../types";
|
||||
import { processEmail, IngestResult, RawAttachment } from "./email-processor";
|
||||
import { normalizeCid } from "../utils/html-processor";
|
||||
import {
|
||||
processEmail,
|
||||
IngestResult,
|
||||
RawAttachment,
|
||||
} from "../application/email-processor";
|
||||
import { normalizeCid } from "../infrastructure/html-processor";
|
||||
|
||||
/** Map an ingestion result to the HTTP response ForwardEmail expects. */
|
||||
export function ingestResultToResponse(result: IngestResult): Response {
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
sendOneClickUnsubscribe,
|
||||
sendUnsubscribes,
|
||||
} from "./unsubscribe";
|
||||
import { getCounters } from "./stats";
|
||||
import { getCounters } from "../application/stats";
|
||||
import type { Env } from "../types";
|
||||
|
||||
const POST_HEADER = "List-Unsubscribe=One-Click";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Env } from "../types";
|
||||
import { UNSUBSCRIBE_TIMEOUT_MS } from "../config/constants";
|
||||
import { bumpCounters } from "./stats";
|
||||
import { logger } from "../lib/logger";
|
||||
import { bumpCounters } from "../application/stats";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
|
||||
/**
|
||||
* Extract a one-click unsubscribe URL from a stored email's headers per
|
||||
@@ -3,7 +3,7 @@ import { http, HttpResponse } from "msw";
|
||||
import { Hono } from "hono";
|
||||
import app from "./admin";
|
||||
import { createMockEnv, server } from "../test/setup";
|
||||
import { getCounters } from "../utils/stats";
|
||||
import { getCounters } from "../application/stats";
|
||||
import { Env } from "../types";
|
||||
|
||||
describe("Admin Routes", () => {
|
||||
|
||||
@@ -5,12 +5,16 @@ import { z } from "zod";
|
||||
import { Env } from "../types";
|
||||
import { csrf } from "hono/csrf";
|
||||
import { ADMIN_COOKIE_MAX_AGE } from "../config/constants";
|
||||
import { logger } from "../lib/logger";
|
||||
import { timingSafeEqual, checkProxyAuth } from "../lib/auth";
|
||||
import { logger } from "../infrastructure/logger";
|
||||
import { timingSafeEqual, checkProxyAuth } from "../infrastructure/auth";
|
||||
import { Layout, clampText } from "./admin/ui";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { renameFeed } from "../lib/feed-service";
|
||||
import { feedRssUrl, feedAtomUrl, feedEmailAddress } from "../utils/urls";
|
||||
import { renameFeed } from "../application/feed-service";
|
||||
import {
|
||||
feedRssUrl,
|
||||
feedAtomUrl,
|
||||
feedEmailAddress,
|
||||
} from "../infrastructure/urls";
|
||||
import { feedsRouter } from "./admin/feeds";
|
||||
import { emailsRouter } from "./admin/emails";
|
||||
import { dashboardScript } from "../scripts/generated/dashboard";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Hono } from "hono";
|
||||
import { Env, EmailMetadata } from "../../types";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { logger } from "../../infrastructure/logger";
|
||||
import { Layout, clampText } from "./ui";
|
||||
import {
|
||||
deleteAttachmentsForEmails,
|
||||
@@ -8,8 +8,12 @@ import {
|
||||
} from "./helpers";
|
||||
import { FeedRepository } from "../../domain/feed-repository";
|
||||
import { FeedId } from "../../domain/value-objects/feed-id";
|
||||
import { feedRssUrl, feedAtomUrl, feedEmailAddress } from "../../utils/urls";
|
||||
import { formatBytes } from "../../utils/format";
|
||||
import {
|
||||
feedRssUrl,
|
||||
feedAtomUrl,
|
||||
feedEmailAddress,
|
||||
} from "../../infrastructure/urls";
|
||||
import { formatBytes } from "../../domain/format";
|
||||
import { EmailAddress } from "../../domain/value-objects/email-address";
|
||||
import { emailsPageScript } from "../../scripts/generated/emails-page";
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Hono } from "hono";
|
||||
import { z } from "zod";
|
||||
import { Env } from "../../types";
|
||||
import { bumpCounters } from "../../utils/stats";
|
||||
import { waitUntilSafe } from "../../utils/worker";
|
||||
import { feedRssUrl, feedEmailAddress } from "../../utils/urls";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { sendUnsubscribes } from "../../utils/unsubscribe";
|
||||
import { getAttachmentBucket } from "../../utils/attachments";
|
||||
import { bumpCounters } from "../../application/stats";
|
||||
import { waitUntilSafe } from "../../infrastructure/worker";
|
||||
import { feedRssUrl, feedEmailAddress } from "../../infrastructure/urls";
|
||||
import { logger } from "../../infrastructure/logger";
|
||||
import { sendUnsubscribes } from "../../infrastructure/unsubscribe";
|
||||
import { getAttachmentBucket } from "../../infrastructure/attachments";
|
||||
import { Layout } from "./ui";
|
||||
import { purgeFeedKeysStep, collectUnsubscribeUrls } from "./helpers";
|
||||
import { FeedRepository } from "../../domain/feed-repository";
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
editFeed,
|
||||
deleteFeedRecord,
|
||||
deleteFeedFastDetailed,
|
||||
} from "../../lib/feed-service";
|
||||
} from "../../application/feed-service";
|
||||
|
||||
type AppEnv = { Bindings: Env };
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EmailData, EmailMetadata, Env } from "../../types";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { getAttachmentBucket } from "../../utils/attachments";
|
||||
import { logger } from "../../infrastructure/logger";
|
||||
import { getAttachmentBucket } from "../../infrastructure/attachments";
|
||||
import { FeedRepository } from "../../domain/feed-repository";
|
||||
import { FeedId } from "../../domain/value-objects/feed-id";
|
||||
|
||||
|
||||
@@ -2,17 +2,21 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import { cors } from "hono/cors";
|
||||
import { Scalar } from "@scalar/hono-api-reference";
|
||||
import { Env, FeedConfig } from "../../types";
|
||||
import { apiAuthMiddleware } from "../../lib/auth";
|
||||
import { apiAuthMiddleware } from "../../infrastructure/auth";
|
||||
import {
|
||||
createFeedRecord,
|
||||
editFeed,
|
||||
deleteFeedRecord,
|
||||
} from "../../lib/feed-service";
|
||||
} from "../../application/feed-service";
|
||||
import { deleteAttachmentsForEmails } from "../admin/helpers";
|
||||
import { FeedRepository } from "../../domain/feed-repository";
|
||||
import { FeedId } from "../../domain/value-objects/feed-id";
|
||||
import { getStats } from "../../utils/stats";
|
||||
import { feedEmailAddress, feedRssUrl, feedAtomUrl } from "../../utils/urls";
|
||||
import { getStats } from "../../application/stats";
|
||||
import {
|
||||
feedEmailAddress,
|
||||
feedRssUrl,
|
||||
feedAtomUrl,
|
||||
} from "../../infrastructure/urls";
|
||||
import {
|
||||
ErrorSchema,
|
||||
FeedIdParam,
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { generateAtomFeed } from "../utils/feed-generator";
|
||||
import { fetchFeedData } from "../utils/feed-fetcher";
|
||||
import { baseUrl, feedAtomUrl } from "../utils/urls";
|
||||
import { generateAtomFeed } from "../infrastructure/feed-generator";
|
||||
import { fetchFeedData } from "../application/feed-fetcher";
|
||||
import { baseUrl, feedAtomUrl } from "../infrastructure/urls";
|
||||
import { isExpired } from "../domain/feed";
|
||||
|
||||
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Context } from "hono";
|
||||
import { html, raw } from "hono/html";
|
||||
import { Env } from "../types";
|
||||
import { processEmailContent } from "../utils/html-processor";
|
||||
import { formatBytes } from "../utils/format";
|
||||
import { processEmailContent } from "../infrastructure/html-processor";
|
||||
import { formatBytes } from "../domain/format";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
import { isExpired } from "../domain/feed";
|
||||
|
||||
@@ -2,7 +2,10 @@ import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
import { cacheFaviconForDomain, getCachedIcon } from "../utils/favicon-fetcher";
|
||||
import {
|
||||
cacheFaviconForDomain,
|
||||
getCachedIcon,
|
||||
} from "../infrastructure/favicon-fetcher";
|
||||
|
||||
export const FAVICON_PATH = "/favicon.svg";
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { getAttachmentBucket } from "../utils/attachments";
|
||||
import { getAttachmentBucket } from "../infrastructure/attachments";
|
||||
|
||||
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
const bucket = getAttachmentBucket(c.env);
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { getStats } from "../utils/stats";
|
||||
import { formatBytes } from "../utils/format";
|
||||
import { getStats } from "../application/stats";
|
||||
import { formatBytes } from "../domain/format";
|
||||
import { R2_FREE_TIER_BYTES, KV_FREE_TIER_BYTES } from "../config/constants";
|
||||
import { Layout } from "./admin/ui";
|
||||
|
||||
|
||||
+3
-3
@@ -3,10 +3,10 @@ import { Env } from "../types";
|
||||
import {
|
||||
verifyAndStoreSubscription,
|
||||
verifyAndDeleteSubscription,
|
||||
} from "../utils/websub";
|
||||
import { waitUntilSafe } from "../utils/worker";
|
||||
} from "../infrastructure/websub";
|
||||
import { waitUntilSafe } from "../infrastructure/worker";
|
||||
import { DEFAULT_LEASE_SECONDS, MAX_LEASE_SECONDS } from "../config/constants";
|
||||
import { feedTopicPattern } from "../utils/urls";
|
||||
import { feedTopicPattern } from "../infrastructure/urls";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
import { FeedId } from "../domain/value-objects/feed-id";
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { http, HttpResponse } from "msw";
|
||||
import worker from "../index";
|
||||
import { server, createMockEnv, MockR2 } from "../test/setup";
|
||||
import type { Env } from "../types";
|
||||
import type { ForwardEmailPayload } from "../lib/forwardemail";
|
||||
import type { ForwardEmailPayload } from "../infrastructure/forwardemail";
|
||||
|
||||
const AUTHORIZED_IP = "138.197.213.185"; // first fallback IP
|
||||
const DOMAIN = "test.getmynews.app";
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { ForwardEmailPayload, handleForwardEmail } from "../lib/forwardemail";
|
||||
import {
|
||||
ForwardEmailPayload,
|
||||
handleForwardEmail,
|
||||
} from "../infrastructure/forwardemail";
|
||||
|
||||
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
try {
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
import { Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import { generateRssFeed } from "../utils/feed-generator";
|
||||
import { fetchFeedData } from "../utils/feed-fetcher";
|
||||
import { baseUrl, feedRssUrl } from "../utils/urls";
|
||||
import { generateRssFeed } from "../infrastructure/feed-generator";
|
||||
import { fetchFeedData } from "../application/feed-fetcher";
|
||||
import { baseUrl, feedRssUrl } from "../infrastructure/urls";
|
||||
import { isExpired } from "../domain/feed";
|
||||
|
||||
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
|
||||
Reference in New Issue
Block a user