# brij5/mocktestbuddy architecture

> Architecture diagram of the GitHub repository brij5/mocktestbuddy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brij5/mocktestbuddy
- Repository: https://github.com/brij5/mocktestbuddy

## Overview

##### Project Type and Purpose
- Exam Buddy is a full-stack, containerized mock-test platform with two user-facing clients (a web app built in React/Vite and a mobile app in React Native/Expo), a Node.js/Express backend, and a MongoDB database.
- It supports role-based access (Admin/User), JWT authentication, exam/question management, and progress tracking.

##### File Structure
- Top-level directories:
- client/ → React/Vite web frontend
- server/ → Node.js/Express REST API
- docker/ → Nginx configs for production reverse-proxy
- docker-compose.dev.yml & docker-compose.prod.yml → multi-container orchestration
- docs/ → design, deployment, API docs
- assets/ & eas.json → React Native mobile app (Expo)
- client/src → components, pages, store (Redux), services (API layer), hooks, layouts
- server → layered backend: config, controllers, services (business logic), models (Mongoose schemas), routes, middleware, utils, validations, scripts, tests

##### Key Architectural Insights from README
- Clients consume REST endpoints over HTTP/S.
- Server issues and validates JWT tokens for auth, performs role checks in middleware.
- MongoDB accessed via Mongoose.
- Production deploy uses Docker images and Nginx as reverse proxy.
- Development uses Docker Compose with hot-reload.

##### Main Components
a. Clients
- Web App (React/Vite)
- Mobile App (Expo/React Native)
b. Edge/Proxy
- Nginx (production only)
c. Backend API
- Express App with layered structure (routes → controllers → services → models)
- Middleware (auth, validation, error handling)
d. Data Layer
- MongoDB database
e. External Services
- Email Service (SMTP or 3rd-party provider)

##### Relationships and Data Flows
- Users → (HTTPS) → Nginx → Web App static assets or → API endpoints
- Mobile App → (HTTPS) → API endpoints
- Web App & Mobile App → send credentials → API → AuthController → AuthService → JWT → Client
- Authenticated clients → call protected API routes → Controllers → Services → Models → MongoDB
- Backend uses emailService util to send transactional emails
- Docker Compose network: frontend, backend, mongo on same virtual network in dev

##### Architectural Patterns & Design Principles
- Layered architecture on server (separation of concerns: routing, business logic, data access)
- Client-side state management (Redux slices) and React Context/hooks
- Containerization (Docker) and infrastructure as code (Compose files)
- Environment-specific configuration (dev vs. prod .env files)
- Modular code organization (feature directories, reusable components, validation schemas)

- Clear, self-descriptive labels for each component and port numbers

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Production Environment"
        direction TB
        WebApp["Web App (React/Vite)"]:::clients
        MobileApp["Mobile App (Expo)"]:::clients
        Nginx["Nginx Reverse Proxy"]:::proxy
        API["Express API"]:::api
        MongoDB["MongoDB"]:::db
        EmailSvc["Email Service"]:::external

        WebApp -->|HTTPS + JWT| Nginx
        MobileApp -->|HTTPS + JWT| Nginx
        Nginx -->|Proxy to Static Assets| WebApp
        Nginx -->|HTTPS + JWT| API
        API -->|Mongoose Driver| MongoDB
        API -->|SMTP Calls| EmailSvc
    end

    subgraph "Development Environment"
        direction TB
        DevWeb["Web App (React/Vite)"]:::clients
        DevMobile["Mobile App (Expo)"]:::clients
        DevAPI["Express API"]:::api
        DevMongo["MongoDB"]:::db

        DevWeb -->|HTTP + JWT| DevAPI
        DevMobile -->|HTTP + JWT| DevAPI
        DevAPI -->|Mongoose Driver| DevMongo
    end

    %% Click Events
    click WebApp "https://github.com/brij5/mocktestbuddy/tree/main/client/"
    click WebApp "https://github.com/brij5/mocktestbuddy/blob/main/client/package.json"
    click WebApp "https://github.com/brij5/mocktestbuddy/tree/main/client/Dockerfile"
    click WebApp "https://github.com/brij5/mocktestbuddy/blob/main/client/src/App.jsx"
    click WebApp "https://github.com/brij5/mocktestbuddy/blob/main/client/src/main.jsx"
    click MobileApp "https://github.com/brij5/mocktestbuddy/tree/main/assets/"
    click MobileApp "https://github.com/brij5/mocktestbuddy/blob/main/eas.json"
    click Nginx "https://github.com/brij5/mocktestbuddy/tree/main/docker/nginx/"
    click Nginx "https://github.com/brij5/mocktestbuddy/blob/main/docker/nginx/nginx.conf"
    click Nginx "https://github.com/brij5/mocktestbuddy/blob/main/docker/nginx/conf.d/default.conf"
    click API "https://github.com/brij5/mocktestbuddy/tree/main/server/"
    click API "https://github.com/brij5/mocktestbuddy/blob/main/server/app.js"
    click API "https://github.com/brij5/mocktestbuddy/blob/main/server/index.js"
    click API "https://github.com/brij5/mocktestbuddy/tree/main/server/Dockerfile"

    %% Styles
    classDef clients fill:#E3F2FD,stroke:#2196F3,stroke-width:2px
    classDef proxy fill:#E8F5E9,stroke:#4CAF50,stroke-width:2px
    classDef api fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px
    classDef db fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px,shape:cylinder
    classDef external fill:#ECEFF1,stroke:#607D8B,stroke-width:2px,stroke-dasharray: 5 5
```
