A robust backend API for a social platform with features for content sharing, user interactions, and moderation.
To run this project, follow these steps:
-
Install Go: Follow the instructions here to install Go on your laptop.
-
Install sqlc and goose:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest go install github.com/pressly/goose/v3/cmd/goose@latest
For more information, refer to the documentation:
-
Run database migrations:
cd sql/schema goose postgres "postgresql://username:password@databasename?sslmode=require" up
-
Generate SQL code:
cd ../.. sqlc generate -
Create
sqlc.yaml:version: "2" sql: - schema: "sql/schema" queries: "sql/queries" engine: "postgresql" gen: go: out: "pkg/database"
-
Build and run the project:
go build && ./expertly-backend -
Set environment variables: Create a
.envfile with the following content:PORT= DB_URL= SECRET_KEY= CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET=
- User registration and login
- JWT-based authentication
- Middleware for protected routes
- Create, read, update, and delete posts
- Get posts by user
- Get post details
- Feed generation
- Create, update, and delete comments
- Nested comments support (replies to comments)
- Get all comments for a post
- Upvote/downvote posts
- Follow/unfollow users
- Save posts for later viewing
- View user profiles
- Update profile information
- View user's posts
- Report users and contributors
- Admin login and moderator creation
- Review and update report status
- Create appeals for reported content
- Review and update appeal status
- View appeals by type (user or contributor)
- Apply to become a contributor
- Review and update application status
- Search for posts
- Search for users
POST /v1/auth/register- Register a new userPOST /v1/auth/login- Login a user
POST /v1/posts- Create a new postGET /v1/posts/{id}- Get post detailsGET /v1/users/{id}/posts- Get posts by userGET /v1/feed- Get feed posts
POST /v1/posts/{id}/comments- Create a commentPUT /v1/comments/{id}- Update a commentDELETE /v1/comments/{id}- Delete a commentGET /v1/posts/{id}/comments- Get all comments for a post
POST /v1/posts/{id}/upvote- Upvote a postDELETE /v1/posts/{id}/upvote- Remove upvotePOST /v1/users/{id}/follow- Follow a userDELETE /v1/users/{id}/follow- Unfollow a userPOST /v1/posts/{id}/save- Save a postDELETE /v1/posts/{id}/save- Unsave a postGET /v1/users/{id}/saved- Get saved posts
GET /v1/users/{id}- Get user profilePUT /v1/users/{id}- Update user profile
POST /v1/admin/login- Admin loginPOST /v1/admin/moderators- Create a moderatorGET /v1/admin/moderators- Get all moderators
POST /v1/reports- Create a reportGET /v1/reports/contributors- Get reported contributorsGET /v1/reports/users- Get reported usersPUT /v1/reports/{id}- Update report status
POST /v1/appeals- Create an appealGET /v1/appeals- Get all appealsGET /v1/appeals/contributors- Get contributor appealsGET /v1/appeals/users- Get user appealsGET /v1/appeals/{id}- Get appeal by IDPUT /v1/appeals/{id}- Update appeal status
POST /v1/contributor-applications- Apply to be a contributorGET /v1/contributor-applications- Get all applicationsGET /v1/contributor-applications/{id}- Get application by IDPUT /v1/contributor-applications/{id}- Update application status
GET /v1/search/posts- Search postsGET /v1/search/users- Search users
- Language: Go
- Database: PostgreSQL
- ORM: sqlc for type-safe SQL
- Migration: goose for database migrations
- Router: chi for HTTP routing
- Authentication: JWT for secure authentication
- File Storage: Cloudinary for media storage
- JWT-based authentication
- Protected routes with middleware
- Environment variables for sensitive information
- Database connection security with SSL