A full-stack social media platform built with modern web technologies. Users can create posts, discover content, follow other users, and engage with a vibrant community.
- Features
- Tech Stack
- Prerequisites
- Project Structure
- Local Setup Guide
- Environment Variables
- Running the Application
- API Documentation
- Deployment
- Contributing
✨ User Management
- Google OAuth authentication
- User profiles and follow system
- JWT-based session management
📝 Post Creation & Management
- Create, read, update, and delete posts
- Image uploads to AWS S3
- Real-time post discovery
💬 Social Features
- Comment on posts
- Follow/unfollow users
- Personalized feed based on followed users
- Explore trending content
🔔 Additional
- Bookmark posts
- Notification system
- Responsive design for all devices
- Runtime: Node.js with TypeScript
- Framework: Express.js 5.x
- GraphQL: Apollo Server 5.x
- Database: PostgreSQL with Prisma ORM
- Cache: Redis
- Authentication: JWT + Google OAuth 2.0
- Cloud Storage: AWS S3
- Package Manager: pnpm
- Framework: Next.js 16
- UI Library: React 19
- Language: TypeScript
- Styling: Tailwind CSS 4 with PostCSS
- State Management: TanStack Query (React Query)
- API Client: GraphQL Request
- Code Generation: GraphQL Code Generator
- Package Manager: pnpm
- Containerization: Docker & Docker Compose
- Database Migrations: Prisma Migrate
Before you begin, ensure you have the following installed on your machine:
- Node.js (v18 or higher) - Download
- pnpm (v10.25.0 or higher) - Install
- PostgreSQL (v12 or higher) - Download
- Redis (v6 or higher) - Download or use Docker
- Git - Download
- Docker & Docker Compose - For running PostgreSQL and Redis in containers
spread/
├── server/ # Backend (GraphQL API)
│ ├── src/
│ │ ├── app/ # GraphQL modules (post, user)
│ │ ├── config/ # Environment configuration
│ │ ├── generated/ # Auto-generated Prisma types
│ │ ├── lib/ # Database and Redis connections
│ │ ├── services/ # Business logic (JWT, user, post)
│ │ └── index.ts # Server entry point
│ ├── prisma/
│ │ ├── schema.prisma # Database schema
│ │ └── migrations/ # Database migration files
│ ├── BACKEND_ARCHITECTURE.md # 📚 Complete backend documentation
│ ├── QUICK_REFERENCE.md # 🚀 Quick reference guide
│ └── package.json
│
├── web/ # Frontend (Next.js App)
│ ├── src/
│ │ ├── app/ # Next.js pages and layouts
│ │ ├── components/ # React components
│ │ ├── clients/ # API client setup
│ │ ├── context/ # React context (Theme)
│ │ ├── gql/ # GraphQL code-generated files
│ │ ├── graphql/ # GraphQL queries and mutations
│ │ └── hooks/ # Custom React hooks
│ ├── public/ # Static assets
│ └── package.json
│
└── docker-compose.yml # Docker services configuration
- Backend Architecture: server/BACKEND_ARCHITECTURE.md - Complete backend documentation including architecture, GraphQL schema, authentication flow, and API examples
- Quick Reference: server/QUICK_REFERENCE.md - Quick reference guide for common tasks and operations
- Frontend Architecture: web/README.md - Comprehensive frontend documentation covering Next.js architecture, React components, state management, GraphQL integration, styling, and development workflow
git clone https://github.com/yourusername/spread.git
cd spreadInstall dependencies for both server and web packages:
# Install all dependencies in monorepo
pnpm installCreate a docker-compose.yml file in the root directory:
version: '3.8'
services:
postgres:
image: postgres:16-alpine
container_name: spread_postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: spread_db
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
container_name: spread_redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgres_data:
redis_data:Run the containers:
docker-compose up -dPostgreSQL:
- Follow the official PostgreSQL installation guide
- Create a database named
spread_db
Redis:
- Follow the official Redis installation guide
- Or on Windows, use WSL2 or Docker
Create server/.env file:
# Server Configuration
PORT=9000
NODE_ENV=development
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/spread_db?schema=public"
# Redis
REDIS_URL="redis://localhost:6379"
# JWT
JWT_SECRET="your-super-secret-jwt-key-change-in-production"
# AWS S3 Configuration
AWS_S3_ACCESS_KEY_ID="your-aws-access-key"
AWS_S3_SECRET_ACCESS_KEY="your-aws-secret-key"
AWS_S3_REGION="us-east-1"
AWS_S3_BUCKET_NAME="your-s3-bucket-name"
# Google OAuth (optional, if using in backend)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"Create web/.env.local file:
# API Configuration
NEXT_PUBLIC_API_URL="http://localhost:9000/graphql"
# Google OAuth
NEXT_PUBLIC_GOOGLE_CLIENT_ID="your-google-client-id"
# Environment
NODE_ENV=development- Create an AWS account at aws.amazon.com
- Create an S3 bucket for storing images
- Create an IAM user with S3 access
- Generate access keys and add them to your
.envfile
- Go to Google Cloud Console
- Create a new project
- Enable the Google+ API
- Create OAuth 2.0 credentials (Web application)
- Add
http://localhost:3000to authorized redirect URIs - Copy your Client ID and Client Secret to the
.envfiles
Navigate to the server directory and run migrations:
cd server
pnpm migrateThis will:
- Create tables in PostgreSQL based on
prisma/schema.prisma - Generate Prisma Client for type-safe database access
pnpm generate| Variable | Description | Example |
|---|---|---|
PORT |
Server port | 9000 |
NODE_ENV |
Environment mode | development |
DATABASE_URL |
PostgreSQL connection string | postgresql://user:pass@localhost:5432/spread_db |
REDIS_URL |
Redis connection URL | redis://localhost:6379 |
JWT_SECRET |
Secret key for JWT signing | your-secret-key |
AWS_S3_ACCESS_KEY_ID |
AWS access key | AKIAIOSFODNN7EXAMPLE |
AWS_S3_SECRET_ACCESS_KEY |
AWS secret key | wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
AWS_S3_REGION |
AWS S3 region | us-east-1 |
AWS_S3_BUCKET_NAME |
S3 bucket name | spread-bucket |
| Variable | Description | Example |
|---|---|---|
NEXT_PUBLIC_API_URL |
GraphQL API endpoint | http://localhost:9000/graphql |
NEXT_PUBLIC_GOOGLE_CLIENT_ID |
Google OAuth client ID | 123456.apps.googleusercontent.com |
cd server
pnpm devThe GraphQL server will start at http://localhost:9000/graphql
cd web
pnpm devThe Next.js application will start at http://localhost:3000
- Web App: http://localhost:3000
- GraphQL Playground: http://localhost:9000/graphql
The GraphQL schema is automatically generated based on the resolvers. Access the Apollo Server Sandbox at:
http://localhost:9000/graphql
You can use this interface to:
- Explore the schema
- Write and test queries/mutations
- View documentation
# Get user profile
query GetUser($id: String!) {
user(id: $id) {
id
email
username
bio
avatar
}
}
# Get feed posts
query GetFeed {
feed {
id
title
content
imageUrl
author {
id
username
}
comments {
id
content
}
}
}# Create a post
mutation CreatePost($input: CreatePostInput!) {
createPost(input: $input) {
id
title
content
}
}
# Follow a user
mutation FollowUser($userId: String!) {
followUser(userId: $userId) {
id
following {
id
}
}
}cd server
# Development mode with auto-reload
pnpm dev
# Build for production
pnpm build
# Start production server
pnpm start
# Run database migrations
pnpm migrate
# Generate Prisma Client
pnpm generatecd web
# Development mode with hot reload and code generation
pnpm dev
# Build for production
pnpm build
# Start production server
pnpm start
# Run linter
pnpm lint
# Generate GraphQL types
pnpm codegen# Windows
netstat -ano | findstr :9000
taskkill /PID <PID> /F
# macOS/Linux
lsof -i :9000
kill -9 <PID>- Ensure PostgreSQL is running:
sudo service postgresql status - Check connection string in
.env - Reset database:
pnpm migrate reset(development only)
- Ensure Redis is running:
redis-cli ping - Check Redis URL in
.env - Default URL should be
redis://localhost:6379
cd web
pnpm codegencd server
pnpm migrate reset --forcecd server
pnpm build
pnpm startcd web
pnpm build
pnpm startBuild and run the entire stack:
docker-compose up --build- Push code to GitHub
- Connect repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy
- Connect GitHub repository
- Set environment variables
- Deploy and get production URL
- Update
NEXT_PUBLIC_API_URLin frontend
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Abhinay Jangde
- Email: abhinayjangde@gmail.com
Happy Coding! 🚀