A production-ready social media backend API built with Node.js, Express, TypeScript, and MongoDB.
- 🔐 Authentication & Authorization - JWT-based auth with role-based access control
- 👤 User Management - Profile management with avatar support
- 📝 Posts - Create, read, update, and delete posts with tags
- 💬 Comments - Nested comments support (reply to comments)
- ❤️ Reactions - Like/unlike posts
- 🏷️ Tags - Tag management (admin only)
- 📰 Global Feed - Aggregated feed with engagement metrics
- 🛡️ Security - Helmet, CORS, rate limiting
- 📊 Logging - Winston logger with file and console outputs
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: MongoDB with Mongoose
- Authentication: JWT (jsonwebtoken)
- Validation: Zod
- Security: Helmet, CORS, bcryptjs
- Logging: Winston
src/
├── app.ts # Express app configuration
├── server.ts # Server entry point
├── config/ # Configuration files
│ ├── env.ts # Environment variables
│ ├── database.ts # MongoDB connection
│ └── logger.ts # Winston logger setup
├── modules/ # Feature modules
│ ├── auth/ # Authentication
│ ├── user/ # User management
│ ├── post/ # Posts
│ ├── comment/ # Comments
│ ├── reaction/ # Reactions
│ ├── feed/ # Global feed
│ └── tag/ # Tags
├── common/ # Shared utilities
│ ├── middleware/ # Express middleware
│ ├── utils/ # Helper functions
│ ├── constants/ # Constants
│ ├── types/ # TypeScript types
│ └── exceptions/ # Custom error classes
├── routes/ # Route definitions
└── database/ # Database models
└── models/ # Mongoose schemas
- Clone the repository
git clone <repository-url>
cd DevCom_Node- Install dependencies
npm install- Set up environment variables
cp .env.example .env-
Update
.envwith your configuration:- MongoDB connection string
- JWT secret
- Cloudinary credentials (optional)
-
Start the development server
npm run devPOST /api/auth/register- Register a new userPOST /api/auth/login- Login user
GET /api/users/profile- Get current user profile (auth required)PUT /api/users/profile- Update current user profile (auth required)GET /api/users- Get all users (auth required)
POST /api/posts- Create a post (auth required)GET /api/posts- Get all posts (paginated)GET /api/posts/:id- Get a specific postPUT /api/posts/:id- Update a post (auth required, owner only)DELETE /api/posts/:id- Delete a post (auth required, owner only)
POST /api/comments/post/:postId- Create a comment (auth required)GET /api/comments/post/:postId- Get all comments for a postGET /api/comments/:id- Get a specific commentPUT /api/comments/:id- Update a comment (auth required, owner only)DELETE /api/comments/:id- Delete a comment (auth required, owner only)
POST /api/reactions/post/:postId- Toggle reaction (auth required)GET /api/reactions/post/:postId/count- Get reaction countGET /api/reactions/post/:postId/check- Check if user reacted (auth required)
GET /api/feed- Get global feed (paginated, optional auth)
GET /api/tags- Get all tagsGET /api/tags/:id- Get a specific tagDELETE /api/tags/:id- Delete a tag (auth required, admin only)
- id, name, email, password, role, avatar
- id, title, content, image_url, tags[], author
- id, comment_message, post, author, parent_comment_id
- id, post, user
- id, name
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm test- Run testsnpm run lint- Run ESLintnpm run format- Format code with Prettier
See .env.example for all required environment variables.
Start MongoDB and API together:
docker-compose up -dThis will start:
- MongoDB on port 27017
- API on port 3000
docker build -t devcom-api .
docker run -p 3000:3000 --env-file .env devcom-apidocker pull ghcr.io/OWNER/REPO:latest
docker run -p 3000:3000 --env-file .env ghcr.io/OWNER/REPO:latestThis project includes GitHub Actions workflows for continuous integration:
- CI Workflow (
.github/workflows/ci.yml):- Runs on push/PR to
mainanddevelopbranches - Sets up MongoDB 7.0 container
- Runs linter, builds project, runs tests
- Publishes to GitHub Packages (npm)
- Builds and pushes Docker image to GitHub Container Registry
- Runs on push/PR to
See .github/workflows/README.md for detailed CI/CD documentation.
ISC