Skip to content

Gigman2/loud-am

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

The Gigmen - Where gig workers rant

A full-stack content publishing platform built with Node.js, MongoDB, Google Cloud Functions, and Next.js. Demonstrates microservices architecture, RESTful API design, and modern web development practices.

πŸ›  Tech Stack

Backend:

  • Node.js + Express
  • MongoDB (Mongoose)
  • JWT Authentication
  • REST APIs

Serverless:

  • Google Cloud Functions
  • Analytics microservice

Frontend:

  • Next.js 14 (App Router)
  • TypeScript
  • Tailwind CSS
  • Server-Side Rendering (SSR)

πŸ“ Project Structure

the-gigmen/
β”œβ”€β”€ backend/                 # Express API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ models/         # MongoDB schemas
β”‚   β”‚   β”œβ”€β”€ routes/         # API endpoints
β”‚   β”‚   β”œβ”€β”€ middleware/     # Auth middleware
β”‚   β”‚   β”œβ”€β”€ config/         # Database config
β”‚   β”‚   └── index.js        # Server entry
β”‚   └── .env
β”œβ”€β”€ cloud-functions/         # GCP Functions
β”‚   └── article-analytics/
β”‚       └── index.js
└── frontend/                # Next.js app
    β”œβ”€β”€ app/                # App router pages
    β”œβ”€β”€ lib/                # API client
    └── .env.local

πŸš€ Quick Start

1. MongoDB Setup

  1. Go to MongoDB Atlas
  2. Create free cluster
  3. Get connection string
  4. Whitelist your IP (0.0.0.0/0 for development)

2. Backend Setup

cd backend

# Install dependencies
npm install

# Create .env file
cat > .env << EOL
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/gigmen
JWT_SECRET=your_super_secret_key_change_this_in_production
PORT=5000
NODE_ENV=development
EOL

# Start development server
npm run dev

Test the API:

# Health check
curl http://localhost:5000/health

# Register user
curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "password": "password123",
    "bio": "Test user bio"
  }'

# Create article (use token from register)
curl -X POST http://localhost:5000/api/articles \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -d '{
    "title": "My First Article",
    "content": "This is my first article content...",
    "tags": ["nodejs", "mongodb"],
    "published": true
  }'

3. Google Cloud Functions Setup

cd cloud-functions/article-analytics

# Install dependencies
npm install

# Install Google Cloud CLI
# https://cloud.google.com/sdk/docs/install

# Login to GCP
gcloud auth login

# Set project
gcloud config set project YOUR_PROJECT_ID

# Deploy function
gcloud functions deploy getArticleAnalytics \
  --runtime nodejs18 \
  --trigger-http \
  --allow-unauthenticated \
  --set-env-vars MONGODB_URI="your_mongodb_connection_string"

# Get function URL
gcloud functions describe getArticleAnalytics

4. Frontend Setup

cd frontend

# Install dependencies
npm install

# Create .env.local
cat > .env.local << EOL
NEXT_PUBLIC_API_URL=http://localhost:5000/api
NEXT_PUBLIC_GCP_ANALYTICS_URL=https://YOUR_GCP_FUNCTION_URL
EOL

# Start development server
npm run dev

Open http://localhost:3000

🎯 Key Features

Backend API

βœ… User authentication with JWT βœ… CRUD operations for articles βœ… MongoDB schemas with indexing βœ… Pagination and search βœ… Role-based access control βœ… Clean middleware architecture βœ… Comprehensive error handling

Google Cloud Function

βœ… Serverless analytics microservice βœ… MongoDB aggregation pipelines βœ… Connection pooling for performance βœ… CORS-enabled endpoints

Next.js Frontend

βœ… Server-Side Rendering (SSR) βœ… Static Site Generation (SSG) βœ… TypeScript for type safety βœ… Responsive design with Tailwind βœ… API client with auth interceptors

πŸ”‘ API Endpoints

Authentication

  • POST /api/auth/register - Create account
  • POST /api/auth/login - Login
  • GET /api/auth/me - Get current user

Articles

  • GET /api/articles - List articles (with pagination)
  • GET /api/articles/:slug - Get single article
  • POST /api/articles - Create article (auth required)
  • PUT /api/articles/:id - Update article (auth required)
  • DELETE /api/articles/:id - Delete article (auth required)
  • GET /api/articles/user/:username - User's articles

Analytics (GCP Function)

  • GET /getArticleAnalytics - Platform analytics

πŸ“Š Database Schema

Users Collection:

{
  username: String,
  email: String,
  password: String (hashed),
  bio: String,
  role: String,
  articlesPublished: Number,
  createdAt: Date,
  updatedAt: Date
}

Articles Collection:

{
  title: String,
  slug: String (auto-generated),
  content: String,
  excerpt: String,
  author: ObjectId (ref: User),
  tags: [String],
  published: Boolean,
  views: Number,
  likes: Number,
  createdAt: Date,
  updatedAt: Date
}

🚒 Deployment

Backend (Render/Railway)

  1. Push code to GitHub
  2. Connect repository to Render/Railway
  3. Add environment variables
  4. Deploy

Frontend (Vercel)

  1. Push code to GitHub
  2. Import repository to Vercel
  3. Add environment variables
  4. Deploy

πŸ§ͺ Testing

# Backend
cd backend
npm test

# Frontend
cd frontend
npm test

πŸŽ“ Learning Outcomes

This project demonstrates:

  • βœ… RESTful API design principles
  • βœ… MongoDB schema modeling and optimization
  • βœ… JWT authentication implementation
  • βœ… Serverless architecture with Google Cloud
  • βœ… Next.js SSR and SSG patterns
  • βœ… TypeScript in full-stack development
  • βœ… Clean code architecture
  • βœ… Modern DevOps practices

πŸ“ What I Learned

Building this project gave me hands-on experience with:

  1. MongoDB: Schema design, aggregation pipelines, indexing strategies
  2. Google Cloud Functions: Serverless deployment, cold start optimization
  3. Next.js: Server-side rendering, static generation, API routes
  4. Authentication: JWT implementation, secure password hashing
  5. API Design: REST best practices, middleware patterns, error handling

πŸ”— Links

  • Live Demo: [Your Vercel URL]
  • API Documentation: [Your Backend URL]/api
  • GitHub: [Your GitHub Repo]

πŸ‘¨β€πŸ’» Author

Eric Kojo Abbey


Built as a portfolio project to demonstrate full-stack development skills with modern technologies relevant to publishing platforms and content management systems.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors