# reyan36/certcat architecture

> Architecture diagram of the GitHub repository reyan36/certcat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/reyan36/certcat
- Repository: https://github.com/reyan36/certcat

## Overview

1. **Overall shape**
   CertCat is a **Next.js App Router** application that combines a public marketing site, a certificate verification experience, an admin console, and a set of server-side API routes for certificate lifecycle operations. The app is split between browser-rendered pages under `app/` and backend handlers under `app/api/`.

2. **User-facing surfaces**
   The main browser entry points are:
   - `app/page.js` for the landing page
   - `app/pricing/page.js` for pricing
   - `app/status/page.js` and `app/verify/[id]/page.js` for public status/verification flows
   - `app/dashboard/page.js` and `app/dashboard/templates/page.js` for the certificate management UI
   - `app/admin/page.js` for admin operations
   These pages form the human-facing layer that drives certificate creation, viewing, and verification.

3. **Backend API layer**
   The functional backend is exposed through Next.js route handlers in `app/api/*`. The key endpoints are:
   - `api/generate` for creating certificates
   - `api/test-email` and `api/test-certificate` for validation and operational checks
   - `api/status`, `api/health`, and `api/email-capacity` for service checks and operational reporting
   - `api/imagekit-auth` for media/service authentication
   - `api/admin/*` for admin-only management and analytics
   This is the main boundary between the UI and the server-side system.

4. **Certificate generation pipeline**
   The generation path appears to be the core product workflow. The `generate` API likely assembles certificate data, renders the certificate using the shared `components/CertificateTemplate.js`, and incorporates visual positioning helpers from `lib/position-utils.js`. The README also indicates support for QR codes and PDF output, so this subsystem probably turns template + recipient data into a downloadable/verifiable certificate artifact.

5. **Verification and public access**
   Public verification is centered around `app/verify/[id]/page.js` and the status pages. The design suggests each certificate gets a stable identifier and a public verification URL. The verification subsystem is separate from admin access and is intended to let anyone validate a certificate without needing privileged credentials.

6. **Admin and authentication boundary**
   Admin functionality is isolated in `app/admin` and `app/api/admin/*`, with dedicated support code in:
   - `lib/admin-auth.js`
   - `lib/admin-middleware.js`
   - `lib/admin-config.js`
   This creates a clear trust boundary: ordinary public users can verify or receive certificates, while admins can read analytics, logs, users, certificates, and authenticate through protected routes.

7. **Data and persistence**
   Firebase is the primary backend data platform:
   - `lib/firebase.js` for client-side Firebase access
   - `lib/firebase-admin.js` for privileged server-side access
   The README explicitly names **Firestore** as the database. The architecture therefore separates public Firebase usage from server-authorized Firebase Admin operations, which is important for diagramming trusted vs. untrusted flows.

8. **Email delivery subsystem**
   `lib/email-service.js` and the `api/test-email` route indicate a dedicated email delivery layer, likely powered by Nodemailer as stated in the README. This subsystem is responsible for sending generated certificates or delivery notifications and is distinct from generation itself. Operational checks like `email-capacity` suggest the app tracks or estimates sending limits.

9. **Storage and media services**
   The repository includes `lib/storage-service.js`, `lib/cloudinary.js`, and an `api/imagekit-auth` route. That implies generated assets or template media are stored or distributed through external media services rather than being kept only in the app server. For an architecture diagram, treat storage/CDN as an external asset layer supporting certificate hosting and template/image management.

10. **Operational and support endpoints**
   The presence of `health`, `status`, `logs`, `analytics`, and test routes indicates the system is designed with observability and admin support in mind. These endpoints provide runtime checks, service diagnostics, and operational insight, which are separate from the certificate issuance flow but important for maintaining the platform.

11. **Shared UI and styling layer**
   The app uses a shared component and styling stack:
   - `components/CertificateTemplate.js` for reusable certificate rendering
   - `app/globals.css`, `tailwind.config.js`, and `postcss.config.js` for styling
   This is a cross-cutting presentation layer used by the dashboard, public pages, and likely the generated certificate preview/rendering pipeline.

12. **External technology boundaries**
   The repo is a modern full-stack JavaScript app built on **Next.js/React** with **Tailwind CSS**. On the server side it integrates **Firebase Admin**, **Firestore**, **Nodemailer**, and media/CDN tooling such as **Cloudinary** or **ImageKit**. These external systems are not just dependencies; they define the core boundaries between UI, application logic, persistence, email delivery, and asset hosting.

Main entry points: [`app/api/generate/route.js`](https://github.com/reyan36/certcat/blob/main/app/api/generate/route.js) (Generate), [`app/dashboard/page.js`](https://github.com/reyan36/certcat/blob/main/app/dashboard/page.js) (Dashboard), [`lib/firebase-admin.js`](https://github.com/reyan36/certcat/blob/main/lib/firebase-admin.js) (Firebase Admin), [`lib/firebase.js`](https://github.com/reyan36/certcat/blob/main/lib/firebase.js) (Firebase)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Router"]
  node_home["Landing<br/>page<br/>[page.js]"]
  node_pricing["Pricing<br/>page<br/>[page.js]"]
  node_status["Status<br/>page<br/>[page.js]"]
  node_verify["Verify<br/>page<br/>[page.js]"]
  node_dashboard["Dashboard<br/>app page<br/>[page.js]"]
  node_templates["Templates<br/>app page<br/>[page.js]"]
  node_adminui["Admin<br/>[page.js]"]
  node_generate_api["Generate<br/>route<br/>[route.js]"]
  node_ops_api["Ops APIs<br/>routes"]
  node_admin_api["Admin APIs<br/>routes"]
  node_imagekit_api["Media Auth<br/>route<br/>[route.js]"]
end

subgraph group_core["Core Logic"]
  node_cert_template["Cert Template<br/>ui component"]
  node_position_utils["Position Utils<br/>helper<br/>[position-utils.js]"]
  node_admin_auth["Admin Auth<br/>security<br/>[admin-auth.js]"]
end

subgraph group_infra["Infra Services"]
  node_firebase_public[("Firebase<br/>client SDK<br/>[firebase.js]")]
  node_firebase_admin[("Firebase Admin<br/>server SDK<br/>[firebase-admin.js]")]
  node_email_service["Email Service<br/>delivery<br/>[email-service.js]"]
  node_storage_service[("Storage<br/>media<br/>[storage-service.js]")]
  node_cloudinary(("Cloudinary<br/>media CDN<br/>[cloudinary.js]"))
end

node_home -->|"enter app"| node_dashboard
node_home -->|"view plans"| node_pricing
node_dashboard -->|"manage templates"| node_templates
node_dashboard -->|"create certs"| node_generate_api
node_dashboard -->|"read/write"| node_firebase_public
node_status -->|"lookup status"| node_firebase_public
node_verify -->|"verify cert"| node_firebase_public
node_generate_api -->|"render"| node_cert_template
node_generate_api -->|"place elements"| node_position_utils
node_generate_api -->|"persist cert"| node_firebase_admin
node_generate_api -->|"send email"| node_email_service
node_generate_api -->|"store asset"| node_storage_service
node_ops_api -->|"read ops data"| node_firebase_admin
node_ops_api -->|"check capacity"| node_email_service
node_adminui -->|"admin actions"| node_admin_api
node_admin_api -->|"protect routes"| node_admin_auth
node_admin_api -->|"manage data"| node_firebase_admin
node_admin_api -->|"inspect mail"| node_email_service
node_imagekit_api -->|"asset auth"| node_cloudinary
node_storage_service -->|"persist media"| node_cloudinary
node_cert_template -->|"preview"| node_dashboard
node_admin_auth -->|"verify admin"| node_firebase_admin

click node_home "https://github.com/reyan36/certcat/blob/main/app/page.js"
click node_pricing "https://github.com/reyan36/certcat/blob/main/app/pricing/page.js"
click node_status "https://github.com/reyan36/certcat/blob/main/app/status/page.js"
click node_verify "https://github.com/reyan36/certcat/blob/main/app/verify/[id]/page.js"
click node_dashboard "https://github.com/reyan36/certcat/blob/main/app/dashboard/page.js"
click node_templates "https://github.com/reyan36/certcat/blob/main/app/dashboard/templates/page.js"
click node_adminui "https://github.com/reyan36/certcat/blob/main/app/admin/page.js"
click node_generate_api "https://github.com/reyan36/certcat/blob/main/app/api/generate/route.js"
click node_imagekit_api "https://github.com/reyan36/certcat/blob/main/app/api/imagekit-auth/route.js"
click node_cert_template "https://github.com/reyan36/certcat/blob/main/components/CertificateTemplate.js"
click node_position_utils "https://github.com/reyan36/certcat/blob/main/lib/position-utils.js"
click node_admin_auth "https://github.com/reyan36/certcat/blob/main/lib/admin-auth.js"
click node_firebase_public "https://github.com/reyan36/certcat/blob/main/lib/firebase.js"
click node_firebase_admin "https://github.com/reyan36/certcat/blob/main/lib/firebase-admin.js"
click node_email_service "https://github.com/reyan36/certcat/blob/main/lib/email-service.js"
click node_storage_service "https://github.com/reyan36/certcat/blob/main/lib/storage-service.js"
click node_cloudinary "https://github.com/reyan36/certcat/blob/main/lib/cloudinary.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_home,node_pricing,node_status,node_verify,node_dashboard,node_templates,node_adminui,node_generate_api,node_ops_api,node_admin_api,node_imagekit_api toneBlue
class node_cert_template,node_position_utils,node_admin_auth toneAmber
class node_firebase_public,node_firebase_admin,node_email_service,node_storage_service,node_cloudinary toneMint
```

## Components

### App Router

Browser pages and server routes in the Next.js app.

- [Landing](https://github.com/reyan36/certcat/blob/main/app/page.js): page · Public marketing entry point. · `app/page.js`
- [Pricing](https://github.com/reyan36/certcat/blob/main/app/pricing/page.js): page · Public pricing page. · `app/pricing/page.js`
- [Status](https://github.com/reyan36/certcat/blob/main/app/status/page.js): page · Public certificate status page. · `app/status/page.js`
- [Verify](https://github.com/reyan36/certcat/blob/main/app/verify/[id]/page.js): page · Public verification page by certificate id. · `app/verify/[id]/page.js`
- [Dashboard](https://github.com/reyan36/certcat/blob/main/app/dashboard/page.js): app page · Certificate management UI. · `app/dashboard/page.js`
- [Templates](https://github.com/reyan36/certcat/blob/main/app/dashboard/templates/page.js): app page · Dashboard template management. · `app/dashboard/templates/page.js`
- [Admin](https://github.com/reyan36/certcat/blob/main/app/admin/page.js): admin page · Privileged administration UI. · `app/admin/page.js`
- [Generate](https://github.com/reyan36/certcat/blob/main/app/api/generate/route.js): route · Certificate creation endpoint. · `app/api/generate/route.js`
- **Ops APIs**: routes · Health, status, capacity, and test endpoints.
- **Admin APIs**: routes · Protected admin management endpoints.
- [Media Auth](https://github.com/reyan36/certcat/blob/main/app/api/imagekit-auth/route.js): route · ImageKit authentication endpoint. · `app/api/imagekit-auth/route.js`

### Core Logic

Shared rendering, workflow, and trust-boundary modules.

- [Cert Template](https://github.com/reyan36/certcat/blob/main/components/CertificateTemplate.js): ui component · Reusable certificate rendering template. · `components/CertificateTemplate.js`
- [Position Utils](https://github.com/reyan36/certcat/blob/main/lib/position-utils.js): helper · Layout and placement helpers. · `lib/position-utils.js`
- [Admin Auth](https://github.com/reyan36/certcat/blob/main/lib/admin-auth.js): security · Admin authentication and middleware. · `lib/admin-auth.js`

### Infra Services

Persistence, email, and media integrations.

- [Firebase](https://github.com/reyan36/certcat/blob/main/lib/firebase.js): client SDK · Client-side Firebase access. · `lib/firebase.js`
- [Firebase Admin](https://github.com/reyan36/certcat/blob/main/lib/firebase-admin.js): server SDK · Privileged Firestore access. · `lib/firebase-admin.js`
- [Email Service](https://github.com/reyan36/certcat/blob/main/lib/email-service.js): delivery · Certificate and notification email delivery. · `lib/email-service.js`
- [Storage](https://github.com/reyan36/certcat/blob/main/lib/storage-service.js): media · Asset and certificate storage integration. · `lib/storage-service.js`
- [Cloudinary](https://github.com/reyan36/certcat/blob/main/lib/cloudinary.js): media CDN · External media hosting service. · `lib/cloudinary.js`

## Connections

- Landing → Dashboard: enter app · Landing page routes users into the product.
- Landing → Pricing: view plans · Public marketing navigation.
- Dashboard → Templates: manage templates · Dashboard opens template management.
- Dashboard → Generate: create certs · Dashboard submits certificate generation requests.
- Dashboard → Firebase: read/write · UI uses client Firebase for app data.
- Status → Firebase: lookup status · Status page fetches certificate state.
- Verify → Firebase: verify cert · Public verification resolves certificate identity.
- Generate → Cert Template: render · Generation uses shared certificate rendering.
- Generate → Position Utils: place elements · Generation computes layout positions.
- Generate → Firebase Admin: persist cert · Server-side certificate data is stored with admin privileges.
- Generate → Email Service: send email · Generated certificates can be delivered by email.
- Generate → Storage: store asset · Generated artifacts or media are persisted externally.
- Ops APIs → Firebase Admin: read ops data · Operational endpoints inspect trusted backend state.
- Ops APIs → Email Service: check capacity · Email capacity and test endpoints exercise delivery.
- Admin → Admin APIs: admin actions · Admin UI calls protected management routes.
- Admin APIs → Admin Auth: protect routes · Admin routes enforce auth and middleware.
- Admin APIs → Firebase Admin: manage data · Admin routes manage users, certificates, logs, and analytics.
- Admin APIs → Email Service: inspect mail · Admin operations may surface delivery state.
- Media Auth → Cloudinary: asset auth · Media authentication supports external asset hosting.
- Storage → Cloudinary: persist media · Storage integration uses Cloudinary as an external service.
- Cert Template → Dashboard: preview · Shared certificate rendering is reused in the UI.
- Admin Auth → Firebase Admin: verify admin · Trusted admin access depends on privileged backend data.
