This is a production-grade backend for the Githouse developer social platform, fully integrated with the React frontend.
- Framework: Express.js (Node.js)
- Language: TypeScript
- Database: PostgreSQL
- Authentication: JWT (JSON Web Tokens)
- Validation: Joi
- Security: bcryptjs, helmet, CORS, rate limiting
- ORM: Raw SQL with pg library (connection pooling)
- State Management: React Context (AuthContext, DataContext)
- API Client: Custom fetch-based client with token management
- Components: Fully integrated with real backend data
backend/
├── src/
│ ├── config/
│ │ └── config.ts # Configuration management
│ ├── database/
│ │ ├── connection.ts # Database connection pool
│ │ ├── migrations.ts # Schema migrations
│ │ └── seed.ts # Database seeding
│ ├── middleware/
│ │ ├── auth.ts # Authentication & authorization
│ │ └── validation.ts # Request validation
│ ├── routes/
│ │ ├── authRoutes.ts # Auth endpoints
│ │ ├── communityRoutes.ts # Community endpoints
│ │ ├── projectRoutes.ts # Project endpoints
│ │ ├── postRoutes.ts # Post/feed endpoints
│ │ └── moderationRoutes.ts # Moderation endpoints
│ ├── services/
│ │ ├── UserService.ts # User business logic
│ │ ├── CommunityService.ts # Community business logic
│ │ ├── ProjectService.ts # Project business logic
│ │ ├── PostService.ts # Post business logic
│ │ └── ModerationService.ts # Moderation business logic
│ ├── types/
│ │ └── index.ts # TypeScript type definitions
│ ├── utils/
│ │ ├── auth.ts # Auth utilities (JWT, password hashing)
│ │ ├── validation.ts # Validation utilities
│ │ └── errors.ts # Error handling
│ └── index.ts # Express app entry point
├── .env # Environment variables
├── package.json
└── tsconfig.json
frontend/
├── src/
│ ├── api/
│ │ └── client.ts # API client for backend communication
│ ├── context/
│ │ ├── AuthContext.tsx # Authentication state
│ │ └── DataContext.tsx # Application data state
│ ├── components/ # React components
│ └── ...
└── .env.local # Frontend env variables
- Node.js 16+ and npm
- PostgreSQL 12+
- Git
-
Navigate to backend directory:
cd backend -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env # Edit .env with your database credentials -
Create PostgreSQL database:
createdb githouse_dev
-
Run migrations:
npm run db:migrate
-
Seed sample data (optional):
npm run db:seed
-
Start the development server:
npm run dev
The backend will start on
http://localhost:5000
-
Navigate to frontend directory:
cd .. -
Install dependencies:
npm install
-
Set up environment variables:
# .env.local should already have: VITE_API_URL=http://localhost:5000/api -
Start the development server:
npm run dev
The frontend will start on
http://localhost:5173
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user profileGET /api/auth/user/:username- Get user by usernamePUT /api/auth/me- Update profile
POST /api/communities- Create communityGET /api/communities- Get all communities (paginated)GET /api/communities/:slug- Get community by slugGET /api/communities/:slug/members- Get community membersPUT /api/communities/:slug- Update community (admin only)POST /api/communities/:slug/join- Join community
POST /api/projects- Create projectGET /api/projects- Get all projects (paginated)GET /api/projects/:slug- Get project by slugPUT /api/projects/:slug- Update project (owner only)
POST /api/posts- Create postGET /api/posts- Get all posts (paginated)GET /api/posts/:postId- Get post by IDPOST /api/posts/:postId/like- Like postDELETE /api/posts/:postId/like- Unlike postPOST /api/posts/:postId/comments- Create commentGET /api/posts/:postId/comments- Get post commentsDELETE /api/posts/:postId/comments/:commentId- Delete comment
POST /api/moderation/reports- Create moderation reportGET /api/moderation/reports- Get all reports (admin only)PUT /api/moderation/reports/:reportId- Update report (admin only)POST /api/moderation/users/:userId/suspend- Suspend user (admin only)POST /api/moderation/users/:userId/unsuspend- Unsuspend user (admin only)
- users - User accounts with authentication
- communities - Developer communities
- community_members - Community membership tracking
- projects - Development projects
- project_contributors - Project contributor tracking
- posts - Feed posts and discussions
- comments - Post comments
- post_likes - Like tracking
- user_follows - User following relationships
- moderation_reports - Moderation reports
- activity_logs - Activity audit trail
- Registration/Login: User provides credentials → Backend validates → JWT token issued
- Token Storage: Frontend stores token in localStorage
- API Requests: Frontend includes token in Authorization header (
Bearer <token>) - Token Validation: Backend validates token on protected routes
- Token Refresh: Refresh tokens can be used to get new access tokens
NODE_ENV=development
PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_NAME=githouse_dev
DB_USER=postgres
DB_PASSWORD=your_password
JWT_SECRET=your_jwt_secret
CORS_ORIGIN=http://localhost:5173
VITE_API_URL=http://localhost:5000/api
npm run dev # Start dev server with auto-reload
npm run build # Build TypeScript to JavaScript
npm run start # Run compiled code
npm run db:migrate # Run database migrations
npm run db:seed # Seed sample data
npm run lint # Run ESLint
npm run test # Run testsnpm run dev # Start Vite dev server
npm run build # Build for production
npm run preview # Preview production build- Build the project:
npm run build - Set production environment variables
- Run migrations:
npm run db:migrate - Start server:
npm run start - Use a process manager like PM2
- Build the project:
npm run build - Deploy the
distfolder to your hosting service - Configure environment variables for production API URL
- ✅ User registration with validation
- ✅ Secure login with JWT
- ✅ Profile management
- ✅ User statistics (followers, following, etc.)
- ✅ User follows system
- ✅ Create and manage communities
- ✅ Community membership
- ✅ Member roles and permissions
- ✅ Community discovery
- ✅ Project creation and management
- ✅ Project contributors
- ✅ Project linking to communities
- ✅ Project statistics
- ✅ Post creation and management
- ✅ Comment system
- ✅ Like/unlike posts
- ✅ Activity feed
- ✅ Report creation
- ✅ Report management (admin)
- ✅ User suspension
- ✅ Content moderation
- ✅ Password hashing with bcrypt
- ✅ JWT-based authentication
- ✅ CORS protection
- ✅ Rate limiting
- ✅ Helmet security headers
- ✅ Input validation with Joi
- Connection pooling for database
- Indexed database queries
- Pagination support
- Error handling and logging
- Efficient TypeScript compilation
All API responses follow a consistent format:
{
"success": true/false,
"message": "Description",
"data": {} // Optional, only on success
}- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT
For issues and questions, please create an issue in the repository.