This monorepo project aims to generate personalized newsletters through AI algorithms. It consists of frontend and backend subsystems. The backend is built in a Node.js environment and utilizes Prisma for Object-Relational Mapping (ORM). The frontend is developed using React and incorporates Auth0 for secure authentication.
This section details the relationships and constraints among the database models—Admin, Newsletter, UsedArticle, and ContentHistory.
-
Admin
id
: UUID-based unique identifier.email
: Unique email.name
: Optional name.newsletters
: Array of authored newsletters.mailingList
: Array of strings (email addresses) to send newsletters.
-
Newsletter
id
: Auto-incremented unique identifier.regenerateCount
: Regeneration attempts counter.title
,content
,sentDate
,adminID
,topic
,reason
,searchQuery
: Various attributes.contentHistory
: Array of historical contents.usedArticles
: Array of used articles.admin
: Foreign key toAdmin
.
-
UsedArticle
id
: Auto-incremented unique identifier.url
,newsletterId
,createdAt
,adminID
,topic
,reason
: Various attributes.summary
: Relation toArticleSummary
.summaryID
: Foreign key toArticleSummary
.newsletter
: Foreign key toNewsletter
.
-
ContentHistory
id
: Auto-incremented unique identifier.newsletterId
,content
,createdAt
: Various attributes.newsletter
: Foreign key toNewsletter
.
-
ArticleSummary
id
: UUID-based unique identifier.- `url: Unique URL.
summary
: Summary text.usedBy
: Array ofUsedArticle
that used this summary.
- Admin -> Newsletter: One-to-Many
- Newsletter -> ContentHistory: One-to-Many
- Newsletter -> UsedArticle: One-to-Many
- UsedArticle -> ArticleSummary: One-to-One
- ArticleSummary -> UsedArticle: One-to-Many
- Cascade Delete: Enabled with
onDelete: Cascade
. - Field Defaults: Specified using Prisma directives.
- Uniqueness and IDs: Ensured through unique fields.
For further reading, consider Prisma's Relations and PostgreSQL's Referential Integrity.
importEmailList
: Bulk email import.addSingleEmail
: Singular email addition.
processArticles
: Article filtering.sortArticles
: Article ranking.
The server-side logic is modularized into an MVC-like architecture comprising routes, controllers, and utility functions. The entry point of the backend is index.ts
.
Acts as the backend entry point, orchestrating the routes, controllers, and middleware configurations. Initializes the Express.js server, and sets it to listen on a specified port or default to 3001.
Located in the src/controllers
directory. Responsible for handling business logic, they interact with the database and return responses.
adminController.ts
: Handles admin-related functionalities.newsletterController.ts
: Manages newsletter generation and sending.
Located in the src/routes
directory. Define the API endpoints and associate them with their corresponding controllers.
adminRoutes.ts
: Routes related to admin functionalities.newsletterRoutes.ts
: Routes for newsletter operations.
Middleware configurations are located in the server/config/middleware.ts
file.
express.json()
: For JSON parsing.cors
: For CORS handling.
Middleware is initialized and configured in the index.ts
entry point.
GET /unsubscribe
POST /api/update-admin
POST /api/create-newsletter
GET /api/get-newsletters
GET /api/get-emails
POST /api/delete-selected-emails
DELETE /api/delete-newsletter/:id
POST /api/add-emails
POST /api/send-newsletter
POST /api/regenerate-newsletter
generateOptimalBingSearchQuery
generateSummaryWithGPT
generateNewsletterWithGPT
- React, Auth0, Emotion, Material-UI
- Authentication and routing.
- Backend API utilities.
- Authenticated segment management.
ConfirmDeleteDialog
ConfirmSendDialog
EmailList
LoginButton
LogoutButton
NewsletterDetailDialog
NewsletterForm
NewsletterList
- Auth0 authentication configurations.
- Bing Search API
- AWS SES
DATABASE_URL
AWS_REGION
,AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
BING_API_KEY
GPT_API_KEY