How adjipratama99/directional-finder works
Project type and purpose
• This is a full-stack Next.js 13 (app-router) application called “directional-finder.”
• Its main features include: user authentication (NextAuth), dashboards for directional finder data, inventory management, reporting, and user management.
• It exposes several internal REST API endpoints (under app/api/…) that talk to a database via a custom db/ layer and ORM-style models.
File structure
Top-level directories and their roles:
• app/ – Next.js “app” router folder with:
– (sites) subfolder separating four main pages: dashboard, inventory, report, users
– Per-page UI components under each site folder
– API routes under app/api/… for auth, df (directional finder), inventory, report, satuan-wilayah, user
• components/ – shared React components and providers (ReactQueryClientProvider, SessionProvider, UI primitives, custom form/table/modal/etc.)
• db/ – database connection and CRUD/query-builder abstractions
• models/ – TypeScript model definitions matching database tables (SatuanKerja, user, inventory, etc.)
• redux/ – Redux Toolkit store and slices for client state
• hooks/ – custom React hooks (pagination, export, debounce, etc.)
• lib/ – utilities (Fetcher HTTP client, authOptions for NextAuth, misc utils)
• public/uploads – runtime file storage for PDFs
• context/ – React Context (MenuContext)
• config & root files – next.config.ts, middleware.ts, package.json, tsconfig.json
README
• Only covers installation, build, and start commands; does not include an architecture section.
• We infer from code that it runs as a Node/Next.js server, renders both server and client components, and uses API routes to power front-end data.
a. Main components:
• Client (browser) – React/Next.js front-end code, served by Next.js
• Next.js Server – handles SSR/SSG/page rendering and API endpoints
• NextAuth Module – under app/api/auth, handles session and JWT, integrates with SessionProvider on client
• Database – SQL (e.g., PostgreSQL/MySQL) accessed via db/connect.ts, repository.ts, crud.ts, and models in models/
• File Storage – local disk (public/uploads) for PDFs; could be swapped for S3
• External Services – OAuth providers (implicit in NextAuth), email or logging services if used
b. Relationships and data flow:
1. User → Next.js frontend (page.tsx under app/)
2. Frontend components → ReactQueryClientProvider or Redux hooks → call internal API endpoints (Fetcher.ts)
3. API route handlers (e.g., app/api/inventory/route.ts) → use db/ layer to query/update database
4. db layer → database → returns results → API route returns JSON → ReactQuery updates UI
5. File upload endpoints (if any) write to public/uploads folder → served statically via Next.js public folder
6. NextAuth routes → manage login, session, store tokens/cookies
c. Architectural patterns & design principles
• Separation of concerns: UI components vs. data-fetching hooks vs. API routes vs. database layer
• Next.js “app” router pattern: nested layouts, server and client components
• Custom hook pattern for pagination, export, debounce
• Repository/Builder pattern in db/queryBuilder + repo.ts
• Centralized state with Redux + React Query for caching and server-state management
• Context for global UI state (menu open/closed)
d. Key technologies & frameworks
• Frontend: Next.js 13 (app router), React 18, TypeScript
• Styling: Tailwind CSS (globals.css + postcss.config.mjs)
• State & data: Redux Toolkit, React Query
• Authentication: NextAuth.js
• Database: Node.js with custom query builder (likely on top of MySQL/Postgres)
• Build & deployment: Node.js server, npm run build && npm run start