This is the backend of a social media application, built with modern web technologies. It handles user authentication, post management, caching, and more.
- Authentication: User Signup, signin, and logout.
- Post Management: Create, update, delete, and retrieve posts.
- Commenting System: Add and view comments on posts.
- Likes: Like and unlike posts.
- Profiles: User profile creation and management.
- Search Functionality: Search for posts or users.
- Follow System: Follow and unfollow users.
- Payment Integration: Payment handling and processing.
- File Uploads: Manage media uploads using a dedicated
/uploads
directory. - Security Enhancements:
- Helmet for setting secure HTTP headers.
- MongoSanitize to prevent NoSQL injection attacks.
- Rate limiting to prevent abuse.
- HPP to protect against HTTP parameter pollution.
- CORS: Configured for secure cross-origin requests.
- Error Handling: Centralized middleware for managing errors.
- Static File Serving: Serve static files for user uploads.
- Node.js with Express: Backend framework
- TypeScript: Typed JavaScript for robust development
- MongoDB with Mongoose: NoSQL database
- Redis Cloud: Caching mechanism
- bcrypt: For hashing passwords
- JWT: Authentication
- Cloudinary: For media uploads
- Docker: Containerized setup (optional)
- Prettier: Code formatting
- Postman: API testing
Ensure the following are installed on your system:
- Node.js (v18 or later)
- pnpm (Preferred package manager)
- MongoDB (can use cloud)
- Redis Cloud account
- Git
- Docker (optional, for containerized setup)
-
Clone the repository:
git clone https://github.com/rehan-adi/Softcore-Backend cd Softcore-Backend
-
Install dependencies:
pnpm install
-
Set up environment variables: Create a
.env
file in the root directory and add the following:PORT=3333 MONGO_URI="your_mongodb_connection_string" appName="YourAppName" DB_NAME="your_database_name" CORS_ORIGIN="your_frontend_url" JWT_SECRET="your_secret_key" GOOGLE_CLIENT_ID="your_google_client_id" GOOGLE_CLIENT_SECRET="your_google_client_secret" CLOUDINARY_CLOUD_NAME="your_cloudinary_name" CLOUDINARY_API_KEY="your_cloudinary_api_key" CLOUDINARY_API_SECRET="your_cloudinary_api_secret" REDIS_URL="your_redis_cloud_url"
-
Start the server:
pnpm run dev
-
Testing the APIs: Use Postman or an alternative tool to test the APIs. Import the provided
postman_collection.json
file for pre-configured requests.
.
├── src
│ ├── config
│ ├── controllers
│ ├── db
│ ├── interfaces
│ ├── lib
│ ├── middlewares
│ ├── models
│ ├── routes
│ ├── utils
│ ├── validations
│ ├── app.ts
│ └── server.ts
├── types
├── uploads
├── .dockerignore
├── .env.sample
├── .gitignore
├── .prettierignore
├── .prettierrc
├── docker-compose.yml
├── Dockerfile
├── package.json
├── pnpm-lock.yaml
├── README.md
└── tsconfig.json
This project is configured to run with Docker Compose for easy setup and management. Note: If you prefer to run the app directly without Docker, skip this section and proceed with the standard setup.
To build and start the application, run the following command:
docker-compose up
This will automatically build the images (if needed) and start the containers based on the configuration in the docker-compose.yml file.
To stop the running containers, use the following command:
docker-compose down
This command will stop and remove all containers defined in the docker-compose.yml file. It will also remove the networks created by Docker Compose, but it will not delete your data volumes unless you explicitly specify --volumes
pnpm run dev
: Starts the development server.pnpm run build
: Builds the production-ready code.pnpm run start
: Starts the built application.pnpm run format
: Formats the codebase using Prettier.
This project is licensed under the MIT License.
- [Rehan]
- GitHub: rehan-adi
- Twitter: Rehan_Coder
Contributions are welcome! Please open an issue or submit a pull request for any improvements or features.
- bcrypt for password hashing
- Express for server setup
- Redis Cloud for caching
- Cloudinary for media handling