How vedant27-lab/stockpilot works
1. Repository shape
- StockPilot is a full-stack inventory system with three visible delivery surfaces: a Node/Express backend, a static web frontend, and an Android wrapper built with Capacitor.
- The codebase is organized around backend domain modules in lib/, browser assets in public/, and the mobile shell in android-app/.
2. Backend application boundary
- server.js is the main runtime entrypoint for the Node.js app.
- api/index.js appears to expose the backend as a serverless/API entry when deployed on Vercel.
- vercel.json indicates the repository is configured for cloud deployment as well as local execution.
3. HTTP/API layer
- Request handling is split into route modules under lib/routes/.
- The API is organized by concern: authentication, personal inventory, invites, and group-scoped operations.
- The group area is further decomposed into dedicated route files for CRUD, members, products, movements, requests, invitations, and logs, which suggests a workflow-heavy domain rather than a single generic CRUD API.
4. Domain model layer
- lib/models/ contains the persistent business entities: User, Product, Movement, Request, ActivityLog, Group, GroupMember, and GroupInvite.
- This model set shows two major concepts:
- a personal inventory/request workflow
- a collaborative group-sharing/workspace model with membership and invites
- ActivityLog provides an audit trail for operations, likely used by the admin dashboard.
5. Authorization and access control
- lib/middleware/auth.js and lib/middleware/groupAuth.js define the main security boundary.
- The app uses role-aware access control: authenticated user access, and additional group-scoped checks for shared resources.
- The README describes admin/customer separation, and the code structure supports that via server-side route protection rather than only frontend hiding.
6. Validation and service helpers
- lib/helpers/validation.js centralizes input checking before writes reach the database.
- lib/helpers/logger.js suggests server-side operational or application logging is standardized rather than ad hoc.
- This indicates a layered flow: request → auth → validation → route logic → model persistence.
7. Primary data flows
- A typical inventory mutation likely flows from the browser dashboard to an Express route, through authentication and validation, then into a Mongoose model write.
- Read flows for dashboards likely aggregate products, movements, requests, and logs into the frontend’s dashboard views.
- Request approval appears to be a distinct workflow: customer submits a request, admin reviews it, then the system executes the inventory change and records it.
8. Web frontend
- The browser UI is mostly static and framework-free: public/login.html, public/dashboard.html, and JavaScript in public/js/.
- public/js/login.js likely handles auth form submission and session establishment.
- public/js/dashboard-core.js and public/js/dashboard-views.js split dashboard behavior from rendering, suggesting a client-side MVC-like separation without a framework.
- public/css/style.css is the shared visual layer for the web app.
9. Mobile packaging
- android-app/ contains a Capacitor-generated Android project that wraps the web app into a native shell.
- android-app/www/index.html is the web entrypoint used by the mobile container.
- The Android source in android-app/android/app/src/main/java/com/stockpilot/app/MainActivity.java is minimal, which implies the app delegates most behavior to the embedded web UI.
- file_paths.xml and the resource set confirm standard Android packaging rather than custom native business logic.
10. Persistence and local state
- data/store.json and runs.json suggest some local file-backed data or runtime tracking exists alongside the database-oriented code.
- However, the README and model structure point to MongoDB/Mongoose as the primary application datastore.
- For an architecture diagram, treat MongoDB as the system of record and these JSON files as auxiliary or development/runtime artifacts unless proven otherwise.
11. Operational/admin utilities
- createAdmin.js is a bootstrap script for provisioning an admin account.
- This is an important architectural boundary because it separates one-time setup from the normal authenticated application flow.
12. Testing and quality gates
- The Android project includes both unit and instrumented tests under android-app/android/app/src/test and src/androidTest.
- The Node.js side does not show a dedicated test tree in the file listing, so the strongest explicit test coverage visible here is on the mobile wrapper side.
13. Build and deployment pipeline
- .github/workflows/build-android.yml automates Android builds in CI.
- android-app/package.json and the Gradle wrapper files indicate the mobile build is reproducible from source.
- Combined with vercel.json, the repo is set up for separate web/API deployment and Android artifact generation.
14. What to draw as the main system boundaries
- Client boundary: static web dashboard/login pages and the Capacitor Android shell.
- Application boundary: Express routes, middleware, and domain logic in lib/.
- Data boundary: MongoDB-backed models plus audit/logging entities.
- Admin/customer and personal/group access should be shown as authorization boundaries crossing the API, not as separate frontends.
Main entry points: index.js Groups API · db.js Database · personal.js Personal API · validation.js Validation
Components 34
Web client
Static browser UI and client-side dashboard scripts.
- Login · Static login surface.
public/login.html - Dashboard · Static dashboard surface.
public/dashboard.html - Login script · Client-side authentication flow.
public/js/login.js - Dashboard core · Dashboard state and interactions.
public/js/dashboard-core.js - Dashboard views · Dashboard rendering and presentation logic.
public/js/dashboard-views.js
Backend app
Express runtime, routing, middleware, and domain models.
- Server · Main Node.js runtime entrypoint.
server.js - API entry · Serverless/API entry for hosted deployment.
api/index.js - Auth routes · Authentication and session-facing endpoints.
lib/routes/auth.js - Personal API · Personal inventory and request workflow endpoints.
lib/routes/personal.js - Groups API · Group-scoped API composition layer.
lib/routes/groups/index.js - Group CRUD · Core group create/read/update/delete operations.
lib/routes/groups/crud.js - Members · Group membership management endpoints.
lib/routes/groups/members.js - Products · Group-scoped product inventory endpoints.
lib/routes/groups/products.js - Movements · Stock movement and transfer endpoints.
lib/routes/groups/movements.js - Requests · Request submission and approval workflow endpoints.
lib/routes/groups/requests.js - Invites · Group invitation issuance and acceptance endpoints.
lib/routes/groups/invitations.js - Logs · Activity and audit log endpoints.
lib/routes/groups/logs.js - Auth middleware · Authenticated-user access control boundary.
lib/middleware/auth.js - Group auth · Group-scoped authorization checks.
lib/middleware/groupAuth.js - Validation · Shared input validation before writes.
lib/helpers/validation.js - Logger · Centralized application logging.
lib/helpers/logger.js - Users · Authenticated users and roles.
lib/models/User.js - Products · Inventory product records.
lib/models/Product.js - Movements · Inventory change records.
lib/models/Movement.js - Requests · Approval workflow records.
lib/models/Request.js - Activity log · Audit trail records.
lib/models/ActivityLog.js - Groups · Collaborative workspace entities.
lib/models/Group.js - Group members · Membership links between users and groups.
lib/models/GroupMember.js - Group invites · Pending invitations into groups.
lib/models/GroupInvite.js
Android shell
Capacitor-wrapped Android delivery surface.
- MainActivity · Minimal Android host activity.
android-app/android/app/src/main/java/com/stockpilot/app/MainActivity.java - Mobile web · Embedded web entrypoint for the Android shell.
android-app/www/index.html - Android build · Capacitor/Gradle Android packaging configuration.
android-app/package.json
Ops & data
Deployment, bootstrap, and auxiliary runtime state.
- Database · Mongoose-backed datastore boundary.
lib/db.js - Admin bootstrap · One-time admin provisioning script.
createAdmin.js
Connections 48
- Server → Auth routes: mounts · Registers auth endpoints on the main server.
- Server → Personal API: mounts · Registers personal inventory routes.
- Server → Groups API: mounts · Registers group API surface.
- API entry → Server: deploys · Hosted API entry delegates to the main app runtime.
- Groups API → Group CRUD: composes · Group API is split into focused route modules.
- Groups API → Members: composes · Group API is split into focused route modules.
- Groups API → Products: composes · Group API is split into focused route modules.
- Groups API → Movements: composes · Group API is split into focused route modules.
- Groups API → Requests: composes · Group API is split into focused route modules.
- Groups API → Invites: composes · Group API is split into focused route modules.
- Groups API → Logs: composes · Group API is split into focused route modules.
- Auth routes → Auth middleware: protects · Authentication middleware guards protected access.
- Personal API → Auth middleware: protects · Personal workflows require authenticated access.
- Groups API → Group auth: protects · Group-scoped resources require additional authorization.
- Group CRUD → Validation: validates · Input is checked before writes.
- Products → Validation: validates · Input is checked before writes.
- Movements → Validation: validates · Input is checked before writes.
- Requests → Validation: validates · Input is checked before writes.
- Invites → Validation: validates · Input is checked before writes.
- Logs → Logger: records · Operational and audit events are logged centrally.
- Auth routes → Users: uses · Authentication depends on user records.
- Personal API → Products: uses · Personal inventory reads and writes products.
- Personal API → Requests: uses · Request workflow persists approval records.
- Products → Products: uses · Group inventory endpoints persist products.
- Movements → Movements: uses · Stock movement endpoints persist movements.
- Requests → Requests: uses · Request workflow persists requests.
- Logs → Activity log: uses · Audit endpoints expose activity log entries.
- Group CRUD → Groups: uses · Core group lifecycle persists group entities.
- Members → Group members: uses · Membership changes persist membership links.
- Invites → Group invites: uses · Invitation workflow persists invite records.
- Users → Database: persists · Models share the database boundary.
- Products → Database: persists · Models share the database boundary.
- Movements → Database: persists · Models share the database boundary.
- Requests → Database: persists · Models share the database boundary.
- Activity log → Database: persists · Models share the database boundary.
- Groups → Database: persists · Models share the database boundary.
- Group members → Database: persists · Models share the database boundary.
- Group invites → Database: persists · Models share the database boundary.
- Login → Login script: loads · Login page is driven by client-side auth logic.
- Dashboard → Dashboard core: loads · Dashboard page bootstraps core behavior.
- Dashboard → Dashboard views: loads · Dashboard page bootstraps rendering layer.
- Login script → Auth routes: calls · Login submits to backend auth endpoints.
- Dashboard core → Personal API: calls · Dashboard interacts with inventory APIs.
- Dashboard core → Groups API: calls · Dashboard interacts with group APIs.
- Dashboard views → Dashboard core: renders · View layer consumes dashboard state and actions.
- MainActivity → Mobile web: hosts · Android activity hosts the embedded web app.
- Android build → Mobile web: packages · Capacitor/Gradle package the web UI into Android.
- Mobile web → Dashboard: wraps · Mobile shell reuses the browser dashboard surface.