-
Notifications
You must be signed in to change notification settings - Fork 73
v1 Structure
There are quite a few files and folders in the base structure of this starter kit, which can make it initially confusing. If all you want to do is start creating your app, you can:
- Write your React components in
client/src/
, just as you would in a Create React App application'ssrc/
directory;- Dependencies that are only used on the client side should be installed as
devDependencies
with--save-dev
/-D
; and
- Dependencies that are only used on the client side should be installed as
- Write your Express routes in
server/api.js
(or in sub-routers that you.use
here);- Endpoints are all mounted at
/api
and can be accessed relatively, so if you definedrouter.get("/endpoint", ...)
the client wouldfetch("/api/endpoint")
); - Dependencies that are used by the server at runtime must be installed as production
dependencies
.
- Endpoints are all mounted at
For more detail, see below.
-
.github
- files for configuring the GitHub repo, e.g. providing templates for issues and pull requests -
.vscode
- files for configuring the VS Code IDE, including defining some recommended extensions and providing debugging configuration for the dev mode -
client/
-
src/
-
pages/
- contains the components representing different pages within the site, currently justAbout.js
andHome.js
-
App.js
- this is the root component of the app, where the React Router switch that chooses between the pages can be found; new page routes can be added here -
index.js
- mounts the root component in a router context and renders it in the DOM.
-
-
webpack/
- Webpack configuration for building the client-side app in development and production modes
-
-
server/
-
api.js
- the crucial file in the server directory, where the Express router that defines the API routes is created. To facilicate push-state routing (the React Router client-side pages) in production mode, all API routes are mounted at/api
, sorouter.get("/", ...)
defines the handler forGET /api
. Other methods and routes can be added here, all relative to that top-level/api
endpoint. -
app.js
- creates and configures an Express application object with appropriate middleware, including mounting the router described above and serving the client files for production mode -
db.js
- in the Postgres or MongoDB versions, this exposes functions that allow the server to connect to and disconnect from the database. The Postgres version also exposes an object with a query method you can import and use where you want to access the database (the MongoDB version handles the connection globally using Mongoose). The connection string is supplied as theDATABASE_URL
(Postgres) orMONGODB_URI
(MongoDB) environment variables, or falls back to trying to connect to the default ports on localhost (see v1 Dev Setup#Databases, or if you want to use an environment variable in your local environment, see v1 Dotenv). -
server.js
- imports and starts the app on the configured port (either the value of thePORT
environment variable or the default, 3000) -
utils/
- contains various utility modules. In practice, you'll probably:- Import from and maybe add new options to
config.js
; - Import from
logger.js
; and - Ignore
middleware.js
entirely (all predefined middleware is already used inapp.js
).
See
server/utils/README.md
for more details. - Import from and maybe add new options to
-
The full version of the starter kit also includes the following:
-
__mocks__/
- a trivial file mock is provided to cover for CSS or image assets imported into React components, see themoduleNameMapper
injest.config.js
and e.g. Using [Jest] with Webpack -
bin/
- scripts for various tasks, seebin/README.md
-
e2e/
- files for the Cypress end-to-end tests, using their suggested folder structure; the tests themselves are ine2e/integration/
-
server/static/
- only used to test the handling of static files and push-state routing,dist/static/
will contain the bundled React client