A modern, feature-rich blogging platform API built with Node.js, Express, TypeScript, and PostgreSQL. This project follows clean architecture principles and provides a robust foundation for building scalable blog applications.
-
Authentication & Authorization
- JWT-based authentication
- Role-based access control (Admin/User)
- Secure password hashing with bcrypt
-
Blog Posts Management
- CRUD operations for posts
- Draft/Published/Scheduled post status
- Categories and tags support
- Rich text content support
-
Comments System
- Nested comments support
- Comment moderation
- CRUD operations for comments
-
Reactions System
- Like/Unlike posts and comments
- Reaction counts and user reaction status
- Extensible reaction types
-
Media Management
- Image upload support with Cloudinary
- Profile picture management
- Media optimization
-
User Management
- User profiles with avatars
- Bio and personal information
- Activity tracking
-
Audit Logging System
- Comprehensive activity tracking
- User action logging across all modules
- Detailed audit trail for compliance
- Action types: CREATE, READ, UPDATE, DELETE
- Entity-specific audit records
The project follows a modular architecture with clear separation of concerns:
src/
├── core/ # Core functionality and shared code
│ ├── middleware/ # Express middleware
│ │ └── audit/ # Audit logging middleware
│ ├── interfaces/ # TypeScript interfaces
│ ├── services/ # Core services
│ │ └── audit/ # Audit logging service
│ └── utils/ # Utility functions
│
├── modules/ # Feature modules
│ ├── audit/ # Audit system module
│ ├── users/ # User management
│ ├── posts/ # Blog posts
│ ├── comments/ # Comments system
│ ├── reactions/ # Reactions/Likes
│ ├── categories/ # Post categories
│ └── tags/ # Post tags
│
└── app.ts # Application entry point
Each module follows a consistent structure:
controller.ts
: Request handling and response formattingservice.ts
: Business logic implementationroutes.ts
: Route definitions and middlewaredto/
: Data Transfer Objects for validation
- Runtime: Node.js (>18.16.0)
- Framework: Express.js with TypeScript
- Database: PostgreSQL with Prisma ORM
- Testing: Jest
- Authentication: JWT with bcrypt
- Validation: class-validator, express-validator
- Documentation: Swagger/OpenAPI
- Cloud Storage: Cloudinary
- Development: ESLint, TypeScript
- API Security: CORS enabled
-
Clone the repository
git clone <your-repository-url> cd blog-posts
-
Install dependencies
yarn install
-
Environment Setup
cp .env.example .env # Configure your environment variables
-
Database Setup
# Run database migrations yarn migrate
-
Development Server
yarn dev
-
Production Build
yarn build yarn start
yarn dev
: Start development server with hot-reloadyarn migrate
: Run Prisma migrations for developmentyarn migrate:prod
: Run Prisma migrations for productionyarn build
: Build the TypeScript projectyarn start
: Start the production serveryarn lint
: Run ESLintyarn test
: Run Jest testsyarn test:watch
: Run tests in watch mode
The project includes Docker support for easy deployment:
# Build and run with Docker Compose
docker-compose up --build
API documentation is available at /api-docs
when running the server. The API follows RESTful principles and includes:
- Detailed endpoint descriptions
- Request/Response examples
- Authentication requirements
- Schema definitions
Required environment variables (see .env.example
):
DATABASE_URL
: PostgreSQL connection stringJWT_SECRET
: Secret key for JWT signingCLOUDINARY_*
: Cloudinary configurationPORT
: Server port (default: 3000)
# Run tests
yarn test
# Run tests with coverage
yarn test:coverage
POST /api/auth/register
: Register new userPOST /api/auth/login
: Login user
GET /api/posts
: List postsPOST /api/posts
: Create postGET /api/posts/:id
: Get postPUT /api/posts/:id
: Update postDELETE /api/posts/:id
: Delete post
GET /api/comments/:postId
: List commentsPOST /api/comments
: Create commentPUT /api/comments/:id
: Update commentDELETE /api/comments/:id
: Delete comment
POST /api/reactions/:entityType/:entityId/like
: Toggle likeGET /api/reactions/:entityType/:entityId/likes
: Get likes count
GET /api/audit/logs
: List audit logs (Admin only)GET /api/audit/logs/:entityType
: Get logs by entity typeGET /api/audit/logs/:entityType/:entityId
: Get entity-specific logsGET /api/audit/users/:userId/activity
: Get user activity logs
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: 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.