A multi-language blog platform built with Next.js (App Router), featuring markdown-based posts, a liking system, and automated content generation using LLMs based on reddit threads (subreddit).
- Multi-language Blog: Displays a list of blog posts and individual post details, supporting English (en-US) and French (fr-FR).
- Markdown/MDX Content: Blog posts are written and stored in Markdown/MDX format in the
content/posts/directory, organized by language. - Post Liking: Anonymous users can "like" individual blog posts. Like counts are stored in the database.
- Automated Blog Post Generation: Includes a script (
writePostFromReddit.ts) that leverages external data sources (like Reddit) and an LLM (e.g., Mistral). The process involves:- Fetching source data (e.g., from a specified subreddit).
- Structuring prompts for the LLM to generate content based on the fetched data.
- Receiving structured JSON output from the LLM, adhering to the MDAST (Markdown Abstract Syntax Tree) specification. This ensures the content is well-formed and predictable.
- Compiling this MDAST JSON structure into ready-to-write Markdown/MDX files using a compiler like Remark (as implemented in
infrastructure/adapters/RemarkMdastCompiler.ts).
- Framework: Next.js (App Router)
- Language: TypeScript
- Styling: Tailwind CSS, shadcn/ui
- Database: Neon Serverless PostgreSQL
- ORM: Drizzle ORM
- Content: Markdown/MDX
- Markdown Processing: Remark, MDAST (for abstract syntax tree representation and generation)
- AI/LLM: Mistral API (via
infrastructure/adapters/MistralApiMdastFactory.tsfor generating structured MDAST JSON)
- Node.js (v20 or later recommended)
- npm, pnpm, or yarn
-
Clone the repository:
git clone <repository-url> cd micro-blog
-
Install dependencies:
npm install # or # pnpm install # or # yarn install
-
Environment Variables: Create a
.envfile in the root directory by copying the example (if one exists) or creating it from scratch. You will need the following variables:DATABASE_URL: Your Neon Serverless PostgreSQL connection string.MISTRAL_API_KEY: Your API key for the Mistral AI service (required for thereddit-to-postscript).
-
Database Setup: Push the database schema to your Neon database:
npm run db:push
Start the Next.js development server:
npm run devOpen http://localhost:3000 in your browser.
To automatically generate a blog post from a Reddit URL using the LLM past the value of your subreddit in the TARGET_SUBREDDIT variable in the writePostFromReddit.ts and run :
# Ensure your .env file has MISTRAL_API_KEY
npm run reddit-to-post
# Example:
# npm run reddit-to-post(Note: Check writePostFromReddit.ts for the exact arguments required)
content/posts/: Contains the Markdown/MDX blog post files, organized by locale (en-US,fr-FR).core/: Defines the core domain logic, use cases, and ports (interfaces) following Ports & Adapters architecture.domain/: Core entities and business rules.ports/: Interfaces for external dependencies (database, file system, APIs).usecases/: Application-specific logic orchestrating domain objects and ports.
infrastructure/: Implementation details for ports and framework-specific code.adapters/: Concrete implementations of the ports defined incore/ports.persistence/: Database interaction logic (Drizzle schema, repositories).framework/nextjs/: Next.js specific code (actions, server functions, utilities).
src/: Next.js application code.app/: App Router implementation (pages, layouts, components).components/: Shared UI components.lib/: Utility functions, dictionaries for i18n.middleware.ts: Handles internationalization routing.
- Ports & Adapters: The core logic is decoupled from infrastructure concerns using interfaces (ports) and concrete implementations (adapters).
- SOLID Principles: Code aims to follow SOLID principles for maintainability and testability.
- Next.js App Router: Iincluding Server/Client component usage and file structure.
- TypeScript: The entire codebase uses TypeScript for type safety.
- MDAST for Content Generation: Leverages MDAST and structured JSON output from LLMs for reliable, automated Markdown generation, ensuring consistency and predictability.
- Styling: Uses Tailwind CSS utility classes primarily, with
shadcn/uifor pre-built components.
- Parameterize Content Script: Allow passing arguments (e.g., subreddit, output directory, language) to the
writePostFromReddit.tsscript via CLI flags instead of relying on hardcoded values within the script. - User Authentication & Comments: Implement user accounts and a commenting system.
- Admin Panel: Create an interface for managing blog posts, users, and settings.
- Expanded i18n: Add support for more languages and improve translation management.
- Testing: Increase test coverage (unit, integration, end-to-end).
- CI/CD: Set up a continuous integration and deployment pipeline.
- LLM Enhancements: Explore more sophisticated LLM integration (e.g., fine-tuning, different models, improved prompt engineering).
- Content Sources: Integrate additional automated content sources beyond Reddit.
- Schema Validation: Add validation for the LLM's MDAST JSON output to ensure robustness.