Skip to content

aliBenhenia/OneCard-Morocco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

oneCard - Digital Cards Store Platform

MERN Stack Next.js Docker Scalable

oneCard is a high-performance digital cards marketplace built with modern web technologies. This platform enables users to create, buy, and manage digital business cards with a focus on scalability, maintainability, and developer experience.

🌟 Key Features

  • MVC Architecture - Clean separation of concerns in backend
  • Next.js 14 - App Router, Server Components, and ISR
  • Scalable Infrastructure - Docker Compose ready for production
  • Responsive Design - Mobile-first UI with Tailwind CSS

πŸ“‚ Project Structure

Backend (MVC Architecture)

backend/
β”œβ”€β”€ config/             # Environment configs & DB connection
β”œβ”€β”€ controllers/        # Business logic (MVC Controllers)
β”œβ”€β”€ models/             # Data schemas (MVC Models)
β”œβ”€β”€ routes/             # API endpoints (MVC Routes)
β”œβ”€β”€ services/           # Reusable business logic (for scaling)
β”œβ”€β”€ utils/              # Helpers, middleware, error handlers
β”œβ”€β”€ validations/        # Request validation schemas
└── server.js           # Entry point

Frontend (Next.js 14 App Router)

frontend/
β”œβ”€β”€ app/                # Next.js App Router structure
β”‚   β”œβ”€β”€ (auth)/         # Authentication routes
β”‚   β”œβ”€β”€ api/            # Server-side API routes
β”‚   β”œβ”€β”€ cards/          # Card management routes
β”‚   β”œβ”€β”€ dashboard/      # User dashboard
β”‚   β”œβ”€β”€ layout.tsx      # Root layout
β”‚   └── page.tsx        # Home page
β”œβ”€β”€ components/         # Reusable UI components
β”œβ”€β”€ lib/                # Shared logic (API clients, utils)
β”œβ”€β”€ public/             # Static assets
β”œβ”€β”€ styles/             # Global styles
└── next.config.js      # Next.js configuration

πŸš€ Getting Started

Prerequisites

  • Node.js v18+
  • MongoDB (local or cloud instance)
  • Docker (optional for containerized setup)

Installation

1. Clone the repository

git clone https://github.com/aliBenhenia/OneCard-Morocco
cd OneCard-Morocco

2. Install dependencies

Frontend (Next.js):

cd frontend
npm install -f  # Force install to handle potential peer dependency issues
npm run dev

Backend (Express):

cd ../backend
npm install
npm install -g nodemon  # Global installation for development
nodemon src/server.js

Frontend runs at: http://localhost:3000
Backend API runs at: http://localhost:3001

4. Alternative: Docker Compose Setup

docker-compose up --build

This will:

  • Build and run frontend container (port 3000)
  • Build and run backend container (port 3001)

πŸ”¬ Architecture Deep Dive

MVC Pattern Implementation

graph LR
    A[Client Request] --> B[Routes]
    B --> C[Controllers]
    C --> D[Services]
    D --> E[Models]
    E --> F[MongoDB]
    F --> E
    E --> D
    D --> C
    C --> B
    B --> A
Loading
  1. Routes: Define API endpoints (/api/cards, /api/users)
  2. Controllers: Handle request/response logic
  3. Services: Reusable business logic (decoupled from HTTP)
  4. Models: Data schemas and database operations

Why This Structure Scales

  • Service Layer: Critical for microservices transition later
  • Validation Separation: Dedicated validation layer prevents controller bloat
  • Middleware Pipeline: Custom middleware for auth, logging, errors
  • Next.js App Router: Built-in caching, data fetching, and route handlers

Composed Infrastructure Design

graph TB
    A[Client] --> B[Nginx Load Balancer]
    B --> C[Frontend Cluster]
    B --> D[Backend Cluster]
    D --> E[Redis Cache]
    D --> F[MongoDB Cluster]
    D --> G[Payment Service]
    D --> H[Notification Service]
Loading

For future scaling:

  1. Frontend: CDN + Static Export (Next.js)
  2. Backend: Kubernetes pods with auto-scaling
  3. Database: MongoDB Atlas sharding
  4. Caching: Redis for session and query caching
  5. Async Processing: RabbitMQ for background jobs

πŸ“ˆ Scaling Strategy

Phase 1: Monolith (Current)

  • Single Express server
  • Next.js frontend
  • MongoDB replica set

Phase 2: Service Decomposition

  1. Extract User Service
  2. Create Card Processing Service
  3. Implement Notification Service
  4. Separate Payment Gateway

Phase 3: Cloud-Native Deployment

  • Frontend: Vercel/Netlify (SSG)
  • Backend: AWS ECS/Fargate
  • Database: MongoDB Atlas
  • Infrastructure: Terraform-managed

πŸ›  Development Workflow

Frontend Commands

npm run dev       # Start dev server
npm run build     # Create production build
npm run lint      # Run linter

Backend Commands

npm start         # Production start
npm run dev       # Dev mode with nodemon
npm test          # Run tests

Docker Commands

docker-compose up      # Start full stack
docker-compose down    # Stop containers
docker-compose logs -f # Follow logs

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“œ License

Distributed under MIT License. See LICENSE for more information.


Pro Tip: For production deployment, always use docker-compose -f docker-compose.prod.yml up -d with production-optimized configuration. The development setup includes hot-reloading and debugging tools not suitable for production.

oneCard - Where digital connections begin ✨

About

Full clone of OneCard with Moroccan localization (payments...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published