A Facebook-style social network. It's split into two parts: a Go backend (REST API + WebSockets) and a Next.js frontend, with SQLite for storage. You can follow people, keep your profile public or private, write posts with different privacy levels, comment and like, create groups with events, chat in real time (private and group), and get live notifications.
- Auth – register and log in. Sessions are kept in a cookie, and there's a "remember me" option.
- Profiles – public or private, with an avatar, cover photo and bio. You can edit your profile and change your password.
- Followers – follow and unfollow people. Private accounts get a follow request they can accept or decline. There's also a small "who to follow" list.
- Posts – text with an optional image. Each post has one of three privacy levels:
public– anyone can see italmost_private– only your accepted followersprivate– only the specific people you pick
- Comments and likes on posts.
- Groups – create a group, invite people or let them request to join, post inside the group, and create events people can say "going" / "not going" to.
- Chat – real-time private and group messages over WebSockets. Supports images, emojis, message requests, and shows who's online.
- Notifications – for follow requests, group invites, join requests, events, and so on.
| Layer | What we used |
|---|---|
| Backend | Go 1.25, standard library net/http (with the Go 1.22 method+path routing) |
| Database | SQLite (mattn/go-sqlite3), migrations with golang-migrate |
| Realtime | WebSockets (gorilla/websocket) |
| Auth | Session cookies, passwords hashed with bcrypt (golang.org/x/crypto) |
| Frontend | Next.js 16 / React 19 / TypeScript |
social-network/
├── docker-compose.yml # runs backend + frontend together
├── run.sh # shortcut for docker compose up --build
├── backend/
│ ├── server.go # entry point, wires up all the routes
│ ├── go.mod
│ └── pkg/
│ ├── auth/ # password hashing, session/auth middleware
│ ├── chat/ # websocket hub
│ ├── db/
│ │ ├── migrations/ # the SQL migration files
│ │ ├── seed/ # demo data added on first run
│ │ └── sqlite/ # opening the db + running migrations
│ ├── handlers/ # http handlers (auth, posts, groups, chat...)
│ ├── middleware/ # CORS
│ └── models/ # db queries + rules like CanViewPost
└── frontend/
└── src/
├── app/ # next.js routes (login, feed, chat, groups...)
├── components/ # shared UI
├── services/ # talks to the backend on :8080
├── lib/ # small helpers (toast, time, lightbox)
└── types/
We're using SQLite, and the schema is built from migration files instead of by hand. That means you don't have to set anything up: the tables get created for you the first time the server runs.
When the backend starts, server.go does three things in this order:
- Opens the SQLite file (
sqlite.Open). We connect with?_foreign_keys=onbecause SQLite ignores foreign keys by default, and we rely onON DELETE CASCADEto clean up related rows. - Runs any migrations that haven't run yet (
sqlite.Migrate, which callsgolang-migrate'sm.Up()). It keeps track of the current version in aschema_migrationstable, so running it again does nothing. That's why it's safe to run on every startup. - Seeds some demo data, but only if the
userstable is empty.
So on a fresh clone you just run go run . (or docker compose up) and it creates social.db, runs migrations 1 through 15, and fills in the demo users.
They live in backend/pkg/db/migrations/sqlite/. Every change is a pair of files, one to apply it and one to undo it:
000001_create_users.up.sql # creates the table / index / trigger
000001_create_users.down.sql # drops it again
000002_create_sessions.up.sql
000002_create_sessions.down.sql
...
000015_create_post_likes.up.sql
000015_create_post_likes.down.sql
The number at the front is the version. golang-migrate only runs the files that are newer than what's already been applied. The .up.sql file moves the schema forward and the .down.sql is the reverse, in case you need to roll back.
One rule we stuck to: don't edit a migration once it's been applied. If we need to change something we add a new, higher-numbered migration instead, otherwise different machines end up with different schemas.
- Make the next pair of files, e.g.
000016_add_bookmarks.up.sqland000016_add_bookmarks.down.sql. - Write the change in the
.up.sqland the undo (aDROP, usually) in the.down.sql. - Restart the backend and it picks it up automatically.
erDiagram
users {
int id PK
string email UK
string password_hash
string first_name
string last_name
date date_of_birth
string nickname
string about_me
string avatar
string cover_photo
bool is_public
bool show_dob
bool allow_message_requests
datetime created_at
}
sessions {
string id PK
int user_id FK
datetime expires_at
}
followers {
int id PK
int follower_id FK
int followee_id FK
string status
}
groups {
int id PK
int creator_id FK
string title
string description
string image
}
group_members {
int id PK
int group_id FK
int user_id FK
int invited_by FK
string role
string status
}
posts {
int id PK
int user_id FK
int group_id FK
string content
string image
string privacy
}
post_viewers {
int post_id PK
int user_id PK
}
post_likes {
int post_id PK
int user_id PK
}
comments {
int id PK
int post_id FK
int user_id FK
string content
string image
}
events {
int id PK
int group_id FK
int creator_id FK
string title
string description
datetime event_time
}
event_responses {
int id PK
int event_id FK
int user_id FK
string response
}
messages {
int id PK
int sender_id FK
int receiver_id FK
int group_id FK
string content
string image
bool is_read
}
message_reads {
int message_id PK
int user_id PK
datetime read_at
}
chat_requests {
int id PK
int from_user_id FK
int to_user_id FK
string status
}
notifications {
int id PK
int user_id FK
string type
int reference_id
int actor_id FK
bool is_read
}
users ||--o{ sessions : "has"
users ||--o{ followers : "follower / followee"
users ||--o{ groups : "creates"
groups ||--o{ group_members : "has"
users ||--o{ group_members : "joins"
users ||--o{ posts : "writes"
groups ||--o{ posts : "contains"
posts ||--o{ comments : "has"
users ||--o{ comments : "writes"
posts ||--o{ post_viewers : "restricted to"
users ||--o{ post_viewers : "can view"
posts ||--o{ post_likes : "receives"
users ||--o{ post_likes : "gives"
groups ||--o{ events : "hosts"
users ||--o{ events : "creates"
events ||--o{ event_responses : "gets"
users ||--o{ event_responses : "answers"
users ||--o{ messages : "sends"
groups ||--o{ messages : "channels"
messages ||--o{ message_reads : "tracked by"
users ||--o{ chat_requests : "sends / receives"
users ||--o{ notifications : "receives"
| Table | What it's for | Main columns |
|---|---|---|
users |
Accounts and profile info | email (unique), password_hash, is_public |
sessions |
Login sessions (cookie to user) | id (the cookie value), user_id, expires_at |
followers |
Who follows who, plus pending requests | follower_id, followee_id, status |
groups |
Groups | creator_id, title, description |
group_members |
Membership, invites and join requests | group_id, user_id, role, status |
posts |
User and group posts | user_id, group_id, privacy |
post_viewers |
The chosen viewers for a private post |
post_id, user_id |
post_likes |
Likes | post_id, user_id |
comments |
Comments on posts | post_id, user_id |
events |
Group events | group_id, creator_id, event_time |
event_responses |
Going / not going | event_id, user_id, response |
messages |
Private and group chat messages | sender_id, receiver_id, group_id |
message_reads |
Read receipts for group messages | message_id, user_id |
chat_requests |
Message requests between people who don't follow each other | from_user_id, to_user_id, status |
notifications |
In-app notifications | user_id, type, reference_id, actor_id |
This was a group project, so we split the work between us and worked through it roughly in this order:
- Read the requirements together and made a list of the features (auth, followers, profiles, posts with the three privacy levels, groups, events, chat, notifications) and the rules tying them together, like figuring out who's allowed to see a given post.
- Designed the database first. We sketched out the tables and how they relate before writing much code (that's the ER diagram above). The many-to-many stuff, like which users can see a private post or who's in a group, goes into join tables such as
post_viewers,post_likes,group_membersandevent_responses. We also usedCHECKconstraints so things like post privacy and follow status can only hold valid values. - Wrote the migrations so the schema is repeatable and nobody has to remember any manual setup. Foreign keys with
ON DELETE CASCADEhandle cleanup. - Built the backend in layers.
server.gojust maps routes to handlers. The handlers inpkg/handlersdeal with the request and response, andpkg/modelsholds the actual SQL and the rules (things likeCanViewPostandChatPermission). Auth is aRequireAuthmiddleware that checks the session cookie. - Added the real-time part. There's a WebSocket hub in
pkg/chatthat pushes chat messages and notifications out to connected clients. - Did the frontend in Next.js. Components don't call the backend directly, they go through a
services/layer, which kept things tidier. - Containerized it with a Dockerfile each for the backend and frontend, plus
docker-compose.ymlso everything comes up with one command. - Tested as we went with Postman for the API and by clicking through the running app.
You need Docker with Compose.
./run.shor just:
docker compose up --build -dThen open:
- Frontend: http://localhost:3000
- Backend: http://localhost:8080
Handy commands:
docker compose logs -f # watch the logs
docker compose down # stop everythingThe database and uploaded files are kept on your machine through the backend/data and backend/uploads volumes.
You'll need Go 1.25+ and Node 20+. The backend uses go-sqlite3, which is cgo, so you also need a C compiler (gcc, or MinGW on Windows) and CGO_ENABLED=1.
First, the backend. Run it from inside backend/, since it looks for the migrations relative to that folder:
cd backend
go run .It listens on http://localhost:8080. The first run creates social.db, applies the migrations and seeds the demo data.
Then the frontend, in another terminal:
cd frontend
npm install --legacy-peer-deps
npm run devThat runs on http://localhost:3000 and points at the backend on :8080 (set in frontend/src/services/api.ts).
The first run seeds a few users you can log in with:
| Password | |
|---|---|
layla@test.com |
password123 |
omar@test.com |
password123 |
karim@test.com |
password123 |
They all use password123. There are a few more (fatima@test.com, ahmed@test.com, maya@test.com and others, all in backend/pkg/db/seed/seed.go). Or just register a new account from the Register page.
Everything is under /api, and apart from register/login/logout it needs a valid session cookie. Some of the main ones:
| Method & path | What it does |
|---|---|
POST /api/register |
make an account |
POST /api/login / logout |
log in / out |
GET /api/me |
the current user |
GET /api/posts / POST /api/posts |
feed / create a post |
POST /api/posts/{id}/comments |
comment on a post |
POST /api/posts/{id}/like |
like a post |
GET /api/groups / POST /api/groups |
list / create groups |
POST /api/groups/{id}/events |
create a group event |
GET /api/notifications |
list notifications |
GET /api/chat |
chat list |
GET /ws |
the websocket |
POST /api/upload |
upload an image |
GET /health |
health check |
The full list is in backend/server.go.
If you want to hit the backend directly:
- Register –
POST http://localhost:8080/api/registerwith a JSON body. You needemail,password(at least 6 chars),first_name,last_nameanddate_of_birth(YYYY-MM-DD).nickname,about_meandis_publicare optional:To register with an avatar, send the same fields as{ "email": "newuser@test.com", "password": "password123", "first_name": "New", "last_name": "User", "date_of_birth": "1998-05-20", "nickname": "newbie", "about_me": "Hello!", "is_public": true }multipart/form-datawith anavatarfile part instead of JSON. - Log in –
POST http://localhost:8080/api/login:Turn on "Send cookies" so Postman keeps the session cookie.{ "email": "layla@test.com", "password": "password123" } - Call the authenticated endpoints – like
GET http://localhost:8080/api/meorGET http://localhost:8080/api/posts. The cookie from logging in goes along automatically. - Create a post –
POST http://localhost:8080/api/postswithcontentandprivacy(public,almost_privateorprivate).
- The
*.dbfile and uploaded images are runtime stuff, so they're git-ignored. The demo seed images are kept though, so a fresh clone still has working avatars and covers. - The backend gets its database path from the
DB_PATHenv var. It defaults to./social.db, and Docker sets it to/app/data/social.db.