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.
- π 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
- Node.js v18+
- pnpm (package manager)
- Docker & Docker Compose (optional, but recommended)
# 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
Make sure Docker and Docker Compose are installed.
make dev # Start development environment
make dev-build # Build and start development
make dev-down # Stop development environment
make prod # Start production environment
make prod-build # Build and start production
make prod-down # Stop production environment
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
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-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
π The API documentation is auto-generated using Swagger (OpenAPI).
- URL: http://localhost:3001/api-docs
- Format: YAML files stored in
src/docs/
- Tags: User, Auth, Role, Article, Comment
- 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
Run tests using Docker or locally:
# Using Docker
make test
# Or locally
pnpm test
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
-
Build the application:
pnpm run build
-
Start production server:
pnpm run start:prod
make prod-build # Build production images
make prod # Start production environment
# 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
# Seed initial data
node scripts/seed.js
# Create admin user
node scripts/create-admin.js
- 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow TypeScript best practices
- Use ESLint configuration provided
- Write tests for new features
- Update documentation as needed
-
MongoDB Connection Error
- Ensure MongoDB is running
- Check
MONGODB_URI
in.env
-
Port Already in Use
- Change
PORT
in.env
- Kill existing processes:
lsof -ti:3001 | xargs kill
- Change
-
Docker Issues
- Clean containers:
make clean
- Rebuild images:
make dev-build
- Clean containers:
If you encounter any issues or have questions:
- Check the API Documentation
- Review the troubleshooting section
- Open an issue on GitHub
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with the MEAN stack
- Inspired by modern blog platforms
- Community contributions welcome
Happy Coding! π