A modern, full-stack web application for Nigerian political discussions and debates. Built with Node.js, Express, PostgreSQL, and Redis.
- User Authentication & Authorization - JWT-based auth with role-based access
- Political Discussions - Create, read, update posts with Nigerian political focus
- Comment System - Threaded discussions with voting
- Voting System - Upvote/downvote posts and comments
- Polling System - Create polls on posts with multiple voting options
- Share Functionality - URL-friendly slugs for easy sharing
- Admin Panel - Content moderation and user management
- Real-time Analytics - Page views and user behavior tracking
- RESTful API - Well-structured endpoints with pagination
- Database Optimization - PostgreSQL with proper indexing
- Caching Layer - Redis for performance optimization
- Security - Rate limiting, input validation, SQL injection protection
- Containerization - Docker and Docker Compose for easy deployment
- Testing - Comprehensive test suite
├── Backend (Node.js/Express)
│ ├── Authentication & Authorization
│ ├── RESTful API Endpoints
│ ├── Database Layer (PostgreSQL)
│ ├── Caching Layer (Redis)
│ └── Security Middleware
├── Database Schema
│ ├── Users & Authentication
│ ├── Posts & Comments
│ ├── Voting System
│ ├── Polling System
│ └── Analytics & Reports
└── Deployment
├── Docker Configuration
├── Environment Management
└── Production Setup
- Node.js 18+
- PostgreSQL 14+
- Redis 6+
- Docker & Docker Compose (optional)
- Clone the repository
git clone https://github.com/yourusername/leftplot-backend.git
cd leftplot-backend- Install dependencies
npm install- Set up environment variables
cp env.example .env
# Edit .env with your configuration- Set up the database
# Create database
createdb leftplot_db
# Run migrations
psql -d leftplot_db -f db/schema.sql
# Seed with sample data
psql -d leftplot_db -f megaseed.sql- Start the application
# Development
npm run dev
# Production
npm start# Build and run with Docker Compose
docker-compose up --build
# Or run individual services
docker-compose up postgres redis
npm startleftplot-backend/
├── db/
│ └── schema.sql # Database schema
├── middleware/
│ └── auth.js # Authentication middleware
├── routes/
│ ├── auth.js # Authentication routes
│ ├── posts.js # Post management
│ ├── comments.js # Comment system
│ ├── polls.js # Polling system
│ ├── users.js # User management
│ ├── admin.js # Admin panel
│ └── reports.js # Reporting system
├── utils/
│ └── slugGenerator.js # URL slug generation
├── test/ # Test suite
├── logs/ # Application logs
├── server.js # Main application file
├── package.json
├── docker-compose.yml
└── Dockerfile
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutPOST /api/auth/verify- Email verification
GET /api/posts- Get all posts (with pagination)GET /api/posts/:identifier- Get post by ID or slugPOST /api/posts- Create new postPUT /api/posts/:id- Update postDELETE /api/posts/:id- Delete post (admin)POST /api/posts/:id/upvote- Upvote postPOST /api/posts/:id/downvote- Downvote post
GET /api/comments/:postId- Get comments for postPOST /api/comments- Create commentPUT /api/comments/:id- Update commentDELETE /api/comments/:id- Delete comment
GET /api/polls/post/:postId- Get polls for postGET /api/polls/:id- Get single pollPOST /api/polls- Create pollPOST /api/polls/:id/vote- Vote on pollPUT /api/polls/:id- Update pollDELETE /api/polls/:id- Delete poll
GET /api/users/profile- Get user profilePUT /api/users/profile- Update profileGET /api/admin/users- Admin: Get all usersGET /api/admin/posts- Admin: Get all postsPATCH /api/admin/users/:id/block- Admin: Block userPATCH /api/admin/posts/:id/block- Admin: Block post
- users - User accounts and authentication
- posts - Political discussions and content
- comments - Threaded discussions
- post_votes - Post voting system
- comment_votes - Comment voting system
- polls - Polling system
- poll_options - Poll choices
- poll_votes - Poll voting records
- reports - Content moderation
- page_views - Analytics tracking
- JWT Authentication - Secure token-based auth
- Password Hashing - bcrypt for password security
- Rate Limiting - Prevent abuse and spam
- Input Validation - Sanitize user inputs
- SQL Injection Protection - Parameterized queries
- CORS Configuration - Cross-origin request handling
- Helmet.js - Security headers
# Run all tests
npm test
# Run specific test files
npm test -- auth.test.js
npm test -- posts.test.js
npm test -- comments.test.js- Redis Caching - API response caching
- Database Indexing - Optimized queries
- Connection Pooling - Efficient database connections
- Compression - Gzip response compression
- Pagination - Efficient data loading
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/leftplot_db
# Redis
REDIS_URL=redis://localhost:6379
# JWT
JWT_SECRET=your-secret-key
# Server
PORT=3000
NODE_ENV=production
# Frontend URL
FRONTEND_URL=https://yourdomain.com- Set up PostgreSQL database
- Configure Redis cache
- Set environment variables
- Enable HTTPS
- Set up monitoring
- Configure backups
- Set up CI/CD pipeline
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for Nigerian political discourse
- Focused on local content and language support
- Designed for scalability and performance
- Community-driven development
For support, create an issue in this repository.