A Next.js-based article experiment project focused on testing and implementing various article-related features, including author variations, explanation boxes, and comment systems.
- Project Overview
- Quick Start
- Project Structure
- Environment Setup
- Installation and Running
- Development Workflow
- Deployment
- Documentation
- Contributing
- Additional Resources
This project is a Next.js-based article experiment platform designed to test and implement various article presentation formats and user engagement features. The project combines modern web technologies with innovative content presentation approaches.
- Multi-Study Support: Run multiple research projects simultaneously with isolated data
- Qualtrics Integration: Track user interactions linked to survey responses
- Research Dashboard: Comprehensive analytics and data export tools
- Dynamic Author Information: Multiple bio variations per study
- Explanation Boxes: Contextual information for articles
- Comment System: Anonymous and authenticated modes with research tracking
- Article Metadata: Version tracking and rich metadata
- Trust Project Integration: Trust indicators and transparency
- Google Analytics Integration: User behavior tracking
The comment system implements a research-focused approach:
- Default comments are stored in the article document and shown to all users
- User interactions (comments, votes, replies) are:
- Saved to the database for research tracking
- Displayed immediately to the interacting user
- Reset to default comments on page refresh
- Components:
Comments: Main orchestrator componentCommentList: Displays comments and handles interactionsCommentForm: Handles new comment submissionCommentVoteSection: Manages voting functionality
- Frontend Framework: Next.js with TypeScript
- Styling: CSS Modules and global styles
- Architecture: Component-based for modular development
- Configuration: Environment variables
- Development Tools: ESLint and TypeScript
The project follows Next.js App Router conventions with:
/src/appfor Next.js pages and layouts/src/componentsfor React components/publicfor static assets/src/libfor utility functions/src/typesfor TypeScript definitions/src/stylesfor global styles and CSS variables
Components are organized by feature and follow a consistent pattern:
- Each component has its own directory
- Component files include:
[ComponentName].tsx: React component[ComponentName].module.css: Component-specific styles
- Components use CSS Modules for scoped styling
- TypeScript interfaces are defined in the types directory
- Firebase/Firestore: Used for data storage
- lib/firestore.ts: Contains database operations
- lib/articles.ts: Article-specific data utilities
- lib/config.ts: Default configuration values
Create a .env.local file with:
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_auth_domain
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_storage_bucket
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id
# Analytics Configuration
NEXT_PUBLIC_GA_MEASUREMENT_ID=your_ga_id
The project supports two Firebase projects:
- Development:
article-experiment-next-dev - Production:
article-experiment-next
-
Set up environment files from your existing
.env.local:npm run env:setup
This creates
.env.devand.env.prodfrom your current.env.local. -
Review and update
.env.devand.env.prodwith the correct Firebase config values for each project.
npm run dev— Next.js server connected to livearticle-experiment-next-dev(loads.env.dev)npm run dev:prod— Next.js server connected to livearticle-experiment-next(loads.env.prod)npm run dev:emulator— Firebase emulator + Next.js server; all data and auth use the local emulator only (loads.env.devfor project config, project:article-experiment-next-dev)
To verify which project you're connected to, check the browser console when running the dev server.
For a complete getting started guide, see docs/GETTING_STARTED.md.
TL;DR:
git clone <repo-url>
cd article-experiment-next
npm install
# Set up .env.local (see Environment Setup)
npm run dev:emulator # or npm run devnpm run dev
- Node.js (v18 or higher)
- npm (v9 or higher)
- Git
- Firebase CLI (
npm install -g firebase-tools)
-
Clone the repository:
git clone https://github.com/your-username/article-experiment-next.git cd article-experiment-next -
Install dependencies:
npm install
-
Set up environment variables:
- Copy
.env.exampleto.env.local - Fill in the required environment variables as described in Environment Setup
- Copy
npm run devThis will start the development server at http://localhost:3000 and connect to the live dev Firebase project (article-experiment-next-dev).
Other development commands:
npm run dev:prod— Connect to live production project (article-experiment-next)npm run dev:emulator— Run Firebase emulator + Next.js; all data/auth use local emulator only
npm run build
npm startThis will create an optimized production build and start the server.
npm test- If you encounter any dependency-related issues, try:
rm -rf node_modules npm install
- Ensure all environment variables are properly set in
.env.local - Check that you're using the correct Node.js version
- Create new components in the
src/componentsdirectory - Use CSS Modules for styling
- Follow TypeScript best practices
- Add appropriate documentation
- Articles are stored in Firestore
- Use the provided Firestore utilities in
src/lib/firestore.ts - Follow the Article type definition in
src/types/article.ts
- Use CSS Modules for component-specific styles
- Follow BEM naming convention
- Maintain consistent spacing and typography
- Use CSS variables for theming
npm run deploy
The project uses two main branches:
- main: Development branch for feature development and testing
- prod: Production branch that deploys to Netlify
Netlify Project Admin | Netlify Public URL
- Connect your repository to Netlify
- Configure build settings:
- Build command:
npm run build - Publish directory:
.next - Base directory:
article-experiment-next
- Build command:
- Set up environment variables in Netlify dashboard
- Configure branch settings:
- Production branch:
prod - Deploy previews: Enabled for pull requests
- Production branch:
- Deploy:
- From your editor/terminal (recommended): Run
npm run deploy. This triggers the "Merge Main to Prod (Advanced)" GitHub Action via GitHub CLI (merge main → prod, then Netlify deploys). Requiresghinstalled and logged in to github.com. - Manually: In GitHub → Actions → "Merge Main to Prod (Advanced)" → Run workflow, type YES to confirm.
- Via git: Checkout
prod, mergemainintoprod, push. Netlify deploys on push toprod.
- From your editor/terminal (recommended): Run
# Development
git checkout main
npm run dev # Start development server
# Production
git checkout prod
npm run build # Build the application
npm run start # Start production server- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Comprehensive documentation is available in the /docs directory:
- Getting Started Guide - Quick start for new developers/researchers
- Common Tasks - Step-by-step workflows
- Local Dev Setup - Complete local development guide
- Source Code Overview - Architecture and code structure
- Firebase Auth Setup - Authentication configuration
- Multiple Research Projects - Multi-study system
- Qualtrics Integration - Survey integration guide
- Logging Events - Event tracking reference
- Deployment Guide - Netlify deployment
- Research Data Export - Data export guide
| Script | Purpose |
|---|---|
npm run dev |
Start dev server (live Firebase) |
npm run dev:emulator |
Start dev server with emulator |
npm run build |
Build for production |
npm run deploy |
Deploy to Netlify (triggers Merge Main to Prod workflow via GitHub CLI) |
npm run export-research |
Export all data for research |
npm run import-data:dev |
Import data to dev Firebase |
firebase use dev |
Switch to dev Firebase project |
firebase use prod |
Switch to prod Firebase project |
See package.json for all available scripts.