Skip to content

omarl68/blog-platfrom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Blog Platform – Backend API

This is the backend for a collaborative blog platform built using the MEAN stack (MongoDB, Express.js, Angular, Node.js), following a modular monolith architecture.

✨ Features

  • πŸ” Role-based access control (Admin, Editor, Writer, Reader)
  • πŸ’¬ Real-time comment system powered by Socket.IO
  • πŸ”— RESTful APIs for articles, users, and comments
  • 🐳 Docker support for development and production
  • πŸ“š OpenAPI documentation with Swagger
  • πŸ—οΈ Modular monolith architecture for scalability
  • πŸ›‘οΈ TypeScript for type safety
  • βœ… Data validation with Joi

πŸš€ Quick Start

πŸ”§ Requirements

  • Node.js v18+
  • pnpm (package manager)
  • Docker & Docker Compose (optional, but recommended)

πŸ“₯ Installation

Option 1: Local Development (without Docker)

# Clone the repository
git clone https://github.com/your-org/blog-platform.git
cd blog-platform

# Install dependencies
pnpm install

# Copy environment file
cp .env.example .env

# Edit `.env` and configure your MongoDB URI
# Example: MONGODB_URI=mongodb://localhost:27017/blog-platform

# Start the development server
pnpm run start:dev

Server will run by default on: http://localhost:3001

Option 2: Docker Development

Make sure Docker and Docker Compose are installed.

Development Environment

make dev         # Start development environment
make dev-build   # Build and start development
make dev-down    # Stop development environment

Production Environment

make prod        # Start production environment
make prod-build  # Build and start production
make prod-down   # Stop production environment

Useful Docker Commands

make logs        # View container logs
make restart     # Restart containers
make clean       # Remove volumes and prune
make clean-dev   # Clean development environment
make test        # Run backend tests
make db-shell    # Access MongoDB shell
make help        # View all available make targets

πŸ” Roles & Permissions

Role Permissions
Admin Manage users, manage all articles
Editor View all articles, edit/write articles
Writer Write and edit own articles
Reader View all articles

πŸ“‚ Project Structure

/project-root/
β”œβ”€β”€ diagrams/                # Architecture diagrams
β”œβ”€β”€ dist/                    # Compiled TypeScript output
β”œβ”€β”€ logs/                    # Application logs
β”œβ”€β”€ public/                  # Static files (avatars, articles)
β”œβ”€β”€ scripts/                 # Database seeders, CLI tools
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ constants/           # Enums, roles, status codes
β”‚   β”œβ”€β”€ core/                # Auth middleware, base services
β”‚   β”œβ”€β”€ docs/                # OpenAPI YAML files
β”‚   β”œβ”€β”€ modules/             # Feature modules (auth, articles, users, comments)
β”‚   β”œβ”€β”€ routes/              # Route definitions and mapping
β”‚   β”œβ”€β”€ types/               # TypeScript interfaces and types
β”‚   β”œβ”€β”€ utils/               # Helper functions (multer, error handling)
β”‚   β”œβ”€β”€ app.ts               # Express application configuration
β”‚   └── server.ts            # Application entry point
β”œβ”€β”€ .env                     # Environment variables
β”œβ”€β”€ .env.example             # Example environment file
β”œβ”€β”€ docker-compose.dev.yml   # Development Docker configuration
β”œβ”€β”€ docker-compose.yml       # Production Docker configuration
β”œβ”€β”€ Makefile                 # Docker and project commands
β”œβ”€β”€ package.json
└── pnpm-lock.yaml

πŸ“‘ API Documentation

πŸ“– The API documentation is auto-generated using Swagger (OpenAPI).

API Endpoints Overview

  • Auth: /api/auth - Authentication and authorization
  • Users: /api/users - User management
  • Articles: /api/articles - Blog article operations
  • Comments: /api/comments - Comment system
  • Roles: /api/roles - Role management

πŸ§ͺ Testing

Run tests using Docker or locally:

# Using Docker
make test

# Or locally
pnpm test

πŸ”§ Environment Variables

Copy .env.example to .env and configure the following variables:

# Database
MONGODB_URI=mongodb://localhost:27017/blog-platform

# Server
PORT=3001
NODE_ENV=development

# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=7d

# Socket.IO
SOCKET_IO_ORIGIN=http://localhost:4200

# File Upload
MAX_FILE_SIZE=5242880  # 5MB
UPLOAD_PATH=./public/uploads

πŸš€ Deployment

Production Deployment

  1. Build the application:

    pnpm run build
  2. Start production server:

    pnpm run start:prod

Docker Production

make prod-build  # Build production images
make prod        # Start production environment

πŸ› οΈ Development

Available Scripts

# Development
pnpm run start:dev    # Start with nodemon
pnpm run build        # Build TypeScript
pnpm run start:prod   # Start production server

# Testing
pnpm run test         # Run tests
pnpm run test:watch   # Run tests in watch mode

# Linting
pnpm run lint         # Run ESLint
pnpm run lint:fix     # Fix ESLint issues

Database Seeding

# Seed initial data
node scripts/seed.js

# Create admin user
node scripts/create-admin.js

βœ… Tech Stack

  • Backend Framework: Node.js with Express.js
  • Database: MongoDB with Mongoose ODM
  • Language: TypeScript
  • Real-time: Socket.IO
  • Documentation: Swagger (OpenAPI)
  • Validation: Joi
  • Authentication: JWT
  • File Upload: Multer
  • Containerization: Docker & Docker Compose
  • Package Manager: pnpm

πŸ“ Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow TypeScript best practices
  • Use ESLint configuration provided
  • Write tests for new features
  • Update documentation as needed

πŸ› Troubleshooting

Common Issues

  1. MongoDB Connection Error

    • Ensure MongoDB is running
    • Check MONGODB_URI in .env
  2. Port Already in Use

    • Change PORT in .env
    • Kill existing processes: lsof -ti:3001 | xargs kill
  3. Docker Issues

    • Clean containers: make clean
    • Rebuild images: make dev-build

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the API Documentation
  2. Review the troubleshooting section
  3. Open an issue on GitHub

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Built with the MEAN stack
  • Inspired by modern blog platforms
  • Community contributions welcome

Happy Coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published