mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-21 06:13: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:
@@ -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