A modern blog application built with Go, featuring JWT authentication, role-based access control, and MongoDB integration and the Gin framework.This project is to help me learn how blog application backends are structured and built.
Work in Progress - Core authentication and user management implemented
- JWT-based authentication
- Role-based access control (Publisher, Writer, Reader)
- User registration and login
- Password hashing with bcrypt
- Input validation (email, password, username)
- MongoDB integration with connection pooling
- Docker containerization
- Environment-based configuration
- Article creation and management
- Category system
- File upload integration
- Search functionality
- User profile management
- API documentation
- Backend: Go (Gin framework)
- Database: MongoDB
- Authentication: JWT tokens
- Containerization: Docker & Docker Compose
- Password Hashing: bcrypt
gh gist blog/
├── Database/ # Database connection
├── handlers/ # HTTP handlers and routes
├── middleware/ # Authentication middleware
├── models/ # Data models
├── repository/ # Database operations
├── services/ # Business logic
├── utils/ # Utility functions (JWT, password)
├── validation/ # Input validation
├── docker-compose.yml # Docker configuration
├── Dockerfile # Container build
└── main.go # Application entry point
- Go 1.19 or higher
- MongoDB (local or Atlas)
- Docker (optional)
Create a .env file in the root directory with the required environment variables. See .env.example for reference.
- Clone the repository
- Install dependencies:
go mod tidy
- Start MongoDB (if running locally)
- Run the application:
go run main.go
- Start all services:
docker compose up --build
GET /api/public/writers- Fetch all writersPOST /api/public/auth/login- User login
POST /api/admin/articles- Create article (requires authentication)
POST /api/admin/auth/register- Create user (publisher only)
The application uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Publisher: Can create users and articles
- Writer: Can create articles
- Reader: Read-only access
- Local Development: Use
go run main.gofor fast iteration - Container Testing: Use
docker compose up --buildbefore commits - Production: Deploy using Docker containers
- Uses Dockerfile for deployment
- Set environment variables via
fly secrets - MongoDB Atlas recommended for production database or any external database
- Local: Uses
.envfile - Docker: Uses docker-compose environment variables
- Production: Uses platform-specific environment variables
- Fork the repository
- Create a feature branch
- Make your changes
- Test with Docker before committing
- Submit a pull request
This project is not open sourced yet