Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Server Configuration
PORT=8080

# Database Configuration (Supabase PostgreSQL)
DATABASE_URL=postgres://postgres:[YOUR_PASSWORD]@db.xkzadsnvjdrspymgcoaq.supabase.co:5432/postgres

# Admin Credentials
ADMIN_EMAIL=admin@infolinks.app
ADMIN_PASSWORD=change-this-immediately

# Security
JWT_SECRET=generate-a-secure-random-string-here
CORS_ALLOWED_ORIGINS=http://localhost:8080,http://localhost:5173
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
pull_request:

jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Test
run: go test ./...

frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install
run: npm ci
- name: Syntax check
run: node --check js/admin.js && node --check js/home.js && node --check js/ui.js && node --check main.js
- name: Build
run: npm run build
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# OS files
.DS_Store

# Build/Environment
.env
node_modules/
dist/

# Go
cmd/server/server
bin/
*.exe
*.test
vendor/

.cursor
1 change: 0 additions & 1 deletion CNAME

This file was deleted.

29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ Each link can display one or more content type badges:
## 🛠️ Tech Stack

- **Frontend:** HTML5, CSS3, JavaScript (Vanilla)
- **Backend:** Go (Golang) — A high-performance REST API and static file server
- **Styling:** Modern, custom CSS with theme support (light/dark) and responsive design
- **Backend Database:** Supabase (PostgreSQL) with Row Level Security
- **Authentication:** Supabase Auth (email/password)
- **Deployment:** GitHub Pages + Supabase
- **Authentication:** JWT-based admin authentication via backend API
- **Deployment:** Render (Go Web Service) + Supabase
- **PWA:** Service Worker for offline support
- **Version Control:** Git & GitHub

Expand All @@ -99,24 +100,33 @@ Each link can display one or more content type badges:
### Prerequisites
- A modern web browser
- Git (for cloning the repository)
- Supabase account (if self-hosting the backend)
- Go (Golang) installed on your system
- Supabase account (if self-hosting the database)

### Installation
### Installation & Running Locally

1. **Clone the repository**
```bash
git clone https://github.com/MohamadObeid9/Info_Links.git
cd Info_Links
```

2. **Open in browser**
2. **Configure Environment**
- Copy `.env.example` to `.env`
- Set your `DATABASE_URL` to your Supabase Postgres connection string.

3. **Run the Full Stack**
```bash
# Simply open index.html in your browser
# Or use a local server
python -m http.server 8000
# Then visit http://localhost:8000
go run cmd/server/main.go
```
- The Go server will start the API and serve the frontend files natively.
- Open your browser to `http://localhost:8080`

### Deployment (Render)
InfoLinks is configured to be deployed as a single Web Service on Render.
- **Build Command:** `go build -o server cmd/server/main.go`
- **Start Command:** `./server`
- Don't forget to set your `DATABASE_URL` environment variable!

---

Expand Down Expand Up @@ -206,6 +216,7 @@ This project is **open source** and available under the MIT License. See the [LI
| **Phase 5** | Launched new website for better UX |
| **Phase 6** | Open-sourced project for community contributions |
| **Phase 7** | Added favorites, content types, analytics, and PWA support |
| **Phase 8** | Fully migrated to a high-performance Go backend with native static serving |

---

Expand Down
62 changes: 0 additions & 62 deletions app.js

This file was deleted.

42 changes: 42 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"log"
"net/http"
"os"

"infolinks-backend/internal/api"
"infolinks-backend/internal/database"

"github.com/joho/godotenv"
)

func main() {
// Load environment variables
if err := godotenv.Load(); err != nil {
log.Println("Note: No .env file found, using system environment variables")
}

// Initialize database
database.InitDB()
defer database.DB.Close()

if err := api.SetJWTSecret(os.Getenv("JWT_SECRET")); err != nil {
log.Fatal("failed to configure JWT secret: ", err)
}

// Setup router
handler := api.NewRouter()

// Start server
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}

log.Printf("🚀 Backend server is starting on port %s...", port)
err := http.ListenAndServe(":"+port, handler)
if err != nil {
log.Fatal("Server failed to start:", err)
}
}
60 changes: 60 additions & 0 deletions docs/baseline-snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Baseline Snapshot

## Environment

- Date: 2026-04-21
- Backend command: `go test ./...`
- Frontend command: `npm run build` (not executable in current environment: `npm` missing)

## Backend Baseline

- `go test ./...` currently fails in `internal/api` because tests require live database connectivity.
- Failure mode: DNS/network resolution to Supabase host while running test suite.
- Current tests are integration-coupled via `TestMain -> database.InitDB()`.

## Frontend Baseline

- Build tool not runnable locally in this session due to missing Node/NPM binary.
- Static code audit confirms syntax/runtime risks in several JS modules and mixed module strategy.

## Endpoint Inventory

### Public

- `GET /api`
- `GET /api/`
- `GET /api/content`
- `GET /api/health`
- `POST /api/auth/login`
- `POST /api/page_views`
- `POST /api/link_clicks`
- `POST /api/reports`
- `POST /api/contributions`
- `POST /api/feedback`

### Admin

- `GET /api/admin/reports`
- `PATCH /api/admin/reports/{id}`
- `DELETE /api/admin/reports/{id}`
- `GET /api/admin/feedback`
- `PATCH /api/admin/feedback/{id}`
- `DELETE /api/admin/feedback/{id}`
- `GET /api/admin/contributions`
- `PATCH /api/admin/contributions/{id}`
- `DELETE /api/admin/contributions/{id}`
- `POST /api/admin/courses`
- `PATCH /api/admin/courses/{id}`
- `DELETE /api/admin/courses/{id}`
- `POST /api/admin/links`
- `PATCH /api/admin/links/{id}`
- `DELETE /api/admin/links/{id}`
- `GET /api/admin/page_views`
- `GET /api/admin/link_clicks`

## Immediate Priorities

1. Restore frontend runtime integrity and module consistency.
2. Fix auth correctness and API validation safeguards.
3. Align build output, static serving, and PWA assets.
4. Decouple tests from hard DB dependency and add CI quality gates.
19 changes: 19 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# InfoLinks Frontend

This directory contains the user interface for InfoLinks, built with plain HTML, CSS, and Vanilla JavaScript.

## Structure
- `index.html`: The main entry point of the application.
- `main.js`: Frontend event wiring and app bootstrap.
- `js/`: Contains feature logic modules (`views.js`, `data.js`, etc.).
- `styles/`: Contains all CSS files for styling the application.
- `assets/`: Contains images, icons, and static assets.

## Deployment & Running
The frontend is designed to be served statically by the Go backend. All API requests are made using relative paths (`/api/...`).

To run the frontend during development, start the Go backend from the repository root:
```bash
go run cmd/server/main.go
```
Then visit `http://localhost:8080/` in your browser.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
Loading
Loading